fix: do not delete watchlist on error. Fixes #61

This commit is contained in:
Maël Gangloff
2025-01-19 13:17:26 +01:00
parent 92bf6e362c
commit 858f3edca3
2 changed files with 15 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ use App\Repository\WatchListRepository;
use App\Service\ChatNotificationService; use App\Service\ChatNotificationService;
use App\Service\Connector\AbstractProvider; use App\Service\Connector\AbstractProvider;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Exception\ORMException; use Doctrine\ORM\Exception\ORMException;
use Eluceo\iCal\Domain\Entity\Attendee; use Eluceo\iCal\Domain\Entity\Attendee;
@@ -257,12 +258,20 @@ class WatchListController extends AbstractController
'token' => $watchList->getToken(), '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->flush();
$this->em->persist($watchList); $this->em->persist($watchList);
$this->em->flush(); $this->em->flush();
$this->em->commit();
return $watchList; return $watchList;
} }

View File

@@ -471,6 +471,11 @@ class Domain
return in_array('redemption period', $this->getStatus()); 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 private function calculateDaysFromStatus($lastStatus, \DateTimeImmutable $now): ?int
{ {
if (in_array('pending delete', $lastStatus->getAddStatus()) && !$this->isRedemptionPeriod()) { if (in_array('pending delete', $lastStatus->getAddStatus()) && !$this->isRedemptionPeriod()) {