From 0bbd502f4dc53d6a860b8939e439ddd26840a980 Mon Sep 17 00:00:00 2001 From: theoboldt Date: Sun, 30 Jul 2023 11:05:18 +0200 Subject: [PATCH] If Participant name is updated, and this participant is linked in a related participant field, the name is also updated at link --- ...bstractRelatedParticipantResetListener.php | 21 +++++++++++++------ ...icipantRelatedParticipantResetListener.php | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/src/AppBundle/EventListeners/AbstractRelatedParticipantResetListener.php b/app/src/AppBundle/EventListeners/AbstractRelatedParticipantResetListener.php index 5613705b..8ddcf1bf 100644 --- a/app/src/AppBundle/EventListeners/AbstractRelatedParticipantResetListener.php +++ b/app/src/AppBundle/EventListeners/AbstractRelatedParticipantResetListener.php @@ -15,6 +15,7 @@ use AppBundle\Entity\CustomField\CustomFieldValueContainer; use AppBundle\Entity\CustomField\ParticipantDetectingCustomFieldValue; use AppBundle\Entity\Event; +use AppBundle\Entity\Participant; use AppBundle\Manager\RelatedParticipantsLocker; use Doctrine\ORM\EntityManager; @@ -24,13 +25,15 @@ abstract class AbstractRelatedParticipantResetListener extends RelatedParticipan /** * Reset proposed participants for an complete event * - * @param EntityManager $em Entity manage - * @param Event $event Related event - * @param int $maxWait If defined, specifies maximum time to wait for lock - * @throws \Doctrine\DBAL\ConnectionException - * @throws \Doctrine\DBAL\DBALException + * @param EntityManager $em Entity manage + * @param Event $event Related event + * @param int $maxWait If defined, specifies maximum time to wait for lock + * @param Participant|null $updateParticipant If defined, all participant links relating to this participant are + * updated; Bad interface, should be improved later */ - protected function resetProposedParticipantsForEvent(EntityManager $em, Event $event, int $maxWait = 30) + protected function resetProposedParticipantsForEvent( + EntityManager $em, Event $event, int $maxWait = 30, ?Participant $updateParticipant = null + ): void { $lockHandle = $this->lock($event); if ($lockHandle !== false && flock($lockHandle, LOCK_EX)) { @@ -85,6 +88,12 @@ protected function resetProposedParticipantsForEvent(EntityManager $em, Event $e if ($customFieldValue instanceof ParticipantDetectingCustomFieldValue) { $customFieldValue->setProposedParticipants(null); $collectionModified = true; + + if ($updateParticipant !== null + && $customFieldValue->getParticipantAid() === $updateParticipant->getAid()) { + $customFieldValue->setParticipantFirstName($updateParticipant->getNameFirst()); + $customFieldValue->setParticipantLastName($updateParticipant->getNameLast()); + } } } if ($collectionModified) { diff --git a/app/src/AppBundle/EventListeners/ParticipantRelatedParticipantResetListener.php b/app/src/AppBundle/EventListeners/ParticipantRelatedParticipantResetListener.php index bda259d3..dc73695f 100644 --- a/app/src/AppBundle/EventListeners/ParticipantRelatedParticipantResetListener.php +++ b/app/src/AppBundle/EventListeners/ParticipantRelatedParticipantResetListener.php @@ -28,7 +28,7 @@ public function preUpdate(Participant $participant, PreUpdateEventArgs $event) { if ($event->hasChangedField('nameLast') || $event->hasChangedField('nameFirst')) { $this->resetProposedParticipantsForEvent( - $event->getEntityManager(), $participant->getParticipation()->getEvent() + $event->getEntityManager(), $participant->getParticipation()->getEvent(), 30, $participant ); } }