Merge branch 'staging' into releases/release-hytha-prod

This commit is contained in:
Tiavina 2025-03-26 19:43:51 +03:00
commit 12a751c1c3
3 changed files with 90 additions and 55 deletions

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace OCA\Gestion\Listener;
use Exception;
use OCA\DAV\Events\CalendarObjectCreatedEvent;
use OCA\Gestion\Service\GestionService;
use OCP\EventDispatcher\Event;
@ -50,8 +51,16 @@ class CalendarObjectCreatedListener implements IEventListener {
return;
}
$calendarData = $event->getObjectData();
$vCalendarString = $calendarData["calendardata"];
$this->gestionService->HandleCreatedCalendarObject($vCalendarString);
try{
$vCalendarString = $calendarData["calendardata"];
$this->gestionService->HandleCreatedCalendarObject($vCalendarString);
}
catch(\OC\OCS\Exception $e){
$this->logger->error("Error while handling created calendar object: ".$e->getMessage());
}
catch(Exception $e){
$this->logger->error("Error while handling created calendar object: ".$e->getMessage());
}
}
}

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace OCA\Gestion\Listener;
use Exception;
use OCA\DAV\Events\CalendarObjectCreatedEvent;
use OCA\DAV\Events\CalendarObjectUpdatedEvent;
use OCA\Gestion\Service\GestionService;
@ -51,8 +52,16 @@ class CalendarObjectUpdatedListener implements IEventListener {
return;
}
$calendarData = $event->getObjectData();
$vCalendarString = $calendarData["calendardata"];
$this->gestionService->HandleUpdatedCalendarObject($vCalendarString);
try{
$vCalendarString = $calendarData["calendardata"];
$this->gestionService->HandleUpdatedCalendarObject($vCalendarString);
}
catch(\OC\OCS\Exception $e){
$this->logger->error("Error while handling updated calendar object: ".$e->getMessage());
}
catch(Exception $e){
$this->logger->error("Error while handling updated calendar object: ".$e->getMessage());
}
}
}

View File

@ -26,6 +26,7 @@ declare(strict_types=1);
namespace OCA\Gestion\Service;
use Exception;
use OCA\Gestion\Constants\BddConstant;
use OCA\Gestion\Constants\DevisMentionConstant;
use OCA\Gestion\Constants\VCalendarPropertyConstant;
@ -205,34 +206,42 @@ class GestionService {
}
public function HandleUpdatedCalendarObject(string $vCalendarString){
$isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString);
if($isCalendarForLeave){
//from devis calendar to leave calendar
try{
$isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString);
if($isCalendarForLeave){
//from devis calendar to leave calendar
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
$devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid);
if($devis != null){
$this->gestionBdd->updateDevisMentionToCanceled($devis['id']);
}
return;
}
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
$devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid);
if($devis != null){
$this->gestionBdd->updateDevisMentionToCanceled($devis['id']);
$isDevisAlreadyUpdated = $this->CheckIfDevisIsAlreadyUpdated($devis,$vCalendarString);
if($isDevisAlreadyUpdated){
return true;
}
$devisIsAlreadyFactured = $devis['mentions'] == DevisMentionConstant::FACTURED || $devis['mentions'] == DevisMentionConstant::FACTURED_FORMATTED;
$this->UpdateDevisDataByVCalendarString($devis,$vCalendarString);
if($devisIsAlreadyFactured == false){
$userName = $this->GetThanatoNameFromVCalendarString($vCalendarString);
$devisTalkMessage = $this->gestionBdd->getDevisTalkRoomMessage($devis['id'],$userName);
$this->talkService->sendDevisTalkNotifications($devisTalkMessage,$userName,$this->userConnectedUuid);
}
}
return;
}
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
$devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid);
if($devis != null){
$isDevisAlreadyUpdated = $this->CheckIfDevisIsAlreadyUpdated($devis,$vCalendarString);
if($isDevisAlreadyUpdated){
return true;
}
$devisIsAlreadyFactured = $devis['mentions'] == DevisMentionConstant::FACTURED || $devis['mentions'] == DevisMentionConstant::FACTURED_FORMATTED;
$this->UpdateDevisDataByVCalendarString($devis,$vCalendarString);
if($devisIsAlreadyFactured == false){
$userName = $this->GetThanatoNameFromVCalendarString($vCalendarString);
$devisTalkMessage = $this->gestionBdd->getDevisTalkRoomMessage($devis['id'],$userName);
$this->talkService->sendDevisTalkNotifications($devisTalkMessage,$userName,$this->userConnectedUuid);
else{
//update from calendar leave or calendar pending to calendar devis
$this->HandleCreatedCalendarObject($vCalendarString);
}
}
else{
//update from calendar leave or calendar pending to calendar devis
$this->HandleCreatedCalendarObject($vCalendarString);
catch(\OC\OCS\Exception $e){
$this->logger->error("Error while handling created calendar object: ".$e->getMessage());
}
catch(Exception $e){
$this->logger->error("Error while handling created calendar object: ".$e->getMessage());
}
return true;
}
@ -258,37 +267,45 @@ class GestionService {
}
}
public function HandleCreatedCalendarObject(string $vCalendarString){
$isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString);
if($isCalendarForLeave){
return;
public function HandleCreatedCalendarObject(string $vCalendarString){
try{
$isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString);
if($isCalendarForLeave){
return;
}
$isCalendarPending = $this->GetIsCalendarPendingFromVCalendarString($vCalendarString);
if($isCalendarPending){
return;
}
$calendarSummary = $this->GetCalendarSummaryFromVCalendarString($vCalendarString);
$clientId = $this->GetClientIdFromVCalendarString($vCalendarString);
$locationId = $this->GetLocationIdFromVCalendarString($vCalendarString);
$thanatoId = $this->GetThanatoIdFromVCalendarString($vCalendarString);
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
$userName = $this->GetThanatoNameFromVCalendarString($vCalendarString);
$devisAlreadyCreated = $this->IsDevisAlreadyCreated($clientId,$locationId,$thanatoId,$calendarSummary,$calendarUuid);
if($devisAlreadyCreated){
return;
}
$defuntId = $this->gestionBdd->insertDefuntByNameAndReturnId($calendarSummary);
$calendarStartDate = $this->GetCalendarDateFromVCalendarString($vCalendarString);
$devisComment = $this->GetDevisCommentFromVCalendarString($vCalendarString);
$devisId = $this->gestionBdd->insertDevisFromVCalendarAndReturnId($thanatoId,$clientId,$locationId,$defuntId,$calendarUuid,$calendarStartDate,$devisComment);
$articlesValue = $this->GetArticlesNameFromVCalendarString($vCalendarString);
if(!empty($articlesValue)){
$articleIds = $this->gestionBdd->getArticleIdsByArticleReferences($articlesValue);
$this->gestionBdd->insertDevisArticleFromDevisIdAndArticlesIdArray($devisId, $articleIds);
}
$devisTalkMessage = $this->gestionBdd->getDevisTalkRoomMessage($devisId,$userName);
$this->talkService->sendDevisTalkNotifications($devisTalkMessage,$userName,$this->userConnectedUuid);
$this->gestionBdd->createDevisTrajetFromVCalendar($devisId,$userName);
}
catch(\OC\OCS\Exception $e){
$this->logger->error("Error while handling created calendar object: ".$e->getMessage());
}
$isCalendarPending = $this->GetIsCalendarPendingFromVCalendarString($vCalendarString);
if($isCalendarPending){
return;
catch(Exception $e){
$this->logger->error("Error while handling created calendar object: ".$e->getMessage());
}
$calendarSummary = $this->GetCalendarSummaryFromVCalendarString($vCalendarString);
$clientId = $this->GetClientIdFromVCalendarString($vCalendarString);
$locationId = $this->GetLocationIdFromVCalendarString($vCalendarString);
$thanatoId = $this->GetThanatoIdFromVCalendarString($vCalendarString);
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
$userName = $this->GetThanatoNameFromVCalendarString($vCalendarString);
$devisAlreadyCreated = $this->IsDevisAlreadyCreated($clientId,$locationId,$thanatoId,$calendarSummary,$calendarUuid);
if($devisAlreadyCreated){
return;
}
$defuntId = $this->gestionBdd->insertDefuntByNameAndReturnId($calendarSummary);
$calendarStartDate = $this->GetCalendarDateFromVCalendarString($vCalendarString);
$devisComment = $this->GetDevisCommentFromVCalendarString($vCalendarString);
$devisId = $this->gestionBdd->insertDevisFromVCalendarAndReturnId($thanatoId,$clientId,$locationId,$defuntId,$calendarUuid,$calendarStartDate,$devisComment);
$articlesValue = $this->GetArticlesNameFromVCalendarString($vCalendarString);
if(!empty($articlesValue)){
$articleIds = $this->gestionBdd->getArticleIdsByArticleReferences($articlesValue);
$this->gestionBdd->insertDevisArticleFromDevisIdAndArticlesIdArray($devisId, $articleIds);
}
$devisTalkMessage = $this->gestionBdd->getDevisTalkRoomMessage($devisId,$userName);
$this->talkService->sendDevisTalkNotifications($devisTalkMessage,$userName,$this->userConnectedUuid);
$this->gestionBdd->createDevisTrajetFromVCalendar($devisId,$userName);
}
private function GetThanatoNameFromVCalendarString($vCalendarString){