From 6cafac1b6514287e2fffed845ab9d2e6b95db72c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 5 Jul 2020 13:32:15 +0200 Subject: [PATCH] MAPG-142 modify UserConfirmationRepository to return only one confirmation for user (it is not possible for an user to have multiple) --- src/Controller/UserController.php | 3 ++- src/Repository/UserConfirmationRepository.php | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 83f3c89..18b4dee 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -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); } diff --git a/src/Repository/UserConfirmationRepository.php b/src/Repository/UserConfirmationRepository.php index 5c0723e..d7d80ad 100644 --- a/src/Repository/UserConfirmationRepository.php +++ b/src/Repository/UserConfirmationRepository.php @@ -1,8 +1,6 @@ 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); } }