Skip to content

Commit

Permalink
Convert ExternalSession code to Doctrine. (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
padmasreegade authored Dec 9, 2024
1 parent 9f6bdc5 commit fe77e78
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 288 deletions.
142 changes: 0 additions & 142 deletions module/VuFind/src/VuFind/Db/Row/ExternalSession.php

This file was deleted.

2 changes: 0 additions & 2 deletions module/VuFind/src/VuFind/Db/Row/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
39 changes: 29 additions & 10 deletions module/VuFind/src/VuFind/Db/Service/ExternalSessionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -45,19 +44,17 @@
*/
class ExternalSessionService extends AbstractDbService implements
ExternalSessionServiceInterface,
Feature\DeleteExpiredInterface,
DbTableAwareInterface
Feature\DeleteExpiredInterface
{
use DbTableAwareTrait;

/**
* Create a new external session entity.
*
* @return ExternalSessionEntityInterface
*/
public function createEntity(): ExternalSessionEntityInterface
{
return $this->getDbTable('ExternalSession')->createRow();
$class = $this->getEntityClass(ExternalSession::class);
return new $class();
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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();
}

/**
Expand All @@ -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();
}
}
132 changes: 0 additions & 132 deletions module/VuFind/src/VuFind/Db/Table/ExternalSession.php

This file was deleted.

2 changes: 0 additions & 2 deletions module/VuFind/src/VuFind/Db/Table/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit fe77e78

Please sign in to comment.