Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ExternalSession code to Doctrine. #34

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading