Pipeline fixes

This commit is contained in:
Julie Lenaerts 2025-07-04 13:04:10 +02:00
parent a556a9545b
commit 05a55f24e6
14 changed files with 74 additions and 65 deletions

View File

@ -181,9 +181,6 @@ class Notification implements TrackUpdateInterface
} }
} }
/**
* @return Collection<UserGroup>
*/
public function getAddresseeUserGroups(): Collection public function getAddresseeUserGroups(): Collection
{ {
return $this->addresseeUserGroups; return $this->addresseeUserGroups;

View File

@ -15,11 +15,8 @@ use Symfony\Component\Form\DataMapperInterface;
final readonly class NotificationFlagDataMapper implements DataMapperInterface final readonly class NotificationFlagDataMapper implements DataMapperInterface
{ {
private array $notificationFlagProviders; public function __construct(private array $notificationFlagProviders)
public function __construct(array $notificationFlagProviders)
{ {
$this->notificationFlagProviders = $notificationFlagProviders;
} }
public function mapDataToForms($viewData, $forms): void public function mapDataToForms($viewData, $forms): void
@ -36,9 +33,8 @@ final readonly class NotificationFlagDataMapper implements DataMapperInterface
if (isset($formsArray[$flag])) { if (isset($formsArray[$flag])) {
$flagForm = $formsArray[$flag]; $flagForm = $formsArray[$flag];
$immediateEmailChecked = in_array('immediate-email', $viewData[$flag] ?? []); $immediateEmailChecked = in_array('immediate-email', $viewData[$flag] ?? [], true);
$dailyEmailChecked = in_array('daily-email', $viewData[$flag] ?? []); $dailyEmailChecked = in_array('daily-email', $viewData[$flag] ?? [], true);
$noEmailChecked = in_array('no-email', $viewData[$flag] ?? []);
if ($flagForm->has('immediate_email')) { if ($flagForm->has('immediate_email')) {
$flagForm->get('immediate_email')->setData($immediateEmailChecked); $flagForm->get('immediate_email')->setData($immediateEmailChecked);
@ -62,15 +58,15 @@ final readonly class NotificationFlagDataMapper implements DataMapperInterface
$flagForm = $formsArray[$flag]; $flagForm = $formsArray[$flag];
$viewData[$flag] = []; $viewData[$flag] = [];
if ($flagForm['immediate_email']->getData()) { if (true === $flagForm['immediate_email']->getData()) {
$viewData[$flag][] = 'immediate-email'; $viewData[$flag][] = 'immediate-email';
} }
if ($flagForm['daily_email']->getData()) { if (true === $flagForm['daily_email']->getData()) {
$viewData[$flag][] = 'daily-email'; $viewData[$flag][] = 'daily-email';
} }
if (empty($viewData[$flag])) { if ([] === $viewData[$flag]) {
$viewData[$flag][] = 'no-email'; $viewData[$flag][] = 'no-email';
} }
} }

View File

@ -13,7 +13,6 @@ namespace Chill\MainBundle\Form;
use Chill\MainBundle\Entity\Notification; use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Form\Type\ChillTextareaType; use Chill\MainBundle\Form\Type\ChillTextareaType;
use Chill\MainBundle\Form\Type\PickUserDynamicType;
use Chill\MainBundle\Form\Type\PickUserGroupOrUserDynamicType; use Chill\MainBundle\Form\Type\PickUserGroupOrUserDynamicType;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;

View File

@ -21,7 +21,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class NotificationFlagsType extends AbstractType class NotificationFlagsType extends AbstractType
{ {
private array $notificationFlagProviders; private readonly array $notificationFlagProviders;
public function __construct(NotificationFlagManager $notificationFlagManager) public function __construct(NotificationFlagManager $notificationFlagManager)
{ {
@ -50,11 +50,6 @@ class NotificationFlagsType extends AbstractType
'required' => false, 'required' => false,
'mapped' => false, 'mapped' => false,
]) ])
->add('no_email', CheckboxType::class, [
'label' => false,
'required' => false,
'mapped' => false,
])
; ;
} }
} }

View File

@ -43,6 +43,7 @@ readonly class ScheduleDailyNotificationDigestHandler
$this->logger->warning('[ScheduleDailyNotificationDigestHandler] User not found', [ $this->logger->warning('[ScheduleDailyNotificationDigestHandler] User not found', [
'user_id' => $userId, 'user_id' => $userId,
]); ]);
return; return;
} }
@ -54,14 +55,13 @@ readonly class ScheduleDailyNotificationDigestHandler
); );
// Filter out notifications that were sent immediately // Filter out notifications that were sent immediately
$dailyNotifications = array_filter($notifications, function ($notification) use ($user) { $dailyNotifications = array_filter($notifications, fn($notification) => !$notification->isSendImmediately($user));
return !$notification->isSendImmediately($user);
});
if (empty($dailyNotifications)) { if ([] === $dailyNotifications) {
$this->logger->info('[ScheduleDailyNotificationDigestHandler] No daily notifications found for user', [ $this->logger->info('[ScheduleDailyNotificationDigestHandler] No daily notifications found for user', [
'user_id' => $userId, 'user_id' => $userId,
]); ]);
return; return;
} }

View File

@ -81,7 +81,7 @@ readonly class NotificationMailer
private function sendNotificationEmailsToAddressees(Notification $notification): void private function sendNotificationEmailsToAddressees(Notification $notification): void
{ {
if (null === $notification->getType()) { if ('' === $notification->getType()) {
$this->logger->warning('[NotificationMailer] Notification has no type, skipping email processing', [ $this->logger->warning('[NotificationMailer] Notification has no type, skipping email processing', [
'notification_id' => $notification->getId(), 'notification_id' => $notification->getId(),
]); ]);
@ -183,7 +183,7 @@ readonly class NotificationMailer
*/ */
public function sendDailyDigest($user, array $notifications): void public function sendDailyDigest($user, array $notifications): void
{ {
if (null === $user->getEmail() || empty($notifications)) { if (null === $user->getEmail() || [] === $notifications) {
return; return;
} }
@ -211,37 +211,7 @@ readonly class NotificationMailer
'error_message' => $e->getMessage(), 'error_message' => $e->getMessage(),
'error_trace' => $e->getTraceAsString(), 'error_trace' => $e->getTraceAsString(),
]); ]);
throw $e; // Re-throw so the message handler can handle the failure throw $e;
}
}
/**
* @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(),
]);
}
} }
} }
} }

View File

@ -1,5 +1,14 @@
<?php <?php
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\MainBundle\Notification\FlagProviders; namespace Chill\MainBundle\Notification\FlagProviders;
use Symfony\Component\Translation\TranslatableMessage; use Symfony\Component\Translation\TranslatableMessage;
@ -7,7 +16,6 @@ use Symfony\Contracts\Translation\TranslatableInterface;
class NotificationByUserFlagProvider implements NotificationFlagProviderInterface class NotificationByUserFlagProvider implements NotificationFlagProviderInterface
{ {
public function getFlag(): string public function getFlag(): string
{ {
return 'notif-by-user'; return 'notif-by-user';

View File

@ -1,5 +1,14 @@
<?php <?php
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\MainBundle\Notification\FlagProviders; namespace Chill\MainBundle\Notification\FlagProviders;
use Symfony\Component\Translation\TranslatableMessage; use Symfony\Component\Translation\TranslatableMessage;
@ -7,7 +16,6 @@ use Symfony\Contracts\Translation\TranslatableInterface;
class WorkflowTransitionNotificationFlagProvider implements NotificationFlagProviderInterface class WorkflowTransitionNotificationFlagProvider implements NotificationFlagProviderInterface
{ {
public function getFlag(): string public function getFlag(): string
{ {
return 'workflow-trans-notif'; return 'workflow-trans-notif';

View File

@ -137,10 +137,8 @@ class NotificationMailerTest extends TestCase
$messageBus = $this->createMock(MessageBusInterface::class); $messageBus = $this->createMock(MessageBusInterface::class);
$messageBus->expects($this->once()) $messageBus->expects($this->once())
->method('dispatch') ->method('dispatch')
->with($this->callback(function (SendImmediateNotificationEmailMessage $message) { ->with($this->callback(fn(SendImmediateNotificationEmailMessage $message) => 123 === $message->getNotificationId()
return 123 === $message->getNotificationId() && 456 === $message->getAddresseeId()))
&& 456 === $message->getAddresseeId();
}))
->willReturn(new Envelope(new \stdClass())); ->willReturn(new Envelope(new \stdClass()));
$mailer = $this->buildNotificationMailer(null, $messageBus); $mailer = $this->buildNotificationMailer(null, $messageBus);

View File

@ -2,10 +2,18 @@
declare(strict_types=1); 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; namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration; use Doctrine\Migrations\AbstractMigration;
final class Version20250610102953 extends AbstractMigration final class Version20250610102953 extends AbstractMigration
{ {
public function getDescription(): string public function getDescription(): string

View File

@ -2,6 +2,13 @@
declare(strict_types=1); 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; namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;

View File

@ -2,6 +2,13 @@
declare(strict_types=1); 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; namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;

View File

@ -1,5 +1,14 @@
<?php <?php
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\PersonBundle\Notification\FlagProviders; namespace Chill\PersonBundle\Notification\FlagProviders;
use Chill\MainBundle\Notification\FlagProviders\NotificationFlagProviderInterface; use Chill\MainBundle\Notification\FlagProviders\NotificationFlagProviderInterface;
@ -8,7 +17,6 @@ use Symfony\Contracts\Translation\TranslatableInterface;
class DesignatedReferrerNotificationFlagProvider implements NotificationFlagProviderInterface class DesignatedReferrerNotificationFlagProvider implements NotificationFlagProviderInterface
{ {
public function getFlag(): string public function getFlag(): string
{ {
return 'referrer-acc-course-notif'; return 'referrer-acc-course-notif';

View File

@ -1,5 +1,14 @@
<?php <?php
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\PersonBundle\Notification\FlagProviders; namespace Chill\PersonBundle\Notification\FlagProviders;
use Chill\MainBundle\Notification\FlagProviders\NotificationFlagProviderInterface; use Chill\MainBundle\Notification\FlagProviders\NotificationFlagProviderInterface;
@ -8,7 +17,6 @@ use Symfony\Contracts\Translation\TranslatableInterface;
class PersonAddressMoveNotificationFlagProvider implements NotificationFlagProviderInterface class PersonAddressMoveNotificationFlagProvider implements NotificationFlagProviderInterface
{ {
public function getFlag(): string public function getFlag(): string
{ {
return 'person-move-notif'; return 'person-move-notif';