diff --git a/Classes/Domain/Repository/CommentRepository.php b/Classes/Domain/Repository/CommentRepository.php index f6d505de..47e6ee17 100644 --- a/Classes/Domain/Repository/CommentRepository.php +++ b/Classes/Domain/Repository/CommentRepository.php @@ -23,26 +23,18 @@ class CommentRepository extends Repository { - /** - * @var ConfigurationManagerInterface - */ - protected $configurationManager; - - /** - * @var array - */ - protected $settings; + protected array $settings = []; - /** - * @throws \InvalidArgumentException - */ public function initializeObject(): void { - $this->configurationManager = $this->objectManager->get(ConfigurationManagerInterface::class); - $this->settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, 'blog'); - - $querySettings = $this->objectManager->get(Typo3QuerySettings::class); - // don't add the pid constraint + $configurationManager = GeneralUtility::makeInstance(ConfigurationManagerInterface::class); + $this->settings = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, 'blog'); + + $querySettings = GeneralUtility::makeInstance( + Typo3QuerySettings::class, + GeneralUtility::makeInstance(Context::class), + $configurationManager + ); $querySettings->setRespectStoragePage(false); $this->setDefaultQuerySettings($querySettings); @@ -52,10 +44,7 @@ public function initializeObject(): void } /** - * @param Post $post * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface - * @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException - * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException */ public function findAllByPost(Post $post) { @@ -63,19 +52,19 @@ public function findAllByPost(Post $post) $constraints = []; $constraints[] = $query->equals('post', $post->getUid()); $constraints = $this->fillConstraintsBySettings($query, $constraints); - return $query->matching($query->logicalAnd($constraints))->execute(); + $statement = $query->matching($query->logicalAnd(...$constraints)); + $result = $statement->execute(); + + return $result; } /** - * @param string $filter - * @param int $blogSetup * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface - * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException */ public function findAllByFilter(string $filter = null, int $blogSetup = null) { $query = $this->createQuery(); - $querySettings = $this->objectManager->get(Typo3QuerySettings::class); + $querySettings = $query->getQuerySettings(); $querySettings->setRespectStoragePage(false); $query->setQuerySettings($querySettings); @@ -103,18 +92,14 @@ public function findAllByFilter(string $filter = null, int $blogSetup = null) $constraints[] = $query->in('pid', $this->getPostPidsByRootPid($blogSetup)); } if (count($constraints) > 0) { - return $query->matching($query->logicalAnd($constraints))->execute(); + return $query->matching($query->logicalAnd(...$constraints))->execute(); } return $this->findAll(); } /** - * @param int $limit - * @param int $blogSetup * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface - * @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException - * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException */ public function findActiveComments(int $limit = null, int $blogSetup = null) { @@ -132,13 +117,10 @@ public function findActiveComments(int $limit = null, int $blogSetup = null) $constraints[] = $query->in('pid', $storagePids); } } - return $query->matching($query->logicalAnd($constraints))->execute(); + + return $query->matching($query->logicalAnd(...$constraints))->execute(); } - /** - * @param int $blogRootPid - * @return array - */ protected function getPostPidsByRootPid(int $blogRootPid): array { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) @@ -148,8 +130,8 @@ protected function getPostPidsByRootPid(int $blogRootPid): array ->from('pages') ->where($queryBuilder->expr()->eq('doktype', Constants::DOKTYPE_BLOG_POST)) ->andWhere($queryBuilder->expr()->eq('pid', $blogRootPid)) - ->execute() - ->fetchAll(); + ->executeQuery() + ->fetchAllAssociative(); $result = []; foreach ($rows as $row) { $result[] = $row['uid']; @@ -158,13 +140,6 @@ protected function getPostPidsByRootPid(int $blogRootPid): array return $result; } - /** - * @param QueryInterface $query - * @param array $constraints - * @return array - * @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException - * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException - */ public function fillConstraintsBySettings(QueryInterface $query, array $constraints): array { $respectCommentsModeration = isset($this->settings['comments']['moderation']) @@ -177,8 +152,8 @@ public function fillConstraintsBySettings(QueryInterface $query, array $constrai } $respectPostLanguageId = isset($this->settings['comments']['respectPostLanguageId']) - ? (int)$this->settings['comments']['respectPostLanguageId'] - : 0; + ? (bool) $this->settings['comments']['respectPostLanguageId'] + : false; if ($respectPostLanguageId) { $constraints[] = $query->logicalOr([ $query->equals('postLanguageId', GeneralUtility::makeInstance(Context::class)->getAspect('language')->getId()), @@ -190,17 +165,18 @@ public function fillConstraintsBySettings(QueryInterface $query, array $constrai $constraints[] = $query->logicalAnd([ $query->logicalOr([ $query->equals('post.starttime', 0), - $query->lessThanOrEqual('post.starttime', $tstamp) + $query->lessThanOrEqual('post.starttime', $tstamp), ]), $query->logicalOr([ $query->equals('post.endtime', 0), - $query->greaterThanOrEqual('post.endtime', $tstamp) + $query->greaterThanOrEqual('post.endtime', $tstamp), ]) ]); $constraints[] = $query->logicalAnd([ $query->equals('post.hidden', 0), $query->equals('post.deleted', 0) ]); + return $constraints; } }