From 3851dda3467f550a59eebadd660b451e8c1e0cf0 Mon Sep 17 00:00:00 2001 From: Riad Date: Wed, 30 Oct 2024 17:54:20 +0100 Subject: [PATCH] [TASK] Add todos for refactoring of PollConnector and Resolve version conflicts --- .ddev/commands/host/setup11 | 2 +- Classes/Controller/PollController.php | 19 +++++++++++++++++++ Classes/Domain/Model/BasePoll.php | 4 ++++ Classes/Domain/Repository/PollRepository.php | 19 ++++++++++++------- .../Event/Permission/PermissionCheckEvent.php | 4 ++-- .../Traits/Model/DynamicUserProperties.php | 8 +++++++- ext_emconf.php | 2 +- rector.php | 1 + 8 files changed, 47 insertions(+), 12 deletions(-) diff --git a/.ddev/commands/host/setup11 b/.ddev/commands/host/setup11 index 8e443de..398414f 100755 --- a/.ddev/commands/host/setup11 +++ b/.ddev/commands/host/setup11 @@ -6,7 +6,7 @@ ## ProjectTypes: typo3 ## ExecRaw: true -rm -rf var/cache .Build vendor || true +rm -rf composer.lock var/cache .Build vendor || true ddev composer install echo "DROP DATABASE db; CREATE DATABASE db;" | ddev mysql ddev import-db --file=seeds/db.sql.gz diff --git a/Classes/Controller/PollController.php b/Classes/Controller/PollController.php index 2265773..20fe170 100644 --- a/Classes/Controller/PollController.php +++ b/Classes/Controller/PollController.php @@ -189,6 +189,8 @@ public function listAction(): ResponseInterface } /** + * @todo: add proper return types + * * @\TYPO3\CMS\Extbase\Annotation\IgnoreValidation("poll") */ public function showAction(BasePoll $poll): ResponseInterface @@ -229,6 +231,7 @@ public function showAction(BasePoll $poll): ResponseInterface $this->view->assign('poll', $poll); $this->view->assign('vote', $vote); + $newOptionValues = $event->getNewOptionValues(); if (!empty($newOptionValues)) { $this->view->assign('newOptionValues', $event->getNewOptionValues()); } @@ -243,6 +246,8 @@ public function showAction(BasePoll $poll): ResponseInterface } /** + * @todo: add proper return types + * * @TYPO3\CMS\Extbase\Annotation\Validate("FGTCLB\T3oodle\Domain\Validator\CustomVoteValidator", param="vote") */ public function voteAction(\FGTCLB\T3oodle\Domain\Model\Vote $vote): void @@ -281,6 +286,8 @@ public function voteAction(\FGTCLB\T3oodle\Domain\Model\Vote $vote): void } /** + * @todo: add proper return types + * * @\TYPO3\CMS\Extbase\Annotation\IgnoreValidation("poll") */ public function resetVotesAction(BasePoll $poll): void @@ -303,6 +310,8 @@ public function resetVotesAction(BasePoll $poll): void } /** + * @todo: add proper return types + * * @\TYPO3\CMS\Extbase\Annotation\IgnoreValidation("vote") */ public function deleteOwnVoteAction(\FGTCLB\T3oodle\Domain\Model\Vote $vote): void @@ -322,6 +331,8 @@ public function deleteOwnVoteAction(\FGTCLB\T3oodle\Domain\Model\Vote $vote): vo } /** + * @todo: add proper return types + * * @param int $option uid to finish * @\TYPO3\CMS\Extbase\Annotation\IgnoreValidation("poll") */ @@ -355,6 +366,8 @@ public function finishAction(BasePoll $poll, int $option = 0): void } /** + * @todo add proper return types + * * @\TYPO3\CMS\Extbase\Annotation\IgnoreValidation("poll") */ public function finishSuggestionModeAction(BasePoll $poll): void @@ -399,6 +412,8 @@ public function newSuggestionAction( } /** + * @todo: add proper return types + * * @\TYPO3\CMS\Extbase\Annotation\Validate("FGTCLB\T3oodle\Domain\Validator\SuggestionDtoValidator", param="suggestionDto") */ public function createSuggestionAction(SuggestionDto $suggestionDto): void @@ -700,6 +715,8 @@ public function editAction(BasePoll $poll): ResponseInterface } /** + * @todo Ensure proper return type is set + * * @TYPO3\CMS\Extbase\Annotation\Validate("FGTCLB\T3oodle\Domain\Validator\CustomPollValidator", param="poll") */ public function updateAction(BasePoll $poll): void @@ -741,6 +758,8 @@ public function updateAction(BasePoll $poll): void } /** + * @todo Ensure proper return type is set + * * @TYPO3\CMS\Extbase\Annotation\Validate("FGTCLB\T3oodle\Domain\Validator\CustomPollValidator", param="poll") */ public function deleteAction(BasePoll $poll): void diff --git a/Classes/Domain/Model/BasePoll.php b/Classes/Domain/Model/BasePoll.php index 1e9ac96..ab1d696 100644 --- a/Classes/Domain/Model/BasePoll.php +++ b/Classes/Domain/Model/BasePoll.php @@ -685,11 +685,15 @@ public function getStatus(): PollStatus return new PollStatus(PollStatus::CLOSED); } + // @todo: Check if $this->type() can be used instead of static::class + // @todo: Verify if static::class is appropriate in this context public function isSimplePoll(): bool { return stripos(static::class, 'simple') !== false; } + // @todo: Check if $this->type() can be used instead of static::class + // @todo: Verify if static::class is appropriate in this context public function isSchedulePoll(): bool { return stripos(static::class, 'schedule') !== false; diff --git a/Classes/Domain/Repository/PollRepository.php b/Classes/Domain/Repository/PollRepository.php index 085e957..56a3979 100644 --- a/Classes/Domain/Repository/PollRepository.php +++ b/Classes/Domain/Repository/PollRepository.php @@ -21,10 +21,7 @@ class PollRepository extends \TYPO3\CMS\Extbase\Persistence\Repository { - /** - * @var EventDispatcherInterface - */ - protected $eventDispatcher; + protected EventDispatcherInterface $eventDispatcher; private UserService $userService; @@ -85,9 +82,7 @@ public function findPolls( $andConstraints[] = $query->equals('isPublished', true); } - if ($orConstraints !== []) { - $andConstraints[] = $query->logicalOr($orConstraints); - } + $andConstraints[] = $query->logicalOr($orConstraints); $andConstraints[] = $query->logicalNot($query->equals('slug', '')); @@ -106,6 +101,11 @@ public function setControllerSettings(array $settings): void $this->controllerSettings = $settings; } + /** + * Retrieves the poll type by its unique identifier (UID). + * + * @throws \RuntimeException If the poll is not found. + */ public function getPollTypeByUid(int $poll): string { /** @var ConnectionPool $pool */ @@ -118,9 +118,14 @@ public function getPollTypeByUid(int $poll): string 'uid', $queryBuilder->createNamedParameter($poll, Connection::PARAM_INT) )) + ->setMaxResults(1) ->executeQuery() ->fetchAssociative(); + if ($result === false) { + throw new \RuntimeException('Poll not found', 1730287624); + } + return $result['type']; } diff --git a/Classes/Event/Permission/PermissionCheckEvent.php b/Classes/Event/Permission/PermissionCheckEvent.php index f090451..6ab8e95 100644 --- a/Classes/Event/Permission/PermissionCheckEvent.php +++ b/Classes/Event/Permission/PermissionCheckEvent.php @@ -22,9 +22,9 @@ public function getCurrentStatus(): bool return $this->currentStatus; } - public function setCurrentStatus(bool $status = null): void + public function setCurrentStatus(bool $status): void { - $status ?? $this->currentStatus; + $this->currentStatus = $status; } public function getArguments(): array diff --git a/Classes/Traits/Model/DynamicUserProperties.php b/Classes/Traits/Model/DynamicUserProperties.php index 7b45e9b..720592b 100644 --- a/Classes/Traits/Model/DynamicUserProperties.php +++ b/Classes/Traits/Model/DynamicUserProperties.php @@ -67,7 +67,7 @@ private function getUserRow(int $uid): ?array $pool = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class); $connection = $pool->getConnectionForTable('fe_users'); $queryBuilder = $connection->createQueryBuilder(); - self::$userRowCache[$uid] = $queryBuilder + $result = $queryBuilder ->select('uid', self::$typoscriptSettings['frontendUserNameField']) ->from('fe_users') ->where($queryBuilder->expr()->eq( @@ -78,6 +78,12 @@ private function getUserRow(int $uid): ?array ->executeQuery() ->fetchAssociative(); + if ($result === false) { + return null; + } + + self::$userRowCache[$uid] = $result; + return self::$userRowCache[$uid]; } } diff --git a/ext_emconf.php b/ext_emconf.php index 58ecf53..70e2f94 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -18,7 +18,7 @@ 'author_company' => 'FGTCLB', 'constraints' => [ 'depends' => [ - 'typo3' => '10.4.0-11.5.99', + 'typo3' => '11.5.99', ], 'conflicts' => [], 'suggests' => [], diff --git a/rector.php b/rector.php index 63602ec..d396d88 100644 --- a/rector.php +++ b/rector.php @@ -37,6 +37,7 @@ $rectorConfig->skip([ __DIR__ . '/.Build/*', + __DIR__ . '/.ddev/*', ]); // Rewrite your extbase persistence class mapping from typoscript into php according to official docs.