diff --git a/Classes/Domain/Repository/AbstractRealUrlRepository.php b/Classes/Domain/Repository/AbstractRealUrlRepository.php index 24e06ab..c315a68 100644 --- a/Classes/Domain/Repository/AbstractRealUrlRepository.php +++ b/Classes/Domain/Repository/AbstractRealUrlRepository.php @@ -23,19 +23,11 @@ abstract class AbstractRealUrlRepository */ protected $pathField = 'pagepath'; - /** - * @var null|QueryBuilder - */ - protected $queryBuilder = null; - /** * RealUrlRepository constructor. */ public function __construct() { - $this->queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) - ->getQueryBuilderForTable($this->tableName); - $this->queryBuilder->getRestrictions()->removeAll(); } /** @@ -45,11 +37,12 @@ public function __construct() */ public function deleteByPathAndPid(string $path, int $pid): bool { - $affectedRows = $this->queryBuilder + $queryBuilder = $this->getQueryBuilder(); + $affectedRows = $queryBuilder ->delete($this->tableName) ->where( - $this->queryBuilder->expr()->eq($this->pathField, $this->queryBuilder->createNamedParameter($path)), - $this->queryBuilder->expr()->eq('page_id', $pid) + $queryBuilder->expr()->eq($this->pathField, $queryBuilder->createNamedParameter($path)), + $queryBuilder->expr()->eq('page_id', $pid) ) ->execute(); return $affectedRows > 0; @@ -69,15 +62,16 @@ public function hasCachingEntriesFromDeletedPages(): bool */ public function deleteWithDeletedPages(): bool { + $queryBuilder = $this->getQueryBuilder(); $uids = $this->findAllWithDeletedPages(); $uidList = implode(',',array_map(function($a) {return implode('~',$a);},$uids)); if (count($uids) > 0) { - $affectedRows = $this->queryBuilder + $affectedRows = $this->getQueryBuilder() ->delete($this->tableName) ->where( - $this->queryBuilder->expr()->in('uid', $uidList) + $queryBuilder->expr()->in('uid', $uidList) ) ->execute(); return $affectedRows > 0; @@ -93,18 +87,31 @@ public function deleteWithDeletedPages(): bool */ protected function findAllWithDeletedPages(): array { + $queryBuilder = $this->getQueryBuilder(); $connection = DatabaseUtility::getConnectionForTable('pages'); $uids = $connection->executeQuery('select uid from pages where deleted=1;')->fetchAll(); - + $uidList = implode(',',array_map(function($a) {return implode('~',$a);},$uids)); - - return (array)$this->queryBuilder + + return (array)$queryBuilder ->select('uid') ->from($this->tableName) ->where( - $this->queryBuilder->expr()->in('page_id', $uidList) + $queryBuilder->expr()->in('page_id', $uidList) ) ->execute() ->fetchAll(0); } + + /** + * @return QueryBuilder + */ + protected function getQueryBuilder() + { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable($this->tableName); + $queryBuilder->getRestrictions()->removeAll(); + + return $queryBuilder; + } } diff --git a/Classes/Domain/Repository/RealurlPathDataRepository.php b/Classes/Domain/Repository/RealurlPathDataRepository.php index 99289f0..45a3845 100644 --- a/Classes/Domain/Repository/RealurlPathDataRepository.php +++ b/Classes/Domain/Repository/RealurlPathDataRepository.php @@ -58,12 +58,12 @@ public function findAllDuplicates(int $startPid): array */ protected function findAllFromStartPid(int $startPid): array { - $result = $this->queryBuilder + $result = $this->getQueryBuilder() ->select('uid', 'page_id', 'pagepath') ->from($this->tableName) ->where($this->getWhereStringForStartPid($startPid)) ->setMaxResults(100000) - ->groupBy('page_id') + ->groupBy('page_id', 'pagepath') ->execute(); $rows = $result->fetchAll(); return $rows;