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
{
return $this->addresseeUserGroups;

View File

@ -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';
}
}

View File

@ -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;

View File

@ -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,
])
;
}
}

View File

@ -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;
}

View File

@ -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;
}
}
}

View File

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

View File

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

View File

@ -137,10 +137,8 @@ class NotificationMailerTest extends TestCase
$messageBus = $this->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);

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

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

View File

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