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 committed 2020-07-05 13:33:02 +02:00
1 parent 631582a912
commit 6cafac1b65
2 files changed
+4 -5

No files matched your search

+2 -1
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);
}
@@ -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);
}
}