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\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;
}