Skip to content

Commit

Permalink
[TASK] Add todos for refactoring of PollConnector and Resolve version…
Browse files Browse the repository at this point in the history
… conflicts
  • Loading branch information
Riiiad committed Oct 30, 2024
1 parent e373a80 commit 3851dda
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .ddev/commands/host/setup11
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions Classes/Controller/PollController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Classes/Domain/Model/BasePoll.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 12 additions & 7 deletions Classes/Domain/Repository/PollRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@

class PollRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;
protected EventDispatcherInterface $eventDispatcher;

private UserService $userService;

Expand Down Expand Up @@ -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', ''));

Expand All @@ -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 */
Expand All @@ -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'];
}

Expand Down
4 changes: 2 additions & 2 deletions Classes/Event/Permission/PermissionCheckEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion Classes/Traits/Model/DynamicUserProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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];
}
}
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'author_company' => 'FGTCLB',
'constraints' => [
'depends' => [
'typo3' => '10.4.0-11.5.99',
'typo3' => '11.5.99',
],
'conflicts' => [],
'suggests' => [],
Expand Down
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

$rectorConfig->skip([
__DIR__ . '/.Build/*',
__DIR__ . '/.ddev/*',
]);

// Rewrite your extbase persistence class mapping from typoscript into php according to official docs.
Expand Down

0 comments on commit 3851dda

Please sign in to comment.