mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
recreate calendar range when an event is deleted
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Chill\CalendarBundle\Messenger\Doctrine;
|
||||
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\CalendarBundle\Messenger\Message\CalendarMessage;
|
||||
use Chill\CalendarBundle\Messenger\Message\CalendarRemovedMessage;
|
||||
use Doctrine\ORM\Event\LifecycleEventArgs;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
@@ -44,7 +45,14 @@ class CalendarEntityListener
|
||||
|
||||
public function postRemove(Calendar $calendar, LifecycleEventArgs $args): void
|
||||
{
|
||||
// TODO
|
||||
if (!$calendar->preventEnqueueChanges) {
|
||||
$this->messageBus->dispatch(
|
||||
new CalendarRemovedMessage(
|
||||
$calendar,
|
||||
$this->security->getUser()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function postUpdate(Calendar $calendar, LifecycleEventArgs $args): void
|
||||
|
@@ -39,7 +39,7 @@ class CalendarRangeRemoveToRemoteHandler implements MessageHandlerInterface
|
||||
$this->remoteCalendarConnector->removeCalendarRange(
|
||||
$calendarRangeRemovedMessage->getRemoteId(),
|
||||
$calendarRangeRemovedMessage->getRemoteAttributes(),
|
||||
$this->userRepository->find($calendarRangeRemovedMessage->getCalendarRangeUserId())
|
||||
$this->userRepository->find($calendarRangeRemovedMessage->getCalendarUserId())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\CalendarBundle\Messenger\Handler;
|
||||
|
||||
use Chill\CalendarBundle\Messenger\Message\CalendarRemovedMessage;
|
||||
use Chill\CalendarBundle\RemoteCalendar\Connector\RemoteCalendarConnectorInterface;
|
||||
use Chill\CalendarBundle\Repository\CalendarRangeRepository;
|
||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
||||
|
||||
/**
|
||||
* Handle the deletion of calendar
|
||||
*
|
||||
* @AsMessageHandler
|
||||
*/
|
||||
class CalendarRemoveHandler implements MessageHandlerInterface
|
||||
{
|
||||
private RemoteCalendarConnectorInterface $remoteCalendarConnector;
|
||||
private CalendarRangeRepository $calendarRangeRepository;
|
||||
private UserRepositoryInterface $userRepository;
|
||||
|
||||
/**
|
||||
* @param RemoteCalendarConnectorInterface $remoteCalendarConnector
|
||||
* @param CalendarRangeRepository $calendarRangeRepository
|
||||
* @param UserRepositoryInterface $userRepository
|
||||
*/
|
||||
public function __construct(RemoteCalendarConnectorInterface $remoteCalendarConnector, CalendarRangeRepository $calendarRangeRepository, UserRepositoryInterface $userRepository)
|
||||
{
|
||||
$this->remoteCalendarConnector = $remoteCalendarConnector;
|
||||
$this->calendarRangeRepository = $calendarRangeRepository;
|
||||
$this->userRepository = $userRepository;
|
||||
}
|
||||
|
||||
public function __invoke(CalendarRemovedMessage $message)
|
||||
{
|
||||
if (null !== $message->getAssociatedCalendarRangeId()) {
|
||||
$associatedRange = $this->calendarRangeRepository->find($message->getAssociatedCalendarRangeId());
|
||||
} else {
|
||||
$associatedRange = null;
|
||||
}
|
||||
|
||||
$this->remoteCalendarConnector->removeCalendar(
|
||||
$message->getRemoteId(),
|
||||
$message->getRemoteAttributes(),
|
||||
$this->userRepository->find($message->getCalendarUserId()),
|
||||
$associatedRange
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\CalendarBundle\Messenger\Message;
|
||||
|
||||
use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
|
||||
class CalendarRemovedMessage
|
||||
{
|
||||
private ?int $byUserId = null;
|
||||
|
||||
private int $calendarUserId;
|
||||
|
||||
private array $remoteAttributes;
|
||||
|
||||
private string $remoteId;
|
||||
|
||||
private ?int $associatedCalendarRangeId = null;
|
||||
|
||||
public function __construct(Calendar $calendar, ?User $byUser)
|
||||
{
|
||||
$this->remoteId = $calendar->getRemoteId();
|
||||
$this->remoteAttributes = $calendar->getRemoteAttributes();
|
||||
$this->calendarUserId = $calendar->getMainUser()->getId();
|
||||
|
||||
if ($calendar->hasCalendarRange()) {
|
||||
$this->associatedCalendarRangeId = $calendar->getCalendarRange()->getId();
|
||||
}
|
||||
|
||||
if (null !== $byUser) {
|
||||
$this->byUserId = $byUser->getId();
|
||||
}
|
||||
}
|
||||
|
||||
public function getByUserId(): ?int
|
||||
{
|
||||
return $this->byUserId;
|
||||
}
|
||||
|
||||
public function getCalendarUserId(): ?int
|
||||
{
|
||||
return $this->calendarUserId;
|
||||
}
|
||||
|
||||
public function getRemoteAttributes(): array
|
||||
{
|
||||
return $this->remoteAttributes;
|
||||
}
|
||||
|
||||
public function getRemoteId(): string
|
||||
{
|
||||
return $this->remoteId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getAssociatedCalendarRangeId(): ?int
|
||||
{
|
||||
return $this->associatedCalendarRangeId;
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user