From 6ac8fc9eccccb7c838314c2bb24d9417e44a677c Mon Sep 17 00:00:00 2001 From: Tiavina Date: Wed, 26 Mar 2025 19:50:54 +0300 Subject: [PATCH] add error handling for calendar object moved events in GestionService --- .../Listener/CalendarObjectMovedListener.php | 15 ++++++-- gestion/lib/Service/GestionService.php | 34 ++++++++++++------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/gestion/lib/Listener/CalendarObjectMovedListener.php b/gestion/lib/Listener/CalendarObjectMovedListener.php index ec6f6b6..e2f7320 100644 --- a/gestion/lib/Listener/CalendarObjectMovedListener.php +++ b/gestion/lib/Listener/CalendarObjectMovedListener.php @@ -25,6 +25,7 @@ declare(strict_types=1); namespace OCA\Gestion\Listener; +use Exception; use OCA\DAV\Events\CalendarObjectMovedEvent; use OCA\Gestion\Service\GestionService; use OCP\EventDispatcher\Event; @@ -50,9 +51,17 @@ class CalendarObjectMovedListener implements IEventListener { return; } $calendarData = $event->getObjectData(); - $targetCalendarId = $event->getTargetCalendarId(); - $vCalendarString = $calendarData["calendardata"]; - $this->gestionService->HandleCalendarObjectMoved($vCalendarString,$targetCalendarId); + try{ + $targetCalendarId = $event->getTargetCalendarId(); + $vCalendarString = $calendarData["calendardata"]; + $this->gestionService->HandleCalendarObjectMoved($vCalendarString,$targetCalendarId); + } + catch(Exception $e){ + $this->logger->error("Error while handling calendar object moved event: ".$e->getMessage()); + } + catch(Exception $e){ + $this->logger->error("Error while handling calendar object moved event: ".$e->getMessage()); + } } } diff --git a/gestion/lib/Service/GestionService.php b/gestion/lib/Service/GestionService.php index ffeaffe..6926b10 100644 --- a/gestion/lib/Service/GestionService.php +++ b/gestion/lib/Service/GestionService.php @@ -247,24 +247,32 @@ class GestionService { } public function HandleCalendarObjectMoved(string $vCalendarString,$targetCalendarId){ - $calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString); - $isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString); - $isCalendarDevis = $isCalendarForLeave == false; - if($isCalendarDevis){ - $devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid); - if($devis != null){ - $userPrincipalName = $this->gestionBdd->getCalendarPrincipalNameByCalendarId($targetCalendarId); - if($userPrincipalName != null){ - $thanatoId = $this->gestionBdd->getThanatoIdByUserUuid($userPrincipalName); - if($thanatoId != null){ - $thanatoHasBeenChanged = $thanatoId != $devis["id_thanato"]; - if($thanatoHasBeenChanged){ - $this->gestionBdd->updateDevisThanato($devis['id'],$thanatoId); + try{ + $calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString); + $isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString); + $isCalendarDevis = $isCalendarForLeave == false; + if($isCalendarDevis){ + $devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid); + if($devis != null){ + $userPrincipalName = $this->gestionBdd->getCalendarPrincipalNameByCalendarId($targetCalendarId); + if($userPrincipalName != null){ + $thanatoId = $this->gestionBdd->getThanatoIdByUserUuid($userPrincipalName); + if($thanatoId != null){ + $thanatoHasBeenChanged = $thanatoId != $devis["id_thanato"]; + if($thanatoHasBeenChanged){ + $this->gestionBdd->updateDevisThanato($devis['id'],$thanatoId); + } } } } } } + catch(\OC\OCS\Exception $e){ + $this->logger->error("Error while handling calendar object moved event: ".$e->getMessage()); + } + catch(Exception $e){ + $this->logger->error("Error while handling calendar object moved event: ".$e->getMessage()); + } } public function HandleCreatedCalendarObject(string $vCalendarString){