diff --git a/module/VuFind/src/VuFind/Db/Row/ExternalSession.php b/module/VuFind/src/VuFind/Db/Row/ExternalSession.php deleted file mode 100644 index ad46955a5fa..00000000000 --- a/module/VuFind/src/VuFind/Db/Row/ExternalSession.php +++ /dev/null @@ -1,142 +0,0 @@ - - * @author Ere Maijala - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License - * @link https://vufind.org Main Site - */ - -namespace VuFind\Db\Row; - -use DateTime; -use VuFind\Db\Entity\ExternalSessionEntityInterface; - -/** - * Row Definition for external_session - * - * @category VuFind - * @package Db_Row - * @author Demian Katz - * @author Ere Maijala - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License - * @link https://vufind.org Main Site - * - * @property int $id - * @property string $session_id - * @property string $external_session_id - * @property string $created - */ -class ExternalSession extends RowGateway implements ExternalSessionEntityInterface -{ - /** - * Constructor - * - * @param \Laminas\Db\Adapter\Adapter $adapter Database adapter - */ - public function __construct($adapter) - { - parent::__construct('id', 'external_session', $adapter); - } - - /** - * Get identifier (returns null for an uninitialized or non-persisted object). - * - * @return ?int - */ - public function getId(): ?int - { - return $this->id ?? null; - } - - /** - * Get PHP session id string. - * - * @return string - */ - public function getSessionId(): string - { - return $this->session_id ?? ''; - } - - /** - * Set PHP session id string. - * - * @param string $sessionId PHP session id string - * - * @return static - */ - public function setSessionId(string $sessionId): static - { - $this->session_id = $sessionId; - return $this; - } - - /** - * Get PHP external session id string. - * - * @return string - */ - public function getExternalSessionId(): string - { - return $this->external_session_id ?? ''; - } - - /** - * Set external session id string. - * - * @param string $externalSessionId External session id string - * - * @return static - */ - public function setExternalSessionId(string $externalSessionId): static - { - $this->external_session_id = $externalSessionId; - return $this; - } - - /** - * Get created date. - * - * @return DateTime - */ - public function getCreated(): DateTime - { - return DateTime::createFromFormat('Y-m-d H:i:s', $this->created); - } - - /** - * Set created date. - * - * @param DateTime $dateTime Created date - * - * @return static - */ - public function setCreated(DateTime $dateTime): static - { - $this->created = $dateTime->format('Y-m-d H:i:s'); - return $this; - } -} diff --git a/module/VuFind/src/VuFind/Db/Row/PluginManager.php b/module/VuFind/src/VuFind/Db/Row/PluginManager.php index 3e8a81f144a..8a52cff7d2e 100644 --- a/module/VuFind/src/VuFind/Db/Row/PluginManager.php +++ b/module/VuFind/src/VuFind/Db/Row/PluginManager.php @@ -46,7 +46,6 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager * @var array */ protected $aliases = [ - 'externalsession' => ExternalSession::class, 'ratings' => Ratings::class, 'search' => Search::class, 'session' => Session::class, @@ -60,7 +59,6 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager * @var array */ protected $factories = [ - ExternalSession::class => RowGatewayFactory::class, Ratings::class => RowGatewayFactory::class, Search::class => RowGatewayFactory::class, Session::class => RowGatewayFactory::class, diff --git a/module/VuFind/src/VuFind/Db/Service/ExternalSessionService.php b/module/VuFind/src/VuFind/Db/Service/ExternalSessionService.php index 88f29186900..ccd3f958851 100644 --- a/module/VuFind/src/VuFind/Db/Service/ExternalSessionService.php +++ b/module/VuFind/src/VuFind/Db/Service/ExternalSessionService.php @@ -30,9 +30,8 @@ namespace VuFind\Db\Service; use DateTime; +use VuFind\Db\Entity\ExternalSession; use VuFind\Db\Entity\ExternalSessionEntityInterface; -use VuFind\Db\Table\DbTableAwareInterface; -use VuFind\Db\Table\DbTableAwareTrait; /** * Database service for external_session table. @@ -45,11 +44,8 @@ */ class ExternalSessionService extends AbstractDbService implements ExternalSessionServiceInterface, - Feature\DeleteExpiredInterface, - DbTableAwareInterface + Feature\DeleteExpiredInterface { - use DbTableAwareTrait; - /** * Create a new external session entity. * @@ -57,7 +53,8 @@ class ExternalSessionService extends AbstractDbService implements */ public function createEntity(): ExternalSessionEntityInterface { - return $this->getDbTable('ExternalSession')->createRow(); + $class = $this->getEntityClass(ExternalSession::class); + return new $class(); } /** @@ -90,7 +87,13 @@ public function addSessionMapping( */ public function getAllByExternalSessionId(string $sid): array { - return iterator_to_array($this->getDbTable('ExternalSession')->select(['external_session_id' => $sid])); + $dql = 'SELECT es ' + . 'FROM ' . $this->getEntityClass(ExternalSession::class) . ' es ' + . 'WHERE es.externalSessionId = :esid '; + $query = $this->entityManager->createQuery($dql); + $query->setParameter('esid', $sid); + $result = $query->getResult(); + return $result; } /** @@ -102,7 +105,11 @@ public function getAllByExternalSessionId(string $sid): array */ public function destroySession(string $sid): void { - $this->getDbTable('ExternalSession')->delete(['session_id' => $sid]); + $dql = 'DELETE FROM ' . $this->getEntityClass(ExternalSession::class) . ' es' + . ' WHERE es.sessionId = :sid'; + $query = $this->entityManager->createQuery($dql); + $query->setParameter('sid', $sid); + $query->execute(); } /** @@ -115,6 +122,18 @@ public function destroySession(string $sid): void */ public function deleteExpired(DateTime $dateLimit, ?int $limit = null): int { - return $this->getDbTable('ExternalSession')->deleteExpired($dateLimit->format('Y-m-d H:i:s'), $limit); + $subQueryBuilder = $this->entityManager->createQueryBuilder(); + $subQueryBuilder->select('es.id') + ->from($this->getEntityClass(ExternalSession::class), 'es') + ->where('es.created < :dateLimit') + ->setParameter('dateLimit', $dateLimit); + if ($limit) { + $subQueryBuilder->setMaxResults($limit); + } + $queryBuilder = $this->entityManager->createQueryBuilder(); + $queryBuilder->delete($this->getEntityClass(ExternalSessionEntityInterface::class), 'es') + ->where('es.id IN (:ids)') + ->setParameter('ids', $subQueryBuilder->getQuery()->getResult()); + return $queryBuilder->getQuery()->execute(); } } diff --git a/module/VuFind/src/VuFind/Db/Table/ExternalSession.php b/module/VuFind/src/VuFind/Db/Table/ExternalSession.php deleted file mode 100644 index 9abe1c56868..00000000000 --- a/module/VuFind/src/VuFind/Db/Table/ExternalSession.php +++ /dev/null @@ -1,132 +0,0 @@ - - * @author Ere Maijala - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License - * @link https://vufind.org Main Page - */ - -namespace VuFind\Db\Table; - -use Laminas\Db\Adapter\Adapter; -use VuFind\Db\Row\RowGateway; -use VuFind\Db\Service\DbServiceAwareInterface; -use VuFind\Db\Service\DbServiceAwareTrait; -use VuFind\Db\Service\ExternalSessionServiceInterface; - -/** - * Table Definition for external_session - * - * @category VuFind - * @package Db_Table - * @author Demian Katz - * @author Ere Maijala - * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License - * @link https://vufind.org Main Site - */ -class ExternalSession extends Gateway implements DbServiceAwareInterface -{ - use DbServiceAwareTrait; - use ExpirationTrait; - - /** - * Constructor - * - * @param Adapter $adapter Database adapter - * @param PluginManager $tm Table manager - * @param array $cfg Laminas configuration - * @param ?RowGateway $rowObj Row prototype object (null for default) - * @param string $table Name of database table to interface with - */ - public function __construct( - Adapter $adapter, - PluginManager $tm, - $cfg, - ?RowGateway $rowObj = null, - $table = 'external_session' - ) { - parent::__construct($adapter, $tm, $cfg, $rowObj, $table); - } - - /** - * Add a mapping between local and external session id's - * - * @param string $localSessionId Local (VuFind) session id - * @param string $externalSessionId External session id - * - * @return void - * - * @deprecated Use ExternalSessionServiceInterface::addSessionMapping() - */ - public function addSessionMapping($localSessionId, $externalSessionId) - { - $this->getDbService(ExternalSessionServiceInterface::class) - ->addSessionMapping($localSessionId, $externalSessionId); - } - - /** - * Retrieve an object from the database based on an external session ID - * - * @param string $sid External session ID to retrieve - * - * @return ?\VuFind\Db\Row\ExternalSession - * - * @deprecated Use ExternalSessionServiceInterface::getAllByExternalSessionId() - */ - public function getByExternalSessionId($sid) - { - $sessions = $this->getDbService(ExternalSessionServiceInterface::class)->getAllByExternalSessionId($sid); - return $sessions[0] ?? null; - } - - /** - * Destroy data for the given session ID. - * - * @param string $sid Session ID to erase - * - * @return void - * - * @deprecated Use ExternalSessionServiceInterface::destroySession() - */ - public function destroySession($sid) - { - $this->getDbService(ExternalSessionServiceInterface::class)->destroySession($sid); - } - - /** - * Update the select statement to find records to delete. - * - * @param Select $select Select clause - * @param string $dateLimit Date threshold of an "expired" record in format - * 'Y-m-d H:i:s'. - * - * @return void - */ - protected function expirationCallback($select, $dateLimit) - { - $select->where->lessThan('created', $dateLimit); - } -} diff --git a/module/VuFind/src/VuFind/Db/Table/PluginManager.php b/module/VuFind/src/VuFind/Db/Table/PluginManager.php index adf76aba9ed..b38c641440b 100644 --- a/module/VuFind/src/VuFind/Db/Table/PluginManager.php +++ b/module/VuFind/src/VuFind/Db/Table/PluginManager.php @@ -46,7 +46,6 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager * @var array */ protected $aliases = [ - 'externalsession' => ExternalSession::class, 'ratings' => Ratings::class, 'search' => Search::class, 'session' => Session::class, @@ -60,7 +59,6 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager * @var array */ protected $factories = [ - ExternalSession::class => GatewayFactory::class, Ratings::class => GatewayFactory::class, Search::class => GatewayFactory::class, Session::class => GatewayFactory::class,