Merge branch 'hytha/hotfixes/error-on-saving-calendar' into staging

This commit is contained in:
Tiavina 2025-03-27 08:51:19 +03:00
commit 26260359b6
4 changed files with 160 additions and 144 deletions

View File

@ -32,7 +32,8 @@ use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use Psr\Log\LoggerInterface;
class CalendarObjectCreatedListener implements IEventListener {
class CalendarObjectCreatedListener implements IEventListener
{
/** @var LoggerInterface */
private $logger;
@ -41,12 +42,15 @@ class CalendarObjectCreatedListener implements IEventListener {
private $gestionService;
public function __construct(
LoggerInterface $logger,GestionService $gestionService) {
LoggerInterface $logger,
GestionService $gestionService
) {
$this->logger = $logger;
$this->gestionService = $gestionService;
}
public function handle(Event $event): void {
public function handle(Event $event): void
{
if (!($event instanceof CalendarObjectCreatedEvent)) {
return;
}
@ -54,11 +58,9 @@ class CalendarObjectCreatedListener implements IEventListener {
try {
$vCalendarString = $calendarData["calendardata"];
$this->gestionService->HandleCreatedCalendarObject($vCalendarString);
}
catch(\OC\OCS\Exception $e){
} catch (\OC\OCS\Exception $e) {
$this->logger->debug("Error while handling created calendar object: " . $e->getMessage());
}
catch(Exception $e){
} catch (\Throwable $e) {
$this->logger->debug("Error while handling created calendar object: " . $e->getMessage());
}
}

View File

@ -32,7 +32,8 @@ use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use Psr\Log\LoggerInterface;
class CalendarObjectMovedListener implements IEventListener {
class CalendarObjectMovedListener implements IEventListener
{
/** @var LoggerInterface */
private $logger;
@ -41,12 +42,15 @@ class CalendarObjectMovedListener implements IEventListener {
private $gestionService;
public function __construct(
LoggerInterface $logger,GestionService $gestionService) {
LoggerInterface $logger,
GestionService $gestionService
) {
$this->logger = $logger;
$this->gestionService = $gestionService;
}
public function handle(Event $event): void {
public function handle(Event $event): void
{
if (!($event instanceof CalendarObjectMovedEvent)) {
return;
}
@ -55,11 +59,9 @@ class CalendarObjectMovedListener implements IEventListener {
$targetCalendarId = $event->getTargetCalendarId();
$vCalendarString = $calendarData["calendardata"];
$this->gestionService->HandleCalendarObjectMoved($vCalendarString, $targetCalendarId);
}
catch(Exception $e){
} catch (\OC\OCS\Exception $e) {
$this->logger->debug("Error while handling calendar object moved event: " . $e->getMessage());
}
catch(Exception $e){
} catch (\Throwable $e) {
$this->logger->debug("Error while handling calendar object moved event: " . $e->getMessage());
}
}

View File

@ -33,7 +33,8 @@ use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use Psr\Log\LoggerInterface;
class CalendarObjectUpdatedListener implements IEventListener {
class CalendarObjectUpdatedListener implements IEventListener
{
/** @var LoggerInterface */
private $logger;
@ -42,12 +43,15 @@ class CalendarObjectUpdatedListener implements IEventListener {
private $gestionService;
public function __construct(
LoggerInterface $logger,GestionService $gestionService) {
LoggerInterface $logger,
GestionService $gestionService
) {
$this->logger = $logger;
$this->gestionService = $gestionService;
}
public function handle(Event $event): void {
public function handle(Event $event): void
{
if (!($event instanceof CalendarObjectUpdatedEvent)) {
return;
}
@ -55,11 +59,9 @@ class CalendarObjectUpdatedListener implements IEventListener {
try {
$vCalendarString = $calendarData["calendardata"];
$this->gestionService->HandleUpdatedCalendarObject($vCalendarString);
}
catch(\OC\OCS\Exception $e){
} catch (\OC\OCS\Exception $e) {
$this->logger->debug("Error while handling updated calendar object: " . $e->getMessage());
}
catch(Exception $e){
} catch (\Throwable $e) {
$this->logger->debug("Error while handling updated calendar object: " . $e->getMessage());
}
}

View File

@ -35,7 +35,8 @@ use OCP\IUserSession;
use Psr\Log\LoggerInterface;
use OCA\Gestion\Helpers\VCalendarHelpers;
class GestionService {
class GestionService
{
/** @var Bdd */
private $gestionBdd;
@ -51,19 +52,20 @@ class GestionService {
Bdd $gestionBdd,
LoggerInterface $logger,
TalkService $talkService,
IUserSession $userSession) {
IUserSession $userSession
) {
$this->logger = $logger;
$this->gestionBdd = $gestionBdd;
$this->talkService = $talkService;
try {
$this->userConnectedUuid = $userSession->getUser()->getUID();
}
catch(Exception){
} catch (Exception) {
$this->userConnectedUuid = BddConstant::DEFAULT_ADMIN_APP_ID_NEXTCLOUD;
}
}
private function GetIsCalendarPendingFromVCalendarString(string $vCalendarString): bool{
private function GetIsCalendarPendingFromVCalendarString(string $vCalendarString): bool
{
$isCalendarPending = false;
$isCalendarPendingValue = VCalendarHelpers::GetValueFromKeyInVCalendarString(VCalendarPropertyConstant::PROPERTY_IS_CALENDAR_PENDING, $vCalendarString);
if ($isCalendarPendingValue == "1") {
@ -72,7 +74,8 @@ class GestionService {
return $isCalendarPending;
}
private function GetIsLeaveFromVCalendarString(string $vCalendarString): bool{
private function GetIsLeaveFromVCalendarString(string $vCalendarString): bool
{
$isLeave = false;
$isLeaveValue = VCalendarHelpers::GetValueFromKeyInVCalendarString(VCalendarPropertyConstant::PROPERTY_IS_LEAVE, $vCalendarString);
if ($isLeaveValue == "1") {
@ -104,7 +107,8 @@ class GestionService {
return $thanatoId;
}
private function getPrincipalUsernameFromVCalendarString(string $vCalendarString){
private function getPrincipalUsernameFromVCalendarString(string $vCalendarString)
{
$calendarUuid = VCalendarHelpers::GetValueFromKeyInVCalendarString("UID", $vCalendarString);
$principalUsername = $this->gestionBdd->getCalendarOrganizerNameByCalendarObjectUuid($calendarUuid);
return $principalUsername;
@ -119,13 +123,15 @@ class GestionService {
return $names;
}
private function IsDevisAlreadyCreated($clientId,$locationId,$thanatoId,$defuntName,$calendarUuid="not-related"){
private function IsDevisAlreadyCreated($clientId, $locationId, $thanatoId, $defuntName, $calendarUuid = "not-related")
{
$defuntId = $this->gestionBdd->getLastDefuntIdByName($defuntName);
$devisId = $this->gestionBdd->getLastDevisIdFromVCalendarProperty($thanatoId, $clientId, $locationId, $defuntId, $calendarUuid);
return $devisId != null;
}
private function GetDevisCommentFromVCalendarString(string $vCalendarString){
private function GetDevisCommentFromVCalendarString(string $vCalendarString)
{
$commentValue = VCalendarHelpers::GetValueFromKeyInVCalendarString("COMMENT", $vCalendarString);
if ($commentValue == "") {
$commentValue = "Commentaire";
@ -142,13 +148,15 @@ class GestionService {
return $calendarUuid;
}
private function GetCalendarDateFromVCalendarString(string $vCalendarString){
private function GetCalendarDateFromVCalendarString(string $vCalendarString)
{
$calendarStartDate = VCalendarHelpers::GetDateStartOrDateEndFromVCalendarString('DTSTART', $vCalendarString);
$calendarStartDate = $calendarStartDate->format('Y-m-d');
return $calendarStartDate;
}
public function HandleCalendarObjectMovedToTrash(string $vCalendarString){
public function HandleCalendarObjectMovedToTrash(string $vCalendarString)
{
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
$devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid);
if ($devis != null) {
@ -157,7 +165,8 @@ class GestionService {
return true;
}
private function UpdateDevisDataByVCalendarString($devis,$vCalendarString){
private function UpdateDevisDataByVCalendarString($devis, $vCalendarString)
{
$requestedDefuntName = $this->GetCalendarSummaryFromVCalendarString($vCalendarString);
$defuntId = $this->gestionBdd->createOrUpdateDefuntByNameAndReturnDefuntId($devis['defunt_id'], $devis['defunt_nom'], $requestedDefuntName);
$this->gestionBdd->updateDevisDefunt($devis['id'], $defuntId, $devis['defunt_id']);
@ -180,7 +189,8 @@ class GestionService {
}
}
private function CheckIfDevisIsAlreadyUpdated($devis,$vCalendarString){
private function CheckIfDevisIsAlreadyUpdated($devis, $vCalendarString)
{
$requestedDefuntName = $this->GetCalendarSummaryFromVCalendarString($vCalendarString);
$requestedClientId = $this->GetClientIdFromVCalendarString($vCalendarString);
$requestLocationId = $this->GetLocationIdFromVCalendarString($vCalendarString);
@ -205,7 +215,8 @@ class GestionService {
$devis['date'] == $requestedDevisDate;
}
public function HandleUpdatedCalendarObject(string $vCalendarString){
public function HandleUpdatedCalendarObject(string $vCalendarString)
{
try {
$isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString);
if ($isCalendarForLeave) {
@ -231,22 +242,20 @@ class GestionService {
$devisTalkMessage = $this->gestionBdd->getDevisTalkRoomMessage($devis['id'], $userName);
$this->talkService->sendDevisTalkNotifications($devisTalkMessage, $userName, $this->userConnectedUuid);
}
}
else{
} else {
//update from calendar leave or calendar pending to calendar devis
$this->HandleCreatedCalendarObject($vCalendarString);
}
}
catch(\OC\OCS\Exception $e){
} catch (\OC\OCS\Exception $e) {
$this->logger->debug("Error while handling created calendar object: " . $e->getMessage());
}
catch(Exception $e){
} catch (\Throwable $e) {
$this->logger->debug("Error while handling created calendar object: " . $e->getMessage());
}
return true;
}
public function HandleCalendarObjectMoved(string $vCalendarString,$targetCalendarId){
public function HandleCalendarObjectMoved(string $vCalendarString, $targetCalendarId)
{
try {
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
$isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString);
@ -266,16 +275,15 @@ class GestionService {
}
}
}
}
catch(\OC\OCS\Exception $e){
} catch (\OC\OCS\Exception $e) {
$this->logger->debug("Error while handling calendar object moved event: " . $e->getMessage());
}
catch(Exception $e){
} catch (\Throwable $e) {
$this->logger->debug("Error while handling calendar object moved event: " . $e->getMessage());
}
}
public function HandleCreatedCalendarObject(string $vCalendarString){
public function HandleCreatedCalendarObject(string $vCalendarString)
{
try {
$isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString);
if ($isCalendarForLeave) {
@ -307,21 +315,21 @@ class GestionService {
$devisTalkMessage = $this->gestionBdd->getDevisTalkRoomMessage($devisId, $userName);
$this->talkService->sendDevisTalkNotifications($devisTalkMessage, $userName, $this->userConnectedUuid);
$this->gestionBdd->createDevisTrajetFromVCalendar($devisId, $userName);
}
catch(\OC\OCS\Exception $e){
} catch (\OC\OCS\Exception $e) {
$this->logger->debug("Error while handling created calendar object: " . $e->getMessage());
}
catch(Exception $e){
} catch (\Throwable $e) {
$this->logger->debug("Error while handling created calendar object: " . $e->getMessage());
}
}
private function GetThanatoNameFromVCalendarString($vCalendarString){
private function GetThanatoNameFromVCalendarString($vCalendarString)
{
$thanatoName = $this->getPrincipalUsernameFromVCalendarString($vCalendarString);
return $thanatoName ?? BddConstant::DEFAULT_ADMIN_APP_ID_NEXTCLOUD;
}
private function GetClientIdFromVCalendarString(string $vCalendarString){
private function GetClientIdFromVCalendarString(string $vCalendarString)
{
$this->logger->debug($vCalendarString);
$clientValue = VCalendarHelpers::GetValueFromKeyInVCalendarString("CLIENT", $vCalendarString);
if ($clientValue == null || $clientValue == "") {
@ -330,7 +338,8 @@ class GestionService {
return (int) $clientValue;
}
private function GetLocationIdFromVCalendarString(string $vCalendarString){
private function GetLocationIdFromVCalendarString(string $vCalendarString)
{
$locationValue = VCalendarHelpers::GetValueFromKeyInVCalendarString("LOCATION", $vCalendarString);
if ($locationValue == null || $locationValue == "") {
$locationValue = 0;
@ -338,7 +347,8 @@ class GestionService {
return (int) $locationValue;
}
private function GetArticlesNameFromVCalendarString(string $vCalendarString): array {
private function GetArticlesNameFromVCalendarString(string $vCalendarString): array
{
$devisArticleValue = VCalendarHelpers::GetValueFromKeyInVCalendarString("DESCRIPTION", $vCalendarString);
$articles = explode('\;', $devisArticleValue);
$mapped = array_map('trim', $articles);