From 858f3edca3897413d46ba734ec571b40cf4a57db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Sun, 19 Jan 2025 13:17:26 +0100 Subject: [PATCH] fix: do not delete watchlist on error. Fixes #61 --- src/Controller/WatchListController.php | 11 ++++++++++- src/Entity/Domain.php | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Controller/WatchListController.php b/src/Controller/WatchListController.php index 303c41a..fa1d997 100644 --- a/src/Controller/WatchListController.php +++ b/src/Controller/WatchListController.php @@ -13,6 +13,7 @@ use App\Repository\WatchListRepository; use App\Service\ChatNotificationService; use App\Service\Connector\AbstractProvider; use Doctrine\Common\Collections\Collection; +use Doctrine\DBAL\LockMode; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Exception\ORMException; use Eluceo\iCal\Domain\Entity\Attendee; @@ -257,12 +258,20 @@ class WatchListController extends AbstractController 'token' => $watchList->getToken(), ]); - $this->em->remove($this->em->getReference(WatchList::class, $watchList->getToken())); + $this->em->beginTransaction(); + + /** @var WatchList $oldWatchlist */ + $oldWatchlist = $this->em->getReference(WatchList::class, $watchList->getToken()); + $this->em->lock($oldWatchlist, LockMode::PESSIMISTIC_WRITE); + + $this->em->remove($oldWatchlist); $this->em->flush(); $this->em->persist($watchList); $this->em->flush(); + $this->em->commit(); + return $watchList; } diff --git a/src/Entity/Domain.php b/src/Entity/Domain.php index 393856c..8558d80 100644 --- a/src/Entity/Domain.php +++ b/src/Entity/Domain.php @@ -471,6 +471,11 @@ class Domain return in_array('redemption period', $this->getStatus()); } + public function isPendingDelete(): bool + { + return in_array('pending delete', $this->getStatus()) && !in_array('redemption period', $this->getStatus()); + } + private function calculateDaysFromStatus($lastStatus, \DateTimeImmutable $now): ?int { if (in_array('pending delete', $lastStatus->getAddStatus()) && !$this->isRedemptionPeriod()) {