Skip to content

Commit

Permalink
fix #3393
Browse files Browse the repository at this point in the history
Signed-off-by: dartcafe <github@dartcafe.de>
  • Loading branch information
dartcafe committed Mar 28, 2024
1 parent f8b873a commit 181599b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/Db/PollMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ protected function buildQuery(): IQueryBuilder {
->from($this->getTableName(), self::TABLE);
$this->joinOptionsForMaxDate($qb, self::TABLE);
$this->joinCurrentUserVotes($qb, self::TABLE, $currentUserId);
$this->joinUserRole($qb, self::TABLE, $currentUserId);
$qb->groupBy(self::TABLE . '.id');
return $qb;
}
Expand All @@ -192,7 +191,9 @@ protected function buildQuery(): IQueryBuilder {
*/
protected function joinUserRole(IQueryBuilder &$qb, string $fromAlias, string $currentUserId): void {

Check failure on line 192 in lib/Db/PollMapper.php

View workflow job for this annotation

GitHub Actions / Psalm (master, 8.1)

PossiblyUnusedMethod

lib/Db/PollMapper.php:192:21: PossiblyUnusedMethod: Cannot find any calls to method OCA\Polls\Db\PollMapper::joinUserRole (see https://psalm.dev/087)
$joinAlias = 'shares';
$qb->addSelect($qb->createFunction('coalesce(' . $joinAlias . '.type, "") AS user_role'));
$emptyString = $qb->createNamedParameter("", IQueryBuilder::PARAM_STR);

$qb->addSelect($qb->createFunction('coalesce(' . $joinAlias . '.type,'. $emptyString . ') AS user_role'));
$qb->selectAlias($joinAlias . '.locked', 'is_current_user_locked');

$qb->leftJoin(
Expand All @@ -205,6 +206,8 @@ protected function joinUserRole(IQueryBuilder &$qb, string $fromAlias, string $c
$qb->expr()->eq($joinAlias . '.deleted', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)),
)
);
$qb->addGroupBy($joinAlias . '.type');
$qb->addGroupBy($joinAlias . '.locked');
}

/**
Expand All @@ -215,9 +218,11 @@ protected function joinUserRole(IQueryBuilder &$qb, string $fromAlias, string $c
*/
protected function joinOptionsForMaxDate(IQueryBuilder &$qb, string $fromAlias): void {
$joinAlias = 'options';
$saveMin = (string) time();

$qb->addSelect($qb->createFunction('coalesce(MAX(' . $joinAlias . '.timestamp), 0) AS max_date'))
$zero = $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT);
$saveMin = $qb->createNamedParameter(time(), IQueryBuilder::PARAM_INT);

$qb->addSelect($qb->createFunction('coalesce(MAX(' . $joinAlias . '.timestamp), '. $zero . ') AS max_date'))
->addSelect($qb->createFunction('coalesce(MIN(' . $joinAlias . '.timestamp), ' . $saveMin . ') AS min_date'));

$qb->leftJoin(
Expand Down

0 comments on commit 181599b

Please sign in to comment.