Merge branch 'fixes/fix-move-calendar' into staging
This commit is contained in:
commit
0cbedac615
@ -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 {
|
||||
|
||||
@ -2487,16 +2487,21 @@ class Bdd {
|
||||
return "";
|
||||
}
|
||||
|
||||
public function getCalendarOrganizerNameByCalendarObjectUuid(string $calendarObjectUuid){
|
||||
$calendarObject = $this->getCalendarObjectByUuid($calendarObjectUuid);
|
||||
if($calendarObject != null){
|
||||
$calendar = $this->getCalendarById($calendarObject['calendarid']);
|
||||
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 getCalendarOrganizerNameByCalendarObjectUuid(string $calendarObjectUuid){
|
||||
$calendarObject = $this->getCalendarObjectByUuid($calendarObjectUuid);
|
||||
if($calendarObject != null){
|
||||
return $this->getCalendarPrincipalNameByCalendarId($calendarObject['calendarid']);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -3617,6 +3622,13 @@ class Bdd {
|
||||
}
|
||||
}
|
||||
|
||||
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 updateDevisClient($devisId,$requestedClientId,$currentClientId = null){
|
||||
$clientIsUpdated = $currentClientId != $requestedClientId;
|
||||
if($clientIsUpdated){
|
||||
|
||||
58
gestion/lib/Listener/CalendarObjectMovedListener.php
Normal file
58
gestion/lib/Listener/CalendarObjectMovedListener.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?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 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();
|
||||
$targetCalendarId = $event->getTargetCalendarId();
|
||||
$vCalendarString = $calendarData["calendardata"];
|
||||
$this->gestionService->HandleCalendarObjectMoved($vCalendarString,$targetCalendarId);
|
||||
}
|
||||
|
||||
}
|
||||
@ -221,6 +221,27 @@ class GestionService {
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function HandleCreatedCalendarObject(string $vCalendarString){
|
||||
$isCalendarForLeave = $this->GetIsLeaveFromVCalendarString($vCalendarString);
|
||||
if($isCalendarForLeave){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user