Merge branch 'hytha/hotfixes/error-on-saving-calendar' into staging
This commit is contained in:
commit
26260359b6
@ -32,7 +32,8 @@ use OCP\EventDispatcher\Event;
|
|||||||
use OCP\EventDispatcher\IEventListener;
|
use OCP\EventDispatcher\IEventListener;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class CalendarObjectCreatedListener implements IEventListener {
|
class CalendarObjectCreatedListener implements IEventListener
|
||||||
|
{
|
||||||
|
|
||||||
/** @var LoggerInterface */
|
/** @var LoggerInterface */
|
||||||
private $logger;
|
private $logger;
|
||||||
@ -41,25 +42,26 @@ class CalendarObjectCreatedListener implements IEventListener {
|
|||||||
private $gestionService;
|
private $gestionService;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
LoggerInterface $logger,GestionService $gestionService) {
|
LoggerInterface $logger,
|
||||||
|
GestionService $gestionService
|
||||||
|
) {
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->gestionService = $gestionService;
|
$this->gestionService = $gestionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(Event $event): void {
|
public function handle(Event $event): void
|
||||||
|
{
|
||||||
if (!($event instanceof CalendarObjectCreatedEvent)) {
|
if (!($event instanceof CalendarObjectCreatedEvent)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$calendarData = $event->getObjectData();
|
$calendarData = $event->getObjectData();
|
||||||
try{
|
try {
|
||||||
$vCalendarString = $calendarData["calendardata"];
|
$vCalendarString = $calendarData["calendardata"];
|
||||||
$this->gestionService->HandleCreatedCalendarObject($vCalendarString);
|
$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());
|
||||||
$this->logger->debug("Error while handling created calendar object: ".$e->getMessage());
|
} catch (\Throwable $e) {
|
||||||
}
|
$this->logger->debug("Error while handling created calendar object: " . $e->getMessage());
|
||||||
catch(Exception $e){
|
|
||||||
$this->logger->debug("Error while handling created calendar object: ".$e->getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,8 @@ use OCP\EventDispatcher\Event;
|
|||||||
use OCP\EventDispatcher\IEventListener;
|
use OCP\EventDispatcher\IEventListener;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class CalendarObjectMovedListener implements IEventListener {
|
class CalendarObjectMovedListener implements IEventListener
|
||||||
|
{
|
||||||
|
|
||||||
/** @var LoggerInterface */
|
/** @var LoggerInterface */
|
||||||
private $logger;
|
private $logger;
|
||||||
@ -41,26 +42,27 @@ class CalendarObjectMovedListener implements IEventListener {
|
|||||||
private $gestionService;
|
private $gestionService;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
LoggerInterface $logger,GestionService $gestionService) {
|
LoggerInterface $logger,
|
||||||
|
GestionService $gestionService
|
||||||
|
) {
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->gestionService = $gestionService;
|
$this->gestionService = $gestionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(Event $event): void {
|
public function handle(Event $event): void
|
||||||
|
{
|
||||||
if (!($event instanceof CalendarObjectMovedEvent)) {
|
if (!($event instanceof CalendarObjectMovedEvent)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$calendarData = $event->getObjectData();
|
$calendarData = $event->getObjectData();
|
||||||
try{
|
try {
|
||||||
$targetCalendarId = $event->getTargetCalendarId();
|
$targetCalendarId = $event->getTargetCalendarId();
|
||||||
$vCalendarString = $calendarData["calendardata"];
|
$vCalendarString = $calendarData["calendardata"];
|
||||||
$this->gestionService->HandleCalendarObjectMoved($vCalendarString,$targetCalendarId);
|
$this->gestionService->HandleCalendarObjectMoved($vCalendarString, $targetCalendarId);
|
||||||
}
|
} catch (\OC\OCS\Exception $e) {
|
||||||
catch(Exception $e){
|
$this->logger->debug("Error while handling calendar object moved event: " . $e->getMessage());
|
||||||
$this->logger->debug("Error while handling calendar object moved event: ".$e->getMessage());
|
} catch (\Throwable $e) {
|
||||||
}
|
$this->logger->debug("Error while handling calendar object moved event: " . $e->getMessage());
|
||||||
catch(Exception $e){
|
|
||||||
$this->logger->debug("Error while handling calendar object moved event: ".$e->getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,8 @@ use OCP\EventDispatcher\Event;
|
|||||||
use OCP\EventDispatcher\IEventListener;
|
use OCP\EventDispatcher\IEventListener;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class CalendarObjectUpdatedListener implements IEventListener {
|
class CalendarObjectUpdatedListener implements IEventListener
|
||||||
|
{
|
||||||
|
|
||||||
/** @var LoggerInterface */
|
/** @var LoggerInterface */
|
||||||
private $logger;
|
private $logger;
|
||||||
@ -42,25 +43,26 @@ class CalendarObjectUpdatedListener implements IEventListener {
|
|||||||
private $gestionService;
|
private $gestionService;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
LoggerInterface $logger,GestionService $gestionService) {
|
LoggerInterface $logger,
|
||||||
|
GestionService $gestionService
|
||||||
|
) {
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->gestionService = $gestionService;
|
$this->gestionService = $gestionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(Event $event): void {
|
public function handle(Event $event): void
|
||||||
|
{
|
||||||
if (!($event instanceof CalendarObjectUpdatedEvent)) {
|
if (!($event instanceof CalendarObjectUpdatedEvent)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$calendarData = $event->getObjectData();
|
$calendarData = $event->getObjectData();
|
||||||
try{
|
try {
|
||||||
$vCalendarString = $calendarData["calendardata"];
|
$vCalendarString = $calendarData["calendardata"];
|
||||||
$this->gestionService->HandleUpdatedCalendarObject($vCalendarString);
|
$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());
|
||||||
$this->logger->debug("Error while handling updated calendar object: ".$e->getMessage());
|
} catch (\Throwable $e) {
|
||||||
}
|
$this->logger->debug("Error while handling updated calendar object: " . $e->getMessage());
|
||||||
catch(Exception $e){
|
|
||||||
$this->logger->debug("Error while handling updated calendar object: ".$e->getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -35,7 +35,8 @@ use OCP\IUserSession;
|
|||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use OCA\Gestion\Helpers\VCalendarHelpers;
|
use OCA\Gestion\Helpers\VCalendarHelpers;
|
||||||
|
|
||||||
class GestionService {
|
class GestionService
|
||||||
|
{
|
||||||
/** @var Bdd */
|
/** @var Bdd */
|
||||||
private $gestionBdd;
|
private $gestionBdd;
|
||||||
|
|
||||||
@ -51,31 +52,33 @@ class GestionService {
|
|||||||
Bdd $gestionBdd,
|
Bdd $gestionBdd,
|
||||||
LoggerInterface $logger,
|
LoggerInterface $logger,
|
||||||
TalkService $talkService,
|
TalkService $talkService,
|
||||||
IUserSession $userSession) {
|
IUserSession $userSession
|
||||||
|
) {
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->gestionBdd = $gestionBdd;
|
$this->gestionBdd = $gestionBdd;
|
||||||
$this->talkService = $talkService;
|
$this->talkService = $talkService;
|
||||||
try{
|
try {
|
||||||
$this->userConnectedUuid = $userSession->getUser()->getUID();
|
$this->userConnectedUuid = $userSession->getUser()->getUID();
|
||||||
}
|
} catch (Exception) {
|
||||||
catch(Exception){
|
|
||||||
$this->userConnectedUuid = BddConstant::DEFAULT_ADMIN_APP_ID_NEXTCLOUD;
|
$this->userConnectedUuid = BddConstant::DEFAULT_ADMIN_APP_ID_NEXTCLOUD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetIsCalendarPendingFromVCalendarString(string $vCalendarString): bool{
|
private function GetIsCalendarPendingFromVCalendarString(string $vCalendarString): bool
|
||||||
|
{
|
||||||
$isCalendarPending = false;
|
$isCalendarPending = false;
|
||||||
$isCalendarPendingValue = VCalendarHelpers::GetValueFromKeyInVCalendarString(VCalendarPropertyConstant::PROPERTY_IS_CALENDAR_PENDING, $vCalendarString);
|
$isCalendarPendingValue = VCalendarHelpers::GetValueFromKeyInVCalendarString(VCalendarPropertyConstant::PROPERTY_IS_CALENDAR_PENDING, $vCalendarString);
|
||||||
if($isCalendarPendingValue == "1"){
|
if ($isCalendarPendingValue == "1") {
|
||||||
$isCalendarPending = true;
|
$isCalendarPending = true;
|
||||||
}
|
}
|
||||||
return $isCalendarPending;
|
return $isCalendarPending;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetIsLeaveFromVCalendarString(string $vCalendarString): bool{
|
private function GetIsLeaveFromVCalendarString(string $vCalendarString): bool
|
||||||
|
{
|
||||||
$isLeave = false;
|
$isLeave = false;
|
||||||
$isLeaveValue = VCalendarHelpers::GetValueFromKeyInVCalendarString(VCalendarPropertyConstant::PROPERTY_IS_LEAVE, $vCalendarString);
|
$isLeaveValue = VCalendarHelpers::GetValueFromKeyInVCalendarString(VCalendarPropertyConstant::PROPERTY_IS_LEAVE, $vCalendarString);
|
||||||
if($isLeaveValue == "1"){
|
if ($isLeaveValue == "1") {
|
||||||
$isLeave = true;
|
$isLeave = true;
|
||||||
}
|
}
|
||||||
return $isLeave;
|
return $isLeave;
|
||||||
@ -85,7 +88,7 @@ class GestionService {
|
|||||||
{
|
{
|
||||||
$summaryValue = "Nom du défunt";
|
$summaryValue = "Nom du défunt";
|
||||||
$value = VCalendarHelpers::GetValueFromKeyInVCalendarString("SUMMARY", $vCalendarString);
|
$value = VCalendarHelpers::GetValueFromKeyInVCalendarString("SUMMARY", $vCalendarString);
|
||||||
if($value !== ""){
|
if ($value !== "") {
|
||||||
$summaryValue = trim($value);
|
$summaryValue = trim($value);
|
||||||
}
|
}
|
||||||
return $summaryValue;
|
return $summaryValue;
|
||||||
@ -95,16 +98,17 @@ class GestionService {
|
|||||||
{
|
{
|
||||||
$thanatoId = 0;
|
$thanatoId = 0;
|
||||||
$organizerName = $this->getPrincipalUsernameFromVCalendarString($vCalendarString);
|
$organizerName = $this->getPrincipalUsernameFromVCalendarString($vCalendarString);
|
||||||
if($organizerName != null){
|
if ($organizerName != null) {
|
||||||
$thanatoIdFromDb = $this->gestionBdd->getThanatoIdByUserUuid($organizerName);
|
$thanatoIdFromDb = $this->gestionBdd->getThanatoIdByUserUuid($organizerName);
|
||||||
if($thanatoIdFromDb != null){
|
if ($thanatoIdFromDb != null) {
|
||||||
$thanatoId = $thanatoIdFromDb;
|
$thanatoId = $thanatoIdFromDb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $thanatoId;
|
return $thanatoId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPrincipalUsernameFromVCalendarString(string $vCalendarString){
|
private function getPrincipalUsernameFromVCalendarString(string $vCalendarString)
|
||||||
|
{
|
||||||
$calendarUuid = VCalendarHelpers::GetValueFromKeyInVCalendarString("UID", $vCalendarString);
|
$calendarUuid = VCalendarHelpers::GetValueFromKeyInVCalendarString("UID", $vCalendarString);
|
||||||
$principalUsername = $this->gestionBdd->getCalendarOrganizerNameByCalendarObjectUuid($calendarUuid);
|
$principalUsername = $this->gestionBdd->getCalendarOrganizerNameByCalendarObjectUuid($calendarUuid);
|
||||||
return $principalUsername;
|
return $principalUsername;
|
||||||
@ -119,15 +123,17 @@ class GestionService {
|
|||||||
return $names;
|
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);
|
$defuntId = $this->gestionBdd->getLastDefuntIdByName($defuntName);
|
||||||
$devisId = $this->gestionBdd->getLastDevisIdFromVCalendarProperty($thanatoId,$clientId,$locationId,$defuntId,$calendarUuid);
|
$devisId = $this->gestionBdd->getLastDevisIdFromVCalendarProperty($thanatoId, $clientId, $locationId, $defuntId, $calendarUuid);
|
||||||
return $devisId != null;
|
return $devisId != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetDevisCommentFromVCalendarString(string $vCalendarString){
|
private function GetDevisCommentFromVCalendarString(string $vCalendarString)
|
||||||
|
{
|
||||||
$commentValue = VCalendarHelpers::GetValueFromKeyInVCalendarString("COMMENT", $vCalendarString);
|
$commentValue = VCalendarHelpers::GetValueFromKeyInVCalendarString("COMMENT", $vCalendarString);
|
||||||
if($commentValue == ""){
|
if ($commentValue == "") {
|
||||||
$commentValue = "Commentaire";
|
$commentValue = "Commentaire";
|
||||||
}
|
}
|
||||||
return $commentValue;
|
return $commentValue;
|
||||||
@ -136,51 +142,55 @@ class GestionService {
|
|||||||
private function GetCalendarUuidFromVCalendarString(string $vCalendarString): string
|
private function GetCalendarUuidFromVCalendarString(string $vCalendarString): string
|
||||||
{
|
{
|
||||||
$calendarUuid = VCalendarHelpers::GetValueFromKeyInVCalendarString("UID", $vCalendarString);
|
$calendarUuid = VCalendarHelpers::GetValueFromKeyInVCalendarString("UID", $vCalendarString);
|
||||||
if($calendarUuid == ""){
|
if ($calendarUuid == "") {
|
||||||
$calendarUuid = $this->gestionBdd::DEFAULT_CALENDAR_UUID_FOR_DEVIS;
|
$calendarUuid = $this->gestionBdd::DEFAULT_CALENDAR_UUID_FOR_DEVIS;
|
||||||
}
|
}
|
||||||
return $calendarUuid;
|
return $calendarUuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetCalendarDateFromVCalendarString(string $vCalendarString){
|
private function GetCalendarDateFromVCalendarString(string $vCalendarString)
|
||||||
$calendarStartDate = VCalendarHelpers::GetDateStartOrDateEndFromVCalendarString('DTSTART',$vCalendarString);
|
{
|
||||||
|
$calendarStartDate = VCalendarHelpers::GetDateStartOrDateEndFromVCalendarString('DTSTART', $vCalendarString);
|
||||||
$calendarStartDate = $calendarStartDate->format('Y-m-d');
|
$calendarStartDate = $calendarStartDate->format('Y-m-d');
|
||||||
return $calendarStartDate;
|
return $calendarStartDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function HandleCalendarObjectMovedToTrash(string $vCalendarString){
|
public function HandleCalendarObjectMovedToTrash(string $vCalendarString)
|
||||||
|
{
|
||||||
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
|
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
|
||||||
$devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid);
|
$devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid);
|
||||||
if($devis != null){
|
if ($devis != null) {
|
||||||
$this->gestionBdd->updateDevisMentionToCanceled($devis['id']);
|
$this->gestionBdd->updateDevisMentionToCanceled($devis['id']);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function UpdateDevisDataByVCalendarString($devis,$vCalendarString){
|
private function UpdateDevisDataByVCalendarString($devis, $vCalendarString)
|
||||||
|
{
|
||||||
$requestedDefuntName = $this->GetCalendarSummaryFromVCalendarString($vCalendarString);
|
$requestedDefuntName = $this->GetCalendarSummaryFromVCalendarString($vCalendarString);
|
||||||
$defuntId = $this->gestionBdd->createOrUpdateDefuntByNameAndReturnDefuntId($devis['defunt_id'],$devis['defunt_nom'],$requestedDefuntName);
|
$defuntId = $this->gestionBdd->createOrUpdateDefuntByNameAndReturnDefuntId($devis['defunt_id'], $devis['defunt_nom'], $requestedDefuntName);
|
||||||
$this->gestionBdd->updateDevisDefunt($devis['id'],$defuntId,$devis['defunt_id']);
|
$this->gestionBdd->updateDevisDefunt($devis['id'], $defuntId, $devis['defunt_id']);
|
||||||
|
|
||||||
$requestedClientId = $this->GetClientIdFromVCalendarString($vCalendarString);
|
$requestedClientId = $this->GetClientIdFromVCalendarString($vCalendarString);
|
||||||
$this->gestionBdd->updateDevisClient($devis['id'],$requestedClientId,$devis['client_id']);
|
$this->gestionBdd->updateDevisClient($devis['id'], $requestedClientId, $devis['client_id']);
|
||||||
|
|
||||||
$requestLocationId = $this->GetLocationIdFromVCalendarString($vCalendarString);
|
$requestLocationId = $this->GetLocationIdFromVCalendarString($vCalendarString);
|
||||||
$this->gestionBdd->updateDevisLieu($devis['id'],$requestLocationId,$devis['lieu_id']);
|
$this->gestionBdd->updateDevisLieu($devis['id'], $requestLocationId, $devis['lieu_id']);
|
||||||
|
|
||||||
$requestedDevisComment = $this->GetDevisCommentFromVCalendarString($vCalendarString);
|
$requestedDevisComment = $this->GetDevisCommentFromVCalendarString($vCalendarString);
|
||||||
$this->gestionBdd->updateDevisComment($devis['id'],$requestedDevisComment,$devis['comment']);
|
$this->gestionBdd->updateDevisComment($devis['id'], $requestedDevisComment, $devis['comment']);
|
||||||
|
|
||||||
$requestedDevisDate = $this->GetCalendarDateFromVCalendarString($vCalendarString);
|
$requestedDevisDate = $this->GetCalendarDateFromVCalendarString($vCalendarString);
|
||||||
$this->gestionBdd->updateDevisDate($devis['id'],$requestedDevisDate);
|
$this->gestionBdd->updateDevisDate($devis['id'], $requestedDevisDate);
|
||||||
$articlesValue = $this->GetArticlesNameFromVCalendarString($vCalendarString);
|
$articlesValue = $this->GetArticlesNameFromVCalendarString($vCalendarString);
|
||||||
if(!empty($articlesValue)){
|
if (!empty($articlesValue)) {
|
||||||
$articleIds = $this->gestionBdd->getArticleIdsByArticleReferences($articlesValue);
|
$articleIds = $this->gestionBdd->getArticleIdsByArticleReferences($articlesValue);
|
||||||
$this->gestionBdd->updateDevisArticles($devis['id'],$articleIds);
|
$this->gestionBdd->updateDevisArticles($devis['id'], $articleIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function CheckIfDevisIsAlreadyUpdated($devis,$vCalendarString){
|
private function CheckIfDevisIsAlreadyUpdated($devis, $vCalendarString)
|
||||||
|
{
|
||||||
$requestedDefuntName = $this->GetCalendarSummaryFromVCalendarString($vCalendarString);
|
$requestedDefuntName = $this->GetCalendarSummaryFromVCalendarString($vCalendarString);
|
||||||
$requestedClientId = $this->GetClientIdFromVCalendarString($vCalendarString);
|
$requestedClientId = $this->GetClientIdFromVCalendarString($vCalendarString);
|
||||||
$requestLocationId = $this->GetLocationIdFromVCalendarString($vCalendarString);
|
$requestLocationId = $this->GetLocationIdFromVCalendarString($vCalendarString);
|
||||||
@ -190,7 +200,7 @@ class GestionService {
|
|||||||
$requestedDevisDate = $this->GetCalendarDateFromVCalendarString($vCalendarString);
|
$requestedDevisDate = $this->GetCalendarDateFromVCalendarString($vCalendarString);
|
||||||
$articleDevis = $this->gestionBdd->getProduitDevisByDevisId($devis['id']);
|
$articleDevis = $this->gestionBdd->getProduitDevisByDevisId($devis['id']);
|
||||||
$articleDevisIds = [];
|
$articleDevisIds = [];
|
||||||
foreach($articleDevis as $currentArticleDevis){
|
foreach ($articleDevis as $currentArticleDevis) {
|
||||||
$articleDevisIds[] = $currentArticleDevis['produit_id'];
|
$articleDevisIds[] = $currentArticleDevis['produit_id'];
|
||||||
}
|
}
|
||||||
sort($requestedArticleIds);
|
sort($requestedArticleIds);
|
||||||
@ -205,84 +215,82 @@ class GestionService {
|
|||||||
$devis['date'] == $requestedDevisDate;
|
$devis['date'] == $requestedDevisDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function HandleUpdatedCalendarObject(string $vCalendarString){
|
public function HandleUpdatedCalendarObject(string $vCalendarString)
|
||||||
try{
|
{
|
||||||
|
try {
|
||||||
$isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString);
|
$isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString);
|
||||||
if($isCalendarForLeave){
|
if ($isCalendarForLeave) {
|
||||||
//from devis calendar to leave calendar
|
//from devis calendar to leave calendar
|
||||||
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
|
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
|
||||||
$devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid);
|
$devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid);
|
||||||
if($devis != null){
|
if ($devis != null) {
|
||||||
$this->gestionBdd->updateDevisMentionToCanceled($devis['id']);
|
$this->gestionBdd->updateDevisMentionToCanceled($devis['id']);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
|
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
|
||||||
$devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid);
|
$devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid);
|
||||||
if($devis != null){
|
if ($devis != null) {
|
||||||
$isDevisAlreadyUpdated = $this->CheckIfDevisIsAlreadyUpdated($devis,$vCalendarString);
|
$isDevisAlreadyUpdated = $this->CheckIfDevisIsAlreadyUpdated($devis, $vCalendarString);
|
||||||
if($isDevisAlreadyUpdated){
|
if ($isDevisAlreadyUpdated) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$devisIsAlreadyFactured = $devis['mentions'] == DevisMentionConstant::FACTURED || $devis['mentions'] == DevisMentionConstant::FACTURED_FORMATTED;
|
$devisIsAlreadyFactured = $devis['mentions'] == DevisMentionConstant::FACTURED || $devis['mentions'] == DevisMentionConstant::FACTURED_FORMATTED;
|
||||||
$this->UpdateDevisDataByVCalendarString($devis,$vCalendarString);
|
$this->UpdateDevisDataByVCalendarString($devis, $vCalendarString);
|
||||||
if($devisIsAlreadyFactured == false){
|
if ($devisIsAlreadyFactured == false) {
|
||||||
$userName = $this->GetThanatoNameFromVCalendarString($vCalendarString);
|
$userName = $this->GetThanatoNameFromVCalendarString($vCalendarString);
|
||||||
$devisTalkMessage = $this->gestionBdd->getDevisTalkRoomMessage($devis['id'],$userName);
|
$devisTalkMessage = $this->gestionBdd->getDevisTalkRoomMessage($devis['id'], $userName);
|
||||||
$this->talkService->sendDevisTalkNotifications($devisTalkMessage,$userName,$this->userConnectedUuid);
|
$this->talkService->sendDevisTalkNotifications($devisTalkMessage, $userName, $this->userConnectedUuid);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
//update from calendar leave or calendar pending to calendar devis
|
//update from calendar leave or calendar pending to calendar devis
|
||||||
$this->HandleCreatedCalendarObject($vCalendarString);
|
$this->HandleCreatedCalendarObject($vCalendarString);
|
||||||
}
|
}
|
||||||
}
|
} catch (\OC\OCS\Exception $e) {
|
||||||
catch(\OC\OCS\Exception $e){
|
$this->logger->debug("Error while handling created calendar object: " . $e->getMessage());
|
||||||
$this->logger->debug("Error while handling created calendar object: ".$e->getMessage());
|
} catch (\Throwable $e) {
|
||||||
}
|
$this->logger->debug("Error while handling created calendar object: " . $e->getMessage());
|
||||||
catch(Exception $e){
|
|
||||||
$this->logger->debug("Error while handling created calendar object: ".$e->getMessage());
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function HandleCalendarObjectMoved(string $vCalendarString,$targetCalendarId){
|
public function HandleCalendarObjectMoved(string $vCalendarString, $targetCalendarId)
|
||||||
try{
|
{
|
||||||
|
try {
|
||||||
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
|
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
|
||||||
$isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString);
|
$isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString);
|
||||||
$isCalendarDevis = $isCalendarForLeave == false;
|
$isCalendarDevis = $isCalendarForLeave == false;
|
||||||
if($isCalendarDevis){
|
if ($isCalendarDevis) {
|
||||||
$devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid);
|
$devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid);
|
||||||
if($devis != null){
|
if ($devis != null) {
|
||||||
$userPrincipalName = $this->gestionBdd->getCalendarPrincipalNameByCalendarId($targetCalendarId);
|
$userPrincipalName = $this->gestionBdd->getCalendarPrincipalNameByCalendarId($targetCalendarId);
|
||||||
if($userPrincipalName != null){
|
if ($userPrincipalName != null) {
|
||||||
$thanatoId = $this->gestionBdd->getThanatoIdByUserUuid($userPrincipalName);
|
$thanatoId = $this->gestionBdd->getThanatoIdByUserUuid($userPrincipalName);
|
||||||
if($thanatoId != null){
|
if ($thanatoId != null) {
|
||||||
$thanatoHasBeenChanged = $thanatoId != $devis["id_thanato"];
|
$thanatoHasBeenChanged = $thanatoId != $devis["id_thanato"];
|
||||||
if($thanatoHasBeenChanged){
|
if ($thanatoHasBeenChanged) {
|
||||||
$this->gestionBdd->updateDevisThanato($devis['id'],$thanatoId);
|
$this->gestionBdd->updateDevisThanato($devis['id'], $thanatoId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (\OC\OCS\Exception $e) {
|
||||||
catch(\OC\OCS\Exception $e){
|
$this->logger->debug("Error while handling calendar object moved event: " . $e->getMessage());
|
||||||
$this->logger->debug("Error while handling calendar object moved event: ".$e->getMessage());
|
} catch (\Throwable $e) {
|
||||||
}
|
$this->logger->debug("Error while handling calendar object moved event: " . $e->getMessage());
|
||||||
catch(Exception $e){
|
|
||||||
$this->logger->debug("Error while handling calendar object moved event: ".$e->getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function HandleCreatedCalendarObject(string $vCalendarString){
|
public function HandleCreatedCalendarObject(string $vCalendarString)
|
||||||
try{
|
{
|
||||||
|
try {
|
||||||
$isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString);
|
$isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString);
|
||||||
if($isCalendarForLeave){
|
if ($isCalendarForLeave) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$isCalendarPending = $this->GetIsCalendarPendingFromVCalendarString($vCalendarString);
|
$isCalendarPending = $this->GetIsCalendarPendingFromVCalendarString($vCalendarString);
|
||||||
if($isCalendarPending){
|
if ($isCalendarPending) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$calendarSummary = $this->GetCalendarSummaryFromVCalendarString($vCalendarString);
|
$calendarSummary = $this->GetCalendarSummaryFromVCalendarString($vCalendarString);
|
||||||
@ -291,54 +299,56 @@ class GestionService {
|
|||||||
$thanatoId = $this->GetThanatoIdFromVCalendarString($vCalendarString);
|
$thanatoId = $this->GetThanatoIdFromVCalendarString($vCalendarString);
|
||||||
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
|
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
|
||||||
$userName = $this->GetThanatoNameFromVCalendarString($vCalendarString);
|
$userName = $this->GetThanatoNameFromVCalendarString($vCalendarString);
|
||||||
$devisAlreadyCreated = $this->IsDevisAlreadyCreated($clientId,$locationId,$thanatoId,$calendarSummary,$calendarUuid);
|
$devisAlreadyCreated = $this->IsDevisAlreadyCreated($clientId, $locationId, $thanatoId, $calendarSummary, $calendarUuid);
|
||||||
if($devisAlreadyCreated){
|
if ($devisAlreadyCreated) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$defuntId = $this->gestionBdd->insertDefuntByNameAndReturnId($calendarSummary);
|
$defuntId = $this->gestionBdd->insertDefuntByNameAndReturnId($calendarSummary);
|
||||||
$calendarStartDate = $this->GetCalendarDateFromVCalendarString($vCalendarString);
|
$calendarStartDate = $this->GetCalendarDateFromVCalendarString($vCalendarString);
|
||||||
$devisComment = $this->GetDevisCommentFromVCalendarString($vCalendarString);
|
$devisComment = $this->GetDevisCommentFromVCalendarString($vCalendarString);
|
||||||
$devisId = $this->gestionBdd->insertDevisFromVCalendarAndReturnId($thanatoId,$clientId,$locationId,$defuntId,$calendarUuid,$calendarStartDate,$devisComment);
|
$devisId = $this->gestionBdd->insertDevisFromVCalendarAndReturnId($thanatoId, $clientId, $locationId, $defuntId, $calendarUuid, $calendarStartDate, $devisComment);
|
||||||
$articlesValue = $this->GetArticlesNameFromVCalendarString($vCalendarString);
|
$articlesValue = $this->GetArticlesNameFromVCalendarString($vCalendarString);
|
||||||
if(!empty($articlesValue)){
|
if (!empty($articlesValue)) {
|
||||||
$articleIds = $this->gestionBdd->getArticleIdsByArticleReferences($articlesValue);
|
$articleIds = $this->gestionBdd->getArticleIdsByArticleReferences($articlesValue);
|
||||||
$this->gestionBdd->insertDevisArticleFromDevisIdAndArticlesIdArray($devisId, $articleIds);
|
$this->gestionBdd->insertDevisArticleFromDevisIdAndArticlesIdArray($devisId, $articleIds);
|
||||||
}
|
}
|
||||||
$devisTalkMessage = $this->gestionBdd->getDevisTalkRoomMessage($devisId,$userName);
|
$devisTalkMessage = $this->gestionBdd->getDevisTalkRoomMessage($devisId, $userName);
|
||||||
$this->talkService->sendDevisTalkNotifications($devisTalkMessage,$userName,$this->userConnectedUuid);
|
$this->talkService->sendDevisTalkNotifications($devisTalkMessage, $userName, $this->userConnectedUuid);
|
||||||
$this->gestionBdd->createDevisTrajetFromVCalendar($devisId,$userName);
|
$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());
|
||||||
$this->logger->debug("Error while handling created calendar object: ".$e->getMessage());
|
} catch (\Throwable $e) {
|
||||||
}
|
$this->logger->debug("Error while handling created calendar object: " . $e->getMessage());
|
||||||
catch(Exception $e){
|
|
||||||
$this->logger->debug("Error while handling created calendar object: ".$e->getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetThanatoNameFromVCalendarString($vCalendarString){
|
private function GetThanatoNameFromVCalendarString($vCalendarString)
|
||||||
|
{
|
||||||
$thanatoName = $this->getPrincipalUsernameFromVCalendarString($vCalendarString);
|
$thanatoName = $this->getPrincipalUsernameFromVCalendarString($vCalendarString);
|
||||||
return $thanatoName ?? BddConstant::DEFAULT_ADMIN_APP_ID_NEXTCLOUD;
|
return $thanatoName ?? BddConstant::DEFAULT_ADMIN_APP_ID_NEXTCLOUD;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetClientIdFromVCalendarString(string $vCalendarString){
|
private function GetClientIdFromVCalendarString(string $vCalendarString)
|
||||||
|
{
|
||||||
$this->logger->debug($vCalendarString);
|
$this->logger->debug($vCalendarString);
|
||||||
$clientValue = VCalendarHelpers::GetValueFromKeyInVCalendarString("CLIENT", $vCalendarString);
|
$clientValue = VCalendarHelpers::GetValueFromKeyInVCalendarString("CLIENT", $vCalendarString);
|
||||||
if($clientValue == null || $clientValue == ""){
|
if ($clientValue == null || $clientValue == "") {
|
||||||
$clientValue = 0;
|
$clientValue = 0;
|
||||||
}
|
}
|
||||||
return (int)$clientValue;
|
return (int) $clientValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetLocationIdFromVCalendarString(string $vCalendarString){
|
private function GetLocationIdFromVCalendarString(string $vCalendarString)
|
||||||
|
{
|
||||||
$locationValue = VCalendarHelpers::GetValueFromKeyInVCalendarString("LOCATION", $vCalendarString);
|
$locationValue = VCalendarHelpers::GetValueFromKeyInVCalendarString("LOCATION", $vCalendarString);
|
||||||
if($locationValue == null || $locationValue == ""){
|
if ($locationValue == null || $locationValue == "") {
|
||||||
$locationValue = 0;
|
$locationValue = 0;
|
||||||
}
|
}
|
||||||
return (int)$locationValue;
|
return (int) $locationValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetArticlesNameFromVCalendarString(string $vCalendarString): array {
|
private function GetArticlesNameFromVCalendarString(string $vCalendarString): array
|
||||||
|
{
|
||||||
$devisArticleValue = VCalendarHelpers::GetValueFromKeyInVCalendarString("DESCRIPTION", $vCalendarString);
|
$devisArticleValue = VCalendarHelpers::GetValueFromKeyInVCalendarString("DESCRIPTION", $vCalendarString);
|
||||||
$articles = explode('\;', $devisArticleValue);
|
$articles = explode('\;', $devisArticleValue);
|
||||||
$mapped = array_map('trim', $articles);
|
$mapped = array_map('trim', $articles);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user