mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Fix: Workflow: the notification is send when the user is added on first
step. See https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/813
This commit is contained in:
@@ -52,10 +52,20 @@ class NotificationOnTransition implements EventSubscriberInterface
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
'workflow.completed' => 'onCompletedSendNotification',
|
||||
'workflow.completed' => ['onCompletedSendNotification', 2048],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a notification to:
|
||||
*
|
||||
* * the dests of the new step;
|
||||
* * the users which subscribed to workflow, on each step, or on final
|
||||
*
|
||||
* **Warning** take care that this method must be executed **after** the dest users are added to
|
||||
* the step (@link{EntityWorkflowStep::addDestUser}). Currently, this is done during
|
||||
* @link{EntityWorkflowTransitionEventSubscriber::addDests}.
|
||||
*/
|
||||
public function onCompletedSendNotification(Event $event): void
|
||||
{
|
||||
if (!$event->getSubject() instanceof EntityWorkflow) {
|
||||
@@ -65,23 +75,27 @@ class NotificationOnTransition implements EventSubscriberInterface
|
||||
/** @var EntityWorkflow $entityWorkflow */
|
||||
$entityWorkflow = $event->getSubject();
|
||||
|
||||
$dests = array_merge(
|
||||
/** @var array<string, User> $dests array of unique values, where keys is the object's hash */
|
||||
$dests = [];
|
||||
foreach (array_merge(
|
||||
// the subscriber to each step
|
||||
$entityWorkflow->getSubscriberToStep()->toArray(),
|
||||
// the subscriber to final, only if final
|
||||
$entityWorkflow->isFinal() ? $entityWorkflow->getSubscriberToFinal()->toArray() : [],
|
||||
$entityWorkflow->getCurrentStepChained()->getPrevious()->getDestUser()->toArray()
|
||||
);
|
||||
// the dests for the current step
|
||||
$entityWorkflow->getCurrentStep()->getDestUser()->toArray()
|
||||
) as $dest) {
|
||||
$dests[spl_object_hash($dest)] = $dest;
|
||||
}
|
||||
|
||||
$place = $this->metadataExtractor->buildArrayPresentationForPlace($entityWorkflow);
|
||||
$workflow = $this->metadataExtractor->buildArrayPresentationForWorkflow(
|
||||
$this->registry->get($entityWorkflow, $entityWorkflow->getWorkflowName())
|
||||
);
|
||||
|
||||
$visited = [];
|
||||
|
||||
foreach ($dests as $subscriber) {
|
||||
if (
|
||||
$this->security->getUser() === $subscriber
|
||||
|| in_array($subscriber->getId(), $visited, true)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
@@ -102,8 +116,6 @@ class NotificationOnTransition implements EventSubscriberInterface
|
||||
->setMessage($this->engine->render('@ChillMain/Workflow/workflow_notification_on_transition_completed_content.fr.txt.twig', $context))
|
||||
->addAddressee($subscriber);
|
||||
$this->entityManager->persist($notification);
|
||||
|
||||
$visited[] = $subscriber->getId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user