MAPG-142 modify UserConfirmationRepository to return only one confirmation for user

(it is not possible for an user to have multiple)
This commit is contained in:
Bence Pőcze 2020-07-05 13:32:15 +02:00
parent 631582a912
commit 6cafac1b65
Signed by: bence
GPG Key ID: AA52B11A3269D1C1
2 changed files with 4 additions and 5 deletions

View File

@ -184,7 +184,8 @@ class UserController implements ISecured
\Container::$dbConnection->startTransaction();
foreach ($this->userConfirmationRepository->getByUser($user) as $userConfirmation) {
$userConfirmation = $this->userConfirmationRepository->getByUser($user);
if ($userConfirmation !== null) {
$this->pdm->deleteFromDb($userConfirmation);
}

View File

@ -1,8 +1,6 @@
<?php namespace MapGuesser\Repository;
use Generator;
use MapGuesser\Database\Query\Select;
use MapGuesser\Interfaces\Database\IResultSet;
use MapGuesser\PersistentData\Model\User;
use MapGuesser\PersistentData\Model\UserConfirmation;
use MapGuesser\PersistentData\PersistentDataManager;
@ -29,11 +27,11 @@ class UserConfirmationRepository
return $this->pdm->selectFromDb($select, UserConfirmation::class);
}
public function getByUser(User $user): Generator
public function getByUser(User $user): ?UserConfirmation
{
$select = new Select(\Container::$dbConnection);
$select->where('user_id', '=', $user->getId());
yield from $this->pdm->selectMultipleFromDb($select, UserConfirmation::class);
return $this->pdm->selectFromDb($select, UserConfirmation::class);
}
}