From 05a55f24e64345baa3d990ada8e0c970f6ed8896 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 4 Jul 2025 13:04:10 +0200 Subject: [PATCH] Pipeline fixes --- .../ChillMainBundle/Entity/Notification.php | 3 -- .../DataMapper/NotificationFlagDataMapper.php | 16 ++++----- .../ChillMainBundle/Form/NotificationType.php | 1 - .../Form/Type/NotificationFlagsType.php | 7 +--- ...ScheduleDailyNotificationDigestHandler.php | 8 ++--- .../Notification/Email/NotificationMailer.php | 36 ++----------------- .../NotificationByUserFlagProvider.php | 10 +++++- ...flowTransitionNotificationFlagProvider.php | 10 +++++- .../Email/NotificationMailerTest.php | 6 ++-- .../migrations/Version20250610102953.php | 8 +++++ .../migrations/Version20250618115938.php | 7 ++++ .../migrations/Version20250623120824.php | 7 ++++ ...gnatedReferrerNotificationFlagProvider.php | 10 +++++- ...sonAddressMoveNotificationFlagProvider.php | 10 +++++- 14 files changed, 74 insertions(+), 65 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/Notification.php b/src/Bundle/ChillMainBundle/Entity/Notification.php index e64a7434b..a0419729a 100644 --- a/src/Bundle/ChillMainBundle/Entity/Notification.php +++ b/src/Bundle/ChillMainBundle/Entity/Notification.php @@ -181,9 +181,6 @@ class Notification implements TrackUpdateInterface } } - /** - * @return Collection - */ public function getAddresseeUserGroups(): Collection { return $this->addresseeUserGroups; diff --git a/src/Bundle/ChillMainBundle/Form/DataMapper/NotificationFlagDataMapper.php b/src/Bundle/ChillMainBundle/Form/DataMapper/NotificationFlagDataMapper.php index 57aa17d88..7e5a87edb 100644 --- a/src/Bundle/ChillMainBundle/Form/DataMapper/NotificationFlagDataMapper.php +++ b/src/Bundle/ChillMainBundle/Form/DataMapper/NotificationFlagDataMapper.php @@ -15,11 +15,8 @@ use Symfony\Component\Form\DataMapperInterface; final readonly class NotificationFlagDataMapper implements DataMapperInterface { - private array $notificationFlagProviders; - - public function __construct(array $notificationFlagProviders) + public function __construct(private array $notificationFlagProviders) { - $this->notificationFlagProviders = $notificationFlagProviders; } public function mapDataToForms($viewData, $forms): void @@ -36,9 +33,8 @@ final readonly class NotificationFlagDataMapper implements DataMapperInterface if (isset($formsArray[$flag])) { $flagForm = $formsArray[$flag]; - $immediateEmailChecked = in_array('immediate-email', $viewData[$flag] ?? []); - $dailyEmailChecked = in_array('daily-email', $viewData[$flag] ?? []); - $noEmailChecked = in_array('no-email', $viewData[$flag] ?? []); + $immediateEmailChecked = in_array('immediate-email', $viewData[$flag] ?? [], true); + $dailyEmailChecked = in_array('daily-email', $viewData[$flag] ?? [], true); if ($flagForm->has('immediate_email')) { $flagForm->get('immediate_email')->setData($immediateEmailChecked); @@ -62,15 +58,15 @@ final readonly class NotificationFlagDataMapper implements DataMapperInterface $flagForm = $formsArray[$flag]; $viewData[$flag] = []; - if ($flagForm['immediate_email']->getData()) { + if (true === $flagForm['immediate_email']->getData()) { $viewData[$flag][] = 'immediate-email'; } - if ($flagForm['daily_email']->getData()) { + if (true === $flagForm['daily_email']->getData()) { $viewData[$flag][] = 'daily-email'; } - if (empty($viewData[$flag])) { + if ([] === $viewData[$flag]) { $viewData[$flag][] = 'no-email'; } } diff --git a/src/Bundle/ChillMainBundle/Form/NotificationType.php b/src/Bundle/ChillMainBundle/Form/NotificationType.php index ba4ff23eb..58fb1925d 100644 --- a/src/Bundle/ChillMainBundle/Form/NotificationType.php +++ b/src/Bundle/ChillMainBundle/Form/NotificationType.php @@ -13,7 +13,6 @@ namespace Chill\MainBundle\Form; use Chill\MainBundle\Entity\Notification; use Chill\MainBundle\Form\Type\ChillTextareaType; -use Chill\MainBundle\Form\Type\PickUserDynamicType; use Chill\MainBundle\Form\Type\PickUserGroupOrUserDynamicType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\TextType; diff --git a/src/Bundle/ChillMainBundle/Form/Type/NotificationFlagsType.php b/src/Bundle/ChillMainBundle/Form/Type/NotificationFlagsType.php index fb25c9ae0..4535a4815 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/NotificationFlagsType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/NotificationFlagsType.php @@ -21,7 +21,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; class NotificationFlagsType extends AbstractType { - private array $notificationFlagProviders; + private readonly array $notificationFlagProviders; public function __construct(NotificationFlagManager $notificationFlagManager) { @@ -50,11 +50,6 @@ class NotificationFlagsType extends AbstractType 'required' => false, 'mapped' => false, ]) - ->add('no_email', CheckboxType::class, [ - 'label' => false, - 'required' => false, - 'mapped' => false, - ]) ; } } diff --git a/src/Bundle/ChillMainBundle/Notification/Email/NotificationEmailHandlers/ScheduleDailyNotificationDigestHandler.php b/src/Bundle/ChillMainBundle/Notification/Email/NotificationEmailHandlers/ScheduleDailyNotificationDigestHandler.php index 468c5e2b0..e3c310179 100644 --- a/src/Bundle/ChillMainBundle/Notification/Email/NotificationEmailHandlers/ScheduleDailyNotificationDigestHandler.php +++ b/src/Bundle/ChillMainBundle/Notification/Email/NotificationEmailHandlers/ScheduleDailyNotificationDigestHandler.php @@ -43,6 +43,7 @@ readonly class ScheduleDailyNotificationDigestHandler $this->logger->warning('[ScheduleDailyNotificationDigestHandler] User not found', [ 'user_id' => $userId, ]); + return; } @@ -54,14 +55,13 @@ readonly class ScheduleDailyNotificationDigestHandler ); // Filter out notifications that were sent immediately - $dailyNotifications = array_filter($notifications, function ($notification) use ($user) { - return !$notification->isSendImmediately($user); - }); + $dailyNotifications = array_filter($notifications, fn($notification) => !$notification->isSendImmediately($user)); - if (empty($dailyNotifications)) { + if ([] === $dailyNotifications) { $this->logger->info('[ScheduleDailyNotificationDigestHandler] No daily notifications found for user', [ 'user_id' => $userId, ]); + return; } diff --git a/src/Bundle/ChillMainBundle/Notification/Email/NotificationMailer.php b/src/Bundle/ChillMainBundle/Notification/Email/NotificationMailer.php index e15dca129..5db826ec3 100644 --- a/src/Bundle/ChillMainBundle/Notification/Email/NotificationMailer.php +++ b/src/Bundle/ChillMainBundle/Notification/Email/NotificationMailer.php @@ -81,7 +81,7 @@ readonly class NotificationMailer private function sendNotificationEmailsToAddressees(Notification $notification): void { - if (null === $notification->getType()) { + if ('' === $notification->getType()) { $this->logger->warning('[NotificationMailer] Notification has no type, skipping email processing', [ 'notification_id' => $notification->getId(), ]); @@ -183,7 +183,7 @@ readonly class NotificationMailer */ public function sendDailyDigest($user, array $notifications): void { - if (null === $user->getEmail() || empty($notifications)) { + if (null === $user->getEmail() || [] === $notifications) { return; } @@ -211,37 +211,7 @@ readonly class NotificationMailer 'error_message' => $e->getMessage(), 'error_trace' => $e->getTraceAsString(), ]); - throw $e; // Re-throw so the message handler can handle the failure - } - } - - /** - * @deprecated - */ - private function sendNotificationEmailsToAddressesEmails(Notification $notification): void - { - foreach ($notification->getAddressesEmailsAdded() as $emailAddress) { - $email = new TemplatedEmail(); - $email - ->textTemplate('@ChillMain/Notification/email_non_system_notification_content_to_email.fr.md.twig') - ->context([ - 'notification' => $notification, - 'dest' => $emailAddress, - ]); - - $email - ->subject($notification->getTitle()) - ->to($emailAddress); - - try { - $this->mailer->send($email); - } catch (TransportExceptionInterface $e) { - $this->logger->warning('[NotificationMailer] could not send an email notification', [ - 'to' => $emailAddress, - 'error_message' => $e->getMessage(), - 'error_trace' => $e->getTraceAsString(), - ]); - } + throw $e; } } } diff --git a/src/Bundle/ChillMainBundle/Notification/FlagProviders/NotificationByUserFlagProvider.php b/src/Bundle/ChillMainBundle/Notification/FlagProviders/NotificationByUserFlagProvider.php index 9c29c062c..b796919bc 100644 --- a/src/Bundle/ChillMainBundle/Notification/FlagProviders/NotificationByUserFlagProvider.php +++ b/src/Bundle/ChillMainBundle/Notification/FlagProviders/NotificationByUserFlagProvider.php @@ -1,5 +1,14 @@ createMock(MessageBusInterface::class); $messageBus->expects($this->once()) ->method('dispatch') - ->with($this->callback(function (SendImmediateNotificationEmailMessage $message) { - return 123 === $message->getNotificationId() - && 456 === $message->getAddresseeId(); - })) + ->with($this->callback(fn(SendImmediateNotificationEmailMessage $message) => 123 === $message->getNotificationId() + && 456 === $message->getAddresseeId())) ->willReturn(new Envelope(new \stdClass())); $mailer = $this->buildNotificationMailer(null, $messageBus); diff --git a/src/Bundle/ChillMainBundle/migrations/Version20250610102953.php b/src/Bundle/ChillMainBundle/migrations/Version20250610102953.php index 1aea75863..6d6d2c2ab 100644 --- a/src/Bundle/ChillMainBundle/migrations/Version20250610102953.php +++ b/src/Bundle/ChillMainBundle/migrations/Version20250610102953.php @@ -2,10 +2,18 @@ declare(strict_types=1); +/* + * 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. + */ + namespace Chill\Migrations\Main; use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; + final class Version20250610102953 extends AbstractMigration { public function getDescription(): string diff --git a/src/Bundle/ChillMainBundle/migrations/Version20250618115938.php b/src/Bundle/ChillMainBundle/migrations/Version20250618115938.php index 5342970d9..f05a7072f 100644 --- a/src/Bundle/ChillMainBundle/migrations/Version20250618115938.php +++ b/src/Bundle/ChillMainBundle/migrations/Version20250618115938.php @@ -2,6 +2,13 @@ declare(strict_types=1); +/* + * 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. + */ + namespace Chill\Migrations\Main; use Doctrine\DBAL\Schema\Schema; diff --git a/src/Bundle/ChillMainBundle/migrations/Version20250623120824.php b/src/Bundle/ChillMainBundle/migrations/Version20250623120824.php index e5ef06f8c..3cf715db5 100644 --- a/src/Bundle/ChillMainBundle/migrations/Version20250623120824.php +++ b/src/Bundle/ChillMainBundle/migrations/Version20250623120824.php @@ -2,6 +2,13 @@ declare(strict_types=1); +/* + * 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. + */ + namespace Chill\Migrations\Main; use Doctrine\DBAL\Schema\Schema; diff --git a/src/Bundle/ChillPersonBundle/Notification/FlagProviders/DesignatedReferrerNotificationFlagProvider.php b/src/Bundle/ChillPersonBundle/Notification/FlagProviders/DesignatedReferrerNotificationFlagProvider.php index 5e6144d51..74019fd0d 100644 --- a/src/Bundle/ChillPersonBundle/Notification/FlagProviders/DesignatedReferrerNotificationFlagProvider.php +++ b/src/Bundle/ChillPersonBundle/Notification/FlagProviders/DesignatedReferrerNotificationFlagProvider.php @@ -1,5 +1,14 @@