Merge branch 'fixes/fix-move-calendar' into staging
This commit is contained in:
commit
9b7422c328
@ -5,9 +5,11 @@
|
||||
namespace OCA\Gestion\AppInfo;
|
||||
|
||||
use OCA\DAV\Events\CalendarObjectCreatedEvent;
|
||||
use OCA\DAV\Events\CalendarObjectMovedEvent;
|
||||
use OCA\DAV\Events\CalendarObjectMovedToTrashEvent;
|
||||
use OCA\DAV\Events\CalendarObjectUpdatedEvent;
|
||||
use OCA\Gestion\Listener\CalendarObjectCreatedListener;
|
||||
use OCA\Gestion\Listener\CalendarObjectMovedListener;
|
||||
use OCA\Gestion\Listener\CalendarObjectMovedToTrashListener;
|
||||
use OCA\Gestion\Listener\CalendarObjectUpdatedListener;
|
||||
use OCP\AppFramework\App;
|
||||
@ -27,6 +29,7 @@ class Application extends App implements IBootstrap {
|
||||
$context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarObjectCreatedListener::class);
|
||||
$context->registerEventListener(CalendarObjectMovedToTrashEvent::class, CalendarObjectMovedToTrashListener::class);
|
||||
$context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarObjectUpdatedListener::class);
|
||||
$context->registerEventListener(CalendarObjectMovedEvent::class,CalendarObjectMovedListener::class);
|
||||
}
|
||||
|
||||
public function boot(IBootContext $context): void {
|
||||
|
||||
@ -3694,6 +3694,57 @@ class Bdd {
|
||||
$sql = "SELECT * FROM {$this->tableprefix}devis WHERE MONTH(date) = ? AND YEAR(date) = ? AND id_thanato = ?;";
|
||||
return $this->execSQLNoJsonReturn($sql,array( $mois , $annee, $thanato['id'] ));
|
||||
}
|
||||
|
||||
public function reArrangeLigneTrajetyByDevisId($devisId,$idNextcloud){
|
||||
$ligne_trajet = json_decode($this->getOneTrajetdetails_byIdDevis($devisId, $idNextcloud))[0];
|
||||
if($ligne_trajet != NULL) {
|
||||
$this->gestion_delete('ligne_trajet', $ligne_trajet->id, $idNextcloud);
|
||||
$ligne_trajet = NULL;
|
||||
}
|
||||
$devisObject = json_decode($this->getOneDevis($devisId, $idNextcloud))[0];
|
||||
|
||||
$this->generate_ligneTrajet($devisObject, $idNextcloud);
|
||||
$ligne_trajet = json_decode( json: $this->getOneTrajetdetails_byIdDevis($devisObject->devisid, $idNextcloud))[0];
|
||||
$this->range_ligneTrajet($ligne_trajet->id_trajet, $idNextcloud);
|
||||
$this->calculer_distance_trajet(numtrajet: $ligne_trajet->id_trajet, idNextcloud: $idNextcloud);
|
||||
}
|
||||
|
||||
public function getCalendarPrincipalNameByCalendarId($calendarId){
|
||||
$calendar = $this->getCalendarById($calendarId);
|
||||
if($calendar != null){
|
||||
$principalUri = $calendar["principaluri"];
|
||||
$organizerName = str_replace('principals/users/','',$principalUri);
|
||||
$organizerName = trim($organizerName);
|
||||
return $organizerName;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function updateDevisThanato($devisId,$requestedThanatoId){
|
||||
$sql= "UPDATE ".$this->tableprefix."devis as devis
|
||||
SET devis.id_thanato = ?
|
||||
WHERE devis.id = ?";
|
||||
$this->execSQLNoData($sql,[$requestedThanatoId,$devisId]);
|
||||
}
|
||||
|
||||
public function deleteLigneTrajetByDevisId($devisId){
|
||||
$sql = "DELETE FROM ".$this->tableprefix."ligne_trajet WHERE id_devis = ?;";
|
||||
$this->execSQLNoData($sql, array($devisId));
|
||||
}
|
||||
|
||||
public function thereIsThanatoDevisRattachedToLigneTrajetForADate($date,$idNextcloud){
|
||||
$sql = "SELECT * FROM ".$this->tableprefix."ligne_trajet WHERE date = ? AND id_nextcloud = ? AND id_devis != 0 AND id_devis != NULL AND id_devis != ?;";
|
||||
$ligneTrajet = $this->execSQLNoJsonReturn($sql, array($date,$idNextcloud,"-"));
|
||||
if(!empty($ligneTrajet)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function deleteThanatoLigneTrajetForADate($date,$thanatoUserUuid){
|
||||
$sql = "DELETE FROM ".$this->tableprefix."ligne_trajet WHERE date = ? AND id_nextcloud = ?;";
|
||||
$this->execSQLNoData($sql, array($date,$thanatoUserUuid));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
69
gestion/lib/Listener/CalendarObjectMovedListener.php
Normal file
69
gestion/lib/Listener/CalendarObjectMovedListener.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* @copyright 2022 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||
*
|
||||
* @author 2022 Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace OCA\Gestion\Listener;
|
||||
|
||||
use Exception;
|
||||
use OCA\DAV\Events\CalendarObjectMovedEvent;
|
||||
use OCA\Gestion\Service\GestionService;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class CalendarObjectMovedListener implements IEventListener
|
||||
{
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** @var GestionService */
|
||||
private $gestionService;
|
||||
|
||||
public function __construct(
|
||||
LoggerInterface $logger,
|
||||
GestionService $gestionService
|
||||
) {
|
||||
$this->logger = $logger;
|
||||
$this->gestionService = $gestionService;
|
||||
}
|
||||
|
||||
public function handle(Event $event): void
|
||||
{
|
||||
if (!($event instanceof CalendarObjectMovedEvent)) {
|
||||
return;
|
||||
}
|
||||
$calendarData = $event->getObjectData();
|
||||
try {
|
||||
$targetCalendarId = $event->getTargetCalendarId();
|
||||
$vCalendarString = $calendarData["calendardata"];
|
||||
$this->gestionService->HandleCalendarObjectMoved($vCalendarString, $targetCalendarId);
|
||||
} catch (\OC\OCS\Exception $e) {
|
||||
$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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -501,6 +501,7 @@ class GestionService {
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->gestionBdd->reArrangeLigneTrajetyByDevisId($devis['id'],$userName);
|
||||
}
|
||||
else{
|
||||
$this->HandleCreatedCalendarObject($vCalendarString,$cookie);
|
||||
@ -617,4 +618,43 @@ class GestionService {
|
||||
$this->logger->debug("error sending file to talk");
|
||||
}
|
||||
}
|
||||
|
||||
public function HandleCalendarObjectMoved(string $vCalendarString, $targetCalendarId)
|
||||
{
|
||||
try {
|
||||
$calendarUuid = $this->GetCalendarUuidFromVCalendarString($vCalendarString);
|
||||
$absenceType = VCalendarHelpers::GetValueFromKeyInVCalendarString('ABSENCETYPE',$vCalendarString);
|
||||
if($absenceType){
|
||||
return;
|
||||
}
|
||||
$devis = $this->gestionBdd->getDevisByCalendarUuid($calendarUuid);
|
||||
if ($devis != null) {
|
||||
$userPrincipalName = $this->gestionBdd->getCalendarPrincipalNameByCalendarId($targetCalendarId);
|
||||
if ($userPrincipalName != null) {
|
||||
$thanato = $this->gestionBdd->getThanatoByUserUuid($userPrincipalName);
|
||||
if ($thanato != null) {
|
||||
$thanatoHasBeenChanged = $thanato['id'] != $devis["id_thanato"];
|
||||
if ($thanatoHasBeenChanged) {
|
||||
$oldThanato = $this->gestionBdd->getThanatoByThanatoId($devis['id_thanato']);
|
||||
$oldThanatoUserUuid = $oldThanato['fk_user_uuid'];
|
||||
//delete ligne trajet from old devis
|
||||
$this->gestionBdd->deleteLigneTrajetByDevisId($devis['id']);
|
||||
//delete from home and to home trajet if there is no devis at all for this date
|
||||
$thereIsThanatoDevisRattachedToLigneTrajetForADate = $this->gestionBdd->thereIsThanatoDevisRattachedToLigneTrajetForADate($devis['date'], $oldThanatoUserUuid );
|
||||
if(!$thereIsThanatoDevisRattachedToLigneTrajetForADate){
|
||||
//delete all ligne trajet for this date
|
||||
$this->gestionBdd->deleteThanatoLigneTrajetForADate($devis['date'], $oldThanatoUserUuid );
|
||||
}
|
||||
$this->gestionBdd->updateDevisThanato($devis['id'], $thanato['id']);
|
||||
$this->gestionBdd->reArrangeLigneTrajetyByDevisId($devis['id'], $userPrincipalName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\OC\OCS\Exception $e) {
|
||||
$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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user