Commit 4b651861 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

[FIX] Meilleure remontée à l'utilisateur des erreurs rencontrées lors du dépôt de la thèse.

parent ee420d26
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ Journal des modifications
- Script de lancement de l'import run-import.sh : utilisation de flock pour éviter 2 lancements en parallèle.
- Téléchargement de la version initiale/corrigée imprimable : intitulé de titre plus précis sur la version concernée.
- [FIX] Correction du sujet erroné du mail envoyé lorsque l'ajout de la page de couverture est terminé.
- [FIX] Meilleure remontée à l'utilisateur des erreurs rencontrées lors du dépôt de la thèse.

3.0.4
-----
+21 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ use Application\View\Helper\Sortable;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\Tools\Pagination\Paginator;
use DoctrineORMModule\Paginator\Adapter\DoctrinePaginator;
use Notification\Exception\NotificationException;
use UnicaenApp\Exception\RuntimeException;
use Zend\Console\Request as ConsoleRequest;
use Zend\Form\Element\Hidden;
@@ -267,7 +268,16 @@ class FichierTheseController extends AbstractController
            // todo: déplacer ceci dans un service écoutant l'événement "fichier de thèse téléversé" déclenché ci-dessus
            if ($nature->estThesePdf()) {
                $notif = $this->notifierService->getNotificationFactory()->createNotificationForTheseTeleversee($these, $version);
                try {
                    $this->notifierService->trigger($notif);
                } catch (NotificationException $e) {
                    return new JsonModel([
                        'errors' => array_filter([
                            $e->getMessage(),
                            $e->getPrevious() ? $e->getPrevious()->getMessage() : null,
                        ])
                    ]);
                }
            }

            // si un rapport de soutenance est déposé, on notifie de BdD
@@ -277,7 +287,16 @@ class FichierTheseController extends AbstractController
                $notif
                    ->setSubject("Dépôt du rapport de soutenance")
                    ->setTemplatePath('application/these/mail/notif-depot-rapport-soutenance');
                try {
                    $this->notifierService->trigger($notif);
                } catch (NotificationException $e) {
                    return new JsonModel([
                        'errors' => array_filter([
                            $e->getMessage(),
                            $e->getPrevious() ? $e->getPrevious()->getMessage() : null,
                        ])
                    ]);
                }
            }
        }

+16 −4
Original line number Diff line number Diff line
@@ -3,8 +3,11 @@
namespace Notification\Service;

use DateTime;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Notification\Entity\NotifMail;
use Notification\Entity\Service\NotifEntityServiceAwareTrait;
use Notification\Exception\NotificationException;
use Notification\MessageContainer;
use Notification\Notification;
use UnicaenApp\Service\EntityManagerAwareTrait;
@@ -75,6 +78,7 @@ class NotifierService

    /**
     * @param Notification $notification
     * @throws \Notification\Exception\NotificationException
     */
    public function trigger(Notification $notification)
    {
@@ -92,6 +96,7 @@ class NotifierService

    /**
     * @param Notification $notification
     * @throws \Notification\Exception\NotificationException
     */
    protected function sendNotification(Notification $notification)
    {
@@ -110,14 +115,21 @@ class NotifierService
//        $body = htmlentities($body);
        $nMail->setBody($body);
        $nMail->setSentOn(new DateTime());
        $this->getEntityManager()->persist($nMail);
        $this->getEntityManager()->flush($nMail);
        try {
            $this->entityManager->persist($nMail);
            $this->entityManager->flush($nMail);
        } catch (ORMException $e) {
            throw new NotificationException("Erreur rencontrée lors de l'enregistrement dans NotifMail", null, $e);
        }

        try {
            $message = $this->mailerService->send($email);
        } catch (\Exception $e) {
            throw new NotificationException("Erreur rencontrée lors de l'envoi de la notification", null, $e);
        }

        $sendDate = $this->extractDateFromMessage($message) ?: new \DateTime();
        $notification->setSendDate($sendDate);

    }

    /**