This commit is contained in:
Julien Fastré 2022-04-22 11:41:38 +02:00
parent abc3caee00
commit f7d9551dc1
6 changed files with 53 additions and 16 deletions

View File

@ -1,5 +1,14 @@
<?php <?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Notification\EventListener; namespace Chill\MainBundle\Notification\EventListener;
use Chill\MainBundle\Notification\NotificationPersisterInterface; use Chill\MainBundle\Notification\NotificationPersisterInterface;
@ -9,7 +18,6 @@ use Symfony\Component\HttpKernel\Event\TerminateEvent;
class PersistNotificationOnTerminateEventSubscriber implements EventSubscriberInterface class PersistNotificationOnTerminateEventSubscriber implements EventSubscriberInterface
{ {
private EntityManagerInterface $em; private EntityManagerInterface $em;
private NotificationPersisterInterface $persister; private NotificationPersisterInterface $persister;
@ -25,7 +33,7 @@ class PersistNotificationOnTerminateEventSubscriber implements EventSubscriberIn
return [ return [
'kernel.terminate' => [ 'kernel.terminate' => [
['onKernelTerminate', 1024], // we must ensure that the priority is before sending email ['onKernelTerminate', 1024], // we must ensure that the priority is before sending email
] ],
]; ];
} }

View File

@ -1,5 +1,14 @@
<?php <?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Notification; namespace Chill\MainBundle\Notification;
use Chill\MainBundle\Entity\Notification; use Chill\MainBundle\Entity\Notification;
@ -8,11 +17,6 @@ class NotificationPersister implements NotificationPersisterInterface
{ {
private array $waitingNotifications = []; private array $waitingNotifications = [];
public function persist(Notification $notification): void
{
$this->waitingNotifications[] = $notification;
}
/** /**
* @return array|Notification[] * @return array|Notification[]
*/ */
@ -20,4 +24,9 @@ class NotificationPersister implements NotificationPersisterInterface
{ {
return $this->waitingNotifications; return $this->waitingNotifications;
} }
public function persist(Notification $notification): void
{
$this->waitingNotifications[] = $notification;
}
} }

View File

@ -1,11 +1,20 @@
<?php <?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Notification; namespace Chill\MainBundle\Notification;
use Chill\MainBundle\Entity\Notification; use Chill\MainBundle\Entity\Notification;
/** /**
* Store the notification * Store the notification.
* *
* Those notification will be stored into database by the kernel. This * Those notification will be stored into database by the kernel. This
* will also ensure that this happens outside of regular operations * will also ensure that this happens outside of regular operations
@ -13,10 +22,10 @@ use Chill\MainBundle\Entity\Notification;
*/ */
interface NotificationPersisterInterface interface NotificationPersisterInterface
{ {
public function persist(Notification $notification): void;
/** /**
* @return array|Notification[] * @return array|Notification[]
*/ */
public function getWaitingNotifications(): array; public function getWaitingNotifications(): array;
public function persist(Notification $notification): void;
} }

View File

@ -1,5 +1,14 @@
<?php <?php
/**
* 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.
*/
declare(strict_types=1);
namespace Notification\EventListener; namespace Notification\EventListener;
use Chill\MainBundle\Entity\Notification; use Chill\MainBundle\Entity\Notification;
@ -11,7 +20,11 @@ use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\HttpKernel\Event\TerminateEvent; use Symfony\Component\HttpKernel\Event\TerminateEvent;
class PersistNotificationOnTerminateEventSubscriberTest extends TestCase /**
* @internal
* @coversNothing
*/
final class PersistNotificationOnTerminateEventSubscriberTest extends TestCase
{ {
use ProphecyTrait; use ProphecyTrait;

View File

@ -15,7 +15,6 @@ use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Notification\NotificationPersisterInterface; use Chill\MainBundle\Notification\NotificationPersisterInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\LifecycleEventArgs; use Doctrine\Persistence\Event\LifecycleEventArgs;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
@ -25,11 +24,10 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class UserRefEventSubscriber implements EventSubscriberInterface class UserRefEventSubscriber implements EventSubscriberInterface
{ {
private EngineInterface $engine;
private NotificationPersisterInterface $notificationPersister; private NotificationPersisterInterface $notificationPersister;
private EngineInterface $engine;
private Security $security; private Security $security;
private TranslatorInterface $translator; private TranslatorInterface $translator;

View File

@ -41,8 +41,8 @@ class Comment implements TrackCreationInterface, TrackUpdateInterface
/** /**
* @ORM\Column(type="text") * @ORM\Column(type="text")
* @Groups({"read", "write"}) * @Groups({"read", "write"})
* @Assert\NotBlank() * @Assert\NotBlank
* @Assert\NotNull() * @Assert\NotNull
*/ */
private $content; private $content;