From 45beb27f83bc903253c9922c970b1c8b5ad621d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 16 Feb 2022 21:54:06 +0100 Subject: [PATCH 1/2] fix sending notifications --- .../Controller/WorkflowController.php | 2 ++ .../Entity/Workflow/EntityWorkflow.php | 11 +++++++++++ .../EventSubscriber/NotificationOnTransition.php | 14 ++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php index 876e095a8..ac8a5a7e0 100644 --- a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php +++ b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php @@ -197,6 +197,8 @@ class WorkflowController extends AbstractController ); } + $entityWorkflow->futureDestUsers = $transitionForm['future_dest_users']->getData(); + $workflow->apply($entityWorkflow, $transition); foreach ($transitionForm['future_dest_users']->getData() as $user) { diff --git a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php index b9773040a..84a75fc6d 100644 --- a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php +++ b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php @@ -41,6 +41,17 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface use TrackUpdateTrait; + /** + * a list of future dest users for the next steps. + * + * This is in used in order to let controller inform who will be the future users which will validate + * the next step. This is necessary to perform some computation about the next users, before they are + * associated to the entity EntityWorkflowStep. + * + * @var array|User[] + */ + public array $futureDestUsers = []; + /** * @ORM\OneToMany(targetEntity=EntityWorkflowComment::class, mappedBy="entityWorkflow", orphanRemoval=true) * diff --git a/src/Bundle/ChillMainBundle/Workflow/EventSubscriber/NotificationOnTransition.php b/src/Bundle/ChillMainBundle/Workflow/EventSubscriber/NotificationOnTransition.php index c46899e52..6d5a54d45 100644 --- a/src/Bundle/ChillMainBundle/Workflow/EventSubscriber/NotificationOnTransition.php +++ b/src/Bundle/ChillMainBundle/Workflow/EventSubscriber/NotificationOnTransition.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Workflow\EventSubscriber; use Chill\MainBundle\Entity\Notification; +use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\Workflow\EntityWorkflow; use Chill\MainBundle\Workflow\Helper\MetadataExtractor; use Doctrine\ORM\EntityManagerInterface; @@ -34,8 +35,13 @@ class NotificationOnTransition implements EventSubscriberInterface private Security $security; - public function __construct(EntityManagerInterface $entityManager, EngineInterface $engine, MetadataExtractor $metadataExtractor, Security $security, Registry $registry) - { + public function __construct( + EntityManagerInterface $entityManager, + EngineInterface $engine, + MetadataExtractor $metadataExtractor, + Security $security, + Registry $registry + ) { $this->entityManager = $entityManager; $this->engine = $engine; $this->metadataExtractor = $metadataExtractor; @@ -62,7 +68,7 @@ class NotificationOnTransition implements EventSubscriberInterface $dests = array_merge( $entityWorkflow->getSubscriberToStep()->toArray(), $entityWorkflow->isFinal() ? $entityWorkflow->getSubscriberToFinal()->toArray() : [], - $entityWorkflow->getCurrentStep()->getDestUser()->toArray() + $entityWorkflow->getCurrentStepChained()->getPrevious()->getDestUser()->toArray() ); $place = $this->metadataExtractor->buildArrayPresentationForPlace($entityWorkflow); @@ -85,7 +91,7 @@ class NotificationOnTransition implements EventSubscriberInterface 'dest' => $subscriber, 'place' => $place, 'workflow' => $workflow, - 'is_dest' => $entityWorkflow->getCurrentStep()->getDestUser()->contains($subscriber), + 'is_dest' => in_array($subscriber->getId(), array_map(static function (User $u) { return $u->getId(); }, $entityWorkflow->futureDestUsers), true), ]; $notification = new Notification(); From 95b2fcead7c7f6782717143a8cda20d2b4153008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 16 Feb 2022 21:58:49 +0100 Subject: [PATCH 2/2] update changelog [ci-skip] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c392663a..c9f4d2c9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to ## Unreleased +* workflow: fix sending notifications ## Test releases