From 7b7fc88de04deca72c12fa039b7a395335d88e40 Mon Sep 17 00:00:00 2001 From: Padmasree Gade Date: Wed, 18 Sep 2024 10:37:32 -0400 Subject: [PATCH 1/8] initial commit --- .../src/VuFind/Db/Row/PluginManager.php | 2 +- .../src/VuFind/Db/Service/AuthHashService.php | 68 ++++++++++++++++--- .../src/VuFind/Db/Table/PluginManager.php | 4 +- 3 files changed, 60 insertions(+), 14 deletions(-) diff --git a/module/VuFind/src/VuFind/Db/Row/PluginManager.php b/module/VuFind/src/VuFind/Db/Row/PluginManager.php index 9913894c141..102ee12f06a 100644 --- a/module/VuFind/src/VuFind/Db/Row/PluginManager.php +++ b/module/VuFind/src/VuFind/Db/Row/PluginManager.php @@ -61,7 +61,7 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager * @var array */ protected $factories = [ - AuthHash::class => RowGatewayFactory::class, + //AuthHash::class => RowGatewayFactory::class, ExternalSession::class => RowGatewayFactory::class, LoginToken::class => RowGatewayFactory::class, Ratings::class => RowGatewayFactory::class, diff --git a/module/VuFind/src/VuFind/Db/Service/AuthHashService.php b/module/VuFind/src/VuFind/Db/Service/AuthHashService.php index 68d40f93ed9..9a9555b84af 100644 --- a/module/VuFind/src/VuFind/Db/Service/AuthHashService.php +++ b/module/VuFind/src/VuFind/Db/Service/AuthHashService.php @@ -31,8 +31,9 @@ use DateTime; use VuFind\Db\Entity\AuthHashEntityInterface; -use VuFind\Db\Table\DbTableAwareInterface; -use VuFind\Db\Table\DbTableAwareTrait; +use VuFind\Db\Entity\AuthHash; +use VuFind\Log\LoggerAwareTrait; +use Laminas\Log\LoggerAwareInterface; /** * Database service for auth_hash table. @@ -45,10 +46,10 @@ */ class AuthHashService extends AbstractDbService implements AuthHashServiceInterface, - DbTableAwareInterface, - Feature\DeleteExpiredInterface + Feature\DeleteExpiredInterface, + LoggerAwareInterface { - use DbTableAwareTrait; + use LoggerAwareTrait; /** * Create an auth_hash entity object. @@ -57,7 +58,8 @@ class AuthHashService extends AbstractDbService implements */ public function createEntity(): AuthHashEntityInterface { - return $this->getDbTable('AuthHash')->createRow(); + $class = $this->getEntityClass(AuthHash::class); + return new $class(); } /** @@ -69,8 +71,11 @@ public function createEntity(): AuthHashEntityInterface */ public function deleteAuthHash(AuthHashEntityInterface|int $authHashOrId): void { - $authHashId = $authHashOrId instanceof AuthHashEntityInterface ? $authHashOrId->getId() : $authHashOrId; - $this->getDbTable('AuthHash')->delete(['id' => $authHashId]); + $dql = 'DELETE FROM ' . $this->getEntityClass(AuthHash::class) . ' ah ' + . 'WHERE ah.id = :id'; + $query = $this->entityManager->createQuery($dql); + $query->setParameter('id', $authHashOrId); + $query->execute(); } /** @@ -85,7 +90,22 @@ public function deleteAuthHash(AuthHashEntityInterface|int $authHashOrId): void */ public function getByHashAndType(string $hash, string $type, bool $create = true): ?AuthHashEntityInterface { - return $this->getDbTable('AuthHash')->getByHashAndType($hash, $type, $create); + $dql = 'SELECT at ' + . 'FROM ' . $this->getEntityClass(AuthHash::class) . ' ah ' + . 'WHERE ah.hash = :hash ' + . 'AND at.type = :type'; + $query = $this->entityManager->createQuery($dql); + $query->setParameters(compact('hash', 'type')); + $result = $query->getOneOrNullResult(); + if ($result === null && $create) { + $result = $this->createEntity() + ->setHash($hash) + ->setHashType($type) + ->setCreated(new DateTime()); + $this->persistEntity($result); + } + + return $result; } /** @@ -97,7 +117,21 @@ public function getByHashAndType(string $hash, string $type, bool $create = true */ public function getLatestBySessionId(string $sessionId): ?AuthHashEntityInterface { - return $this->getDbTable('AuthHash')->getLatestBySessionId($sessionId); + $dql = 'SELECT at ' + . 'FROM ' . $this->getEntityClass(AuthHash::class) . ' ah ' + . 'WHERE ah.session_id = :session_id ' + . 'ORDER BY ah.created DESC'; + $query = $this->entityManager->createQuery($dql); + $query->setParameter('session_id', $sessionId); + $result = $query->getOneOrNullResult(); + if ($result === null) { + $result = $this->createEntity() + ->setSessionId($sessionId) + ->setCreated(new DateTime()); + $this->persistEntity($result); + } + + return $result; } /** @@ -110,6 +144,18 @@ public function getLatestBySessionId(string $sessionId): ?AuthHashEntityInterfac */ public function deleteExpired(DateTime $dateLimit, ?int $limit = null): int { - return $this->getDbTable('AuthHash')->deleteExpired($dateLimit->format('Y-m-d H:i:s'), $limit); + $subQueryBuilder = $this->entityManager->createQueryBuilder(); + $subQueryBuilder->select('CONCAT(ah.hash, ah.type)') + ->from($this->getEntityClass(AuthHashEntityInterface::class), 'ah') + ->where('ah.created < :dateLimit') + ->setParameter('dateLimit', $dateLimit->format('Y-m-d H:i:s')); + if ($limit) { + $subQueryBuilder->setMaxResults($limit); + } + $queryBuilder = $this->entityManager->createQueryBuilder(); + $queryBuilder->delete($this->getEntityClass(AuthHashEntityInterface::class), 'ah') + ->where('concat(ah.hash, ah.type) IN (:hashes)') + ->setParameter('hashes', $subQueryBuilder->getQuery()->getResult()); + return $queryBuilder->getQuery()->execute(); } } diff --git a/module/VuFind/src/VuFind/Db/Table/PluginManager.php b/module/VuFind/src/VuFind/Db/Table/PluginManager.php index 6327e2374f3..0bec2276aeb 100644 --- a/module/VuFind/src/VuFind/Db/Table/PluginManager.php +++ b/module/VuFind/src/VuFind/Db/Table/PluginManager.php @@ -46,7 +46,7 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager * @var array */ protected $aliases = [ - 'authhash' => AuthHash::class, + //'authhash' => AuthHash::class, 'externalsession' => ExternalSession::class, 'logintoken' => LoginToken::class, 'ratings' => Ratings::class, @@ -62,7 +62,7 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager * @var array */ protected $factories = [ - AuthHash::class => GatewayFactory::class, + //AuthHash::class => GatewayFactory::class, ExternalSession::class => GatewayFactory::class, LoginToken::class => GatewayFactory::class, Ratings::class => GatewayFactory::class, From 30fb38dfe403307f2cc8fd3c873a158ebffd25a6 Mon Sep 17 00:00:00 2001 From: Padmasree Gade Date: Wed, 18 Sep 2024 12:38:17 -0400 Subject: [PATCH 2/8] corrected table reference --- .../VuFind/src/VuFind/Db/Service/AuthHashService.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/module/VuFind/src/VuFind/Db/Service/AuthHashService.php b/module/VuFind/src/VuFind/Db/Service/AuthHashService.php index 9a9555b84af..f724868fcab 100644 --- a/module/VuFind/src/VuFind/Db/Service/AuthHashService.php +++ b/module/VuFind/src/VuFind/Db/Service/AuthHashService.php @@ -90,10 +90,10 @@ public function deleteAuthHash(AuthHashEntityInterface|int $authHashOrId): void */ public function getByHashAndType(string $hash, string $type, bool $create = true): ?AuthHashEntityInterface { - $dql = 'SELECT at ' + $dql = 'SELECT ah ' . 'FROM ' . $this->getEntityClass(AuthHash::class) . ' ah ' . 'WHERE ah.hash = :hash ' - . 'AND at.type = :type'; + . 'AND ah.type = :type'; $query = $this->entityManager->createQuery($dql); $query->setParameters(compact('hash', 'type')); $result = $query->getOneOrNullResult(); @@ -117,12 +117,12 @@ public function getByHashAndType(string $hash, string $type, bool $create = true */ public function getLatestBySessionId(string $sessionId): ?AuthHashEntityInterface { - $dql = 'SELECT at ' + $dql = 'SELECT ah ' . 'FROM ' . $this->getEntityClass(AuthHash::class) . ' ah ' - . 'WHERE ah.session_id = :session_id ' + . 'WHERE ah.sessionId = :sessionId ' . 'ORDER BY ah.created DESC'; $query = $this->entityManager->createQuery($dql); - $query->setParameter('session_id', $sessionId); + $query->setParameter('sessionId', $sessionId); $result = $query->getOneOrNullResult(); if ($result === null) { $result = $this->createEntity() @@ -130,7 +130,7 @@ public function getLatestBySessionId(string $sessionId): ?AuthHashEntityInterfac ->setCreated(new DateTime()); $this->persistEntity($result); } - + return $result; } From d20f7f07480ad9b33930a999613d92311ab72957 Mon Sep 17 00:00:00 2001 From: Padmasree Gade Date: Wed, 18 Sep 2024 12:52:59 -0400 Subject: [PATCH 3/8] stan and composer errors fixed --- module/VuFind/src/VuFind/Db/Service/AuthHashService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/VuFind/src/VuFind/Db/Service/AuthHashService.php b/module/VuFind/src/VuFind/Db/Service/AuthHashService.php index f724868fcab..6761d863907 100644 --- a/module/VuFind/src/VuFind/Db/Service/AuthHashService.php +++ b/module/VuFind/src/VuFind/Db/Service/AuthHashService.php @@ -30,10 +30,10 @@ namespace VuFind\Db\Service; use DateTime; -use VuFind\Db\Entity\AuthHashEntityInterface; +use Laminas\Log\LoggerAwareInterface; use VuFind\Db\Entity\AuthHash; +use VuFind\Db\Entity\AuthHashEntityInterface; use VuFind\Log\LoggerAwareTrait; -use Laminas\Log\LoggerAwareInterface; /** * Database service for auth_hash table. @@ -130,7 +130,7 @@ public function getLatestBySessionId(string $sessionId): ?AuthHashEntityInterfac ->setCreated(new DateTime()); $this->persistEntity($result); } - + return $result; } From 8622be33650b590cd2c009375d08c4691eb5107d Mon Sep 17 00:00:00 2001 From: Padmasree Gade Date: Wed, 18 Sep 2024 14:01:17 -0400 Subject: [PATCH 4/8] restored to match old functionality --- .../src/VuFind/Db/Row/PluginManager.php | 1 - .../src/VuFind/Db/Service/AuthHashService.php | 7 - .../VuFind/src/VuFind/Db/Table/AuthHash.php | 123 ------------------ .../src/VuFind/Db/Table/PluginManager.php | 2 - 4 files changed, 133 deletions(-) delete mode 100644 module/VuFind/src/VuFind/Db/Table/AuthHash.php diff --git a/module/VuFind/src/VuFind/Db/Row/PluginManager.php b/module/VuFind/src/VuFind/Db/Row/PluginManager.php index 102ee12f06a..d2ca7cb318c 100644 --- a/module/VuFind/src/VuFind/Db/Row/PluginManager.php +++ b/module/VuFind/src/VuFind/Db/Row/PluginManager.php @@ -61,7 +61,6 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager * @var array */ protected $factories = [ - //AuthHash::class => RowGatewayFactory::class, ExternalSession::class => RowGatewayFactory::class, LoginToken::class => RowGatewayFactory::class, Ratings::class => RowGatewayFactory::class, diff --git a/module/VuFind/src/VuFind/Db/Service/AuthHashService.php b/module/VuFind/src/VuFind/Db/Service/AuthHashService.php index 6761d863907..1878047f17a 100644 --- a/module/VuFind/src/VuFind/Db/Service/AuthHashService.php +++ b/module/VuFind/src/VuFind/Db/Service/AuthHashService.php @@ -124,13 +124,6 @@ public function getLatestBySessionId(string $sessionId): ?AuthHashEntityInterfac $query = $this->entityManager->createQuery($dql); $query->setParameter('sessionId', $sessionId); $result = $query->getOneOrNullResult(); - if ($result === null) { - $result = $this->createEntity() - ->setSessionId($sessionId) - ->setCreated(new DateTime()); - $this->persistEntity($result); - } - return $result; } diff --git a/module/VuFind/src/VuFind/Db/Table/AuthHash.php b/module/VuFind/src/VuFind/Db/Table/AuthHash.php deleted file mode 100644 index baf35c287f6..00000000000 --- a/module/VuFind/src/VuFind/Db/Table/AuthHash.php +++ /dev/null @@ -1,123 +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; - -/** - * Table Definition for auth_hash - * - * @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 AuthHash extends Gateway -{ - use ExpirationTrait; - - public const TYPE_EMAIL = 'email'; // EmailAuthenticator - - /** - * 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 = 'auth_hash' - ) { - parent::__construct($adapter, $tm, $cfg, $rowObj, $table); - } - - /** - * Retrieve an object from the database based on hash and type; create a new - * row if no existing match is found. - * - * @param string $hash Hash - * @param string $type Hash type - * @param bool $create Should we create rows that don't already exist? - * - * @return ?\VuFind\Db\Row\AuthHash - */ - public function getByHashAndType($hash, $type, $create = true) - { - $row = $this->select(['hash' => $hash, 'type' => $type])->current(); - if ($create && empty($row)) { - $row = $this->createRow(); - $row->hash = $hash; - $row->type = $type; - $row->created = date('Y-m-d H:i:s'); - } - return $row; - } - - /** - * Retrieve last object from the database based on session id. - * - * @param string $sessionId Session ID - * - * @return ?\VuFind\Db\Row\AuthHash - */ - public function getLatestBySessionId($sessionId) - { - $callback = function ($select) use ($sessionId) { - $select->where->equalTo('session_id', $sessionId); - $select->order('created DESC'); - }; - return $this->select($callback)->current(); - } - - /** - * 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 0bec2276aeb..df3a4399b0f 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 = [ - //'authhash' => AuthHash::class, 'externalsession' => ExternalSession::class, 'logintoken' => LoginToken::class, 'ratings' => Ratings::class, @@ -62,7 +61,6 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager * @var array */ protected $factories = [ - //AuthHash::class => GatewayFactory::class, ExternalSession::class => GatewayFactory::class, LoginToken::class => GatewayFactory::class, Ratings::class => GatewayFactory::class, From e41fe5ab7ec21feb25d858b2298c46e00cf8ade0 Mon Sep 17 00:00:00 2001 From: Padmasree Gade Date: Wed, 18 Sep 2024 14:03:31 -0400 Subject: [PATCH 5/8] deleted old row and table classes. --- module/VuFind/src/VuFind/Db/Row/AuthHash.php | 195 ------------------- 1 file changed, 195 deletions(-) delete mode 100644 module/VuFind/src/VuFind/Db/Row/AuthHash.php diff --git a/module/VuFind/src/VuFind/Db/Row/AuthHash.php b/module/VuFind/src/VuFind/Db/Row/AuthHash.php deleted file mode 100644 index de5a60da0ac..00000000000 --- a/module/VuFind/src/VuFind/Db/Row/AuthHash.php +++ /dev/null @@ -1,195 +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\AuthHashEntityInterface; -use VuFind\Db\Service\DbServiceAwareInterface; -use VuFind\Db\Service\DbServiceAwareTrait; - -/** - * Row Definition for auth_hash - * - * @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 $hash - * @property string $type - * @property string $data - * @property string $created - */ -class AuthHash extends RowGateway implements AuthHashEntityInterface, DbServiceAwareInterface -{ - use \VuFind\Db\Table\DbTableAwareTrait; - use DbServiceAwareTrait; - - /** - * Constructor - * - * @param \Laminas\Db\Adapter\Adapter $adapter Database adapter - */ - public function __construct($adapter) - { - parent::__construct('id', 'auth_hash', $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 ?? null; - } - - /** - * 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 hash value. - * - * @return string - */ - public function getHash(): string - { - return $this->hash ?? ''; - } - - /** - * Set hash value. - * - * @param string $hash Hash Value - * - * @return static - */ - public function setHash(string $hash): static - { - $this->hash = $hash; - return $this; - } - - /** - * Get type of hash. - * - * @return ?string - */ - public function getHashType(): ?string - { - return $this->type ?? null; - } - - /** - * Set type of hash. - * - * @param ?string $type Hash Type - * - * @return static - */ - public function setHashType(?string $type): static - { - $this->type = $type; - return $this; - } - - /** - * Get data. - * - * @return ?string - */ - public function getData(): ?string - { - return $this->__get('data'); - } - - /** - * Set data. - * - * @param ?string $data Data - * - * @return static - */ - public function setData(?string $data): static - { - $this->__set('data', $data); - 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; - } -} From dd029511e636fccfb111b80263c55d1f2a99e2d2 Mon Sep 17 00:00:00 2001 From: Padmasree Gade Date: Wed, 18 Sep 2024 16:09:07 -0400 Subject: [PATCH 6/8] remove unnecessary logger --- .../VuFind/src/VuFind/Db/Service/AuthHashService.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/module/VuFind/src/VuFind/Db/Service/AuthHashService.php b/module/VuFind/src/VuFind/Db/Service/AuthHashService.php index 1878047f17a..fed069473c5 100644 --- a/module/VuFind/src/VuFind/Db/Service/AuthHashService.php +++ b/module/VuFind/src/VuFind/Db/Service/AuthHashService.php @@ -30,10 +30,10 @@ namespace VuFind\Db\Service; use DateTime; -use Laminas\Log\LoggerAwareInterface; +//use Laminas\Log\LoggerAwareInterface; use VuFind\Db\Entity\AuthHash; use VuFind\Db\Entity\AuthHashEntityInterface; -use VuFind\Log\LoggerAwareTrait; +//use VuFind\Log\LoggerAwareTrait; /** * Database service for auth_hash table. @@ -46,10 +46,10 @@ */ class AuthHashService extends AbstractDbService implements AuthHashServiceInterface, - Feature\DeleteExpiredInterface, - LoggerAwareInterface + Feature\DeleteExpiredInterface + //LoggerAwareInterface { - use LoggerAwareTrait; + //use LoggerAwareTrait; /** * Create an auth_hash entity object. From 32ea45607f6c39a27662d74ee0f02fb0dc5c4b18 Mon Sep 17 00:00:00 2001 From: Padmasree Gade Date: Wed, 18 Sep 2024 16:41:26 -0400 Subject: [PATCH 7/8] fixed stan errors --- module/VuFind/src/VuFind/Db/Service/AccessTokenService.php | 7 +------ module/VuFind/src/VuFind/Db/Service/AuthHashService.php | 5 ----- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/module/VuFind/src/VuFind/Db/Service/AccessTokenService.php b/module/VuFind/src/VuFind/Db/Service/AccessTokenService.php index 62026a0144b..81f593eeaf5 100644 --- a/module/VuFind/src/VuFind/Db/Service/AccessTokenService.php +++ b/module/VuFind/src/VuFind/Db/Service/AccessTokenService.php @@ -30,11 +30,9 @@ namespace VuFind\Db\Service; use DateTime; -use Laminas\Log\LoggerAwareInterface; use VuFind\Db\Entity\AccessToken; use VuFind\Db\Entity\AccessTokenEntityInterface; use VuFind\Db\Entity\User; -use VuFind\Log\LoggerAwareTrait; /** * Database service for access tokens. @@ -47,11 +45,8 @@ */ class AccessTokenService extends AbstractDbService implements AccessTokenServiceInterface, - Feature\DeleteExpiredInterface, - LoggerAwareInterface + Feature\DeleteExpiredInterface { - use LoggerAwareTrait; - /** * Create an access_token entity object. * diff --git a/module/VuFind/src/VuFind/Db/Service/AuthHashService.php b/module/VuFind/src/VuFind/Db/Service/AuthHashService.php index fed069473c5..4f274267481 100644 --- a/module/VuFind/src/VuFind/Db/Service/AuthHashService.php +++ b/module/VuFind/src/VuFind/Db/Service/AuthHashService.php @@ -30,10 +30,8 @@ namespace VuFind\Db\Service; use DateTime; -//use Laminas\Log\LoggerAwareInterface; use VuFind\Db\Entity\AuthHash; use VuFind\Db\Entity\AuthHashEntityInterface; -//use VuFind\Log\LoggerAwareTrait; /** * Database service for auth_hash table. @@ -47,10 +45,7 @@ class AuthHashService extends AbstractDbService implements AuthHashServiceInterface, Feature\DeleteExpiredInterface - //LoggerAwareInterface { - //use LoggerAwareTrait; - /** * Create an auth_hash entity object. * From 590e67c85a969ee3ce8de304cd8296faee2828c3 Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Thu, 19 Sep 2024 09:35:00 -0400 Subject: [PATCH 8/8] Minor tweaks. --- module/VuFind/src/VuFind/Db/Service/AuthHashService.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/module/VuFind/src/VuFind/Db/Service/AuthHashService.php b/module/VuFind/src/VuFind/Db/Service/AuthHashService.php index 4f274267481..da9ff8af280 100644 --- a/module/VuFind/src/VuFind/Db/Service/AuthHashService.php +++ b/module/VuFind/src/VuFind/Db/Service/AuthHashService.php @@ -69,7 +69,8 @@ public function deleteAuthHash(AuthHashEntityInterface|int $authHashOrId): void $dql = 'DELETE FROM ' . $this->getEntityClass(AuthHash::class) . ' ah ' . 'WHERE ah.id = :id'; $query = $this->entityManager->createQuery($dql); - $query->setParameter('id', $authHashOrId); + $authHashId = $authHashOrId instanceof AuthHashEntityInterface ? $authHashOrId->getId() : $authHashOrId; + $query->setParameter('id', $authHashId); $query->execute(); } @@ -133,7 +134,7 @@ public function getLatestBySessionId(string $sessionId): ?AuthHashEntityInterfac public function deleteExpired(DateTime $dateLimit, ?int $limit = null): int { $subQueryBuilder = $this->entityManager->createQueryBuilder(); - $subQueryBuilder->select('CONCAT(ah.hash, ah.type)') + $subQueryBuilder->select('ah.id') ->from($this->getEntityClass(AuthHashEntityInterface::class), 'ah') ->where('ah.created < :dateLimit') ->setParameter('dateLimit', $dateLimit->format('Y-m-d H:i:s')); @@ -142,7 +143,7 @@ public function deleteExpired(DateTime $dateLimit, ?int $limit = null): int } $queryBuilder = $this->entityManager->createQueryBuilder(); $queryBuilder->delete($this->getEntityClass(AuthHashEntityInterface::class), 'ah') - ->where('concat(ah.hash, ah.type) IN (:hashes)') + ->where('ah.id IN (:hashes)') ->setParameter('hashes', $subQueryBuilder->getQuery()->getResult()); return $queryBuilder->getQuery()->execute(); }