Commit af479bb4 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Merge branch 'suppr-valid-depot-corr'

parents ef5e5dd0 ffc4a8ab
Loading
Loading
Loading
Loading
Loading
+11 −5
Changes for module/Application/src/Application/Controller/Factory/FichierTheseControllerFactory.php: 11 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ use Application\Service\Fichier\FichierService;
use Application\Service\Individu\IndividuService;
use Application\Service\Notification\NotifierService;
use Application\Service\These\TheseService;
use Application\Service\Validation\ValidationService;
use Application\Service\VersionFichier\VersionFichierService;
use Zend\Mvc\Controller\ControllerManager;

@@ -20,18 +21,22 @@ class FichierTheseControllerFactory
     */
    public function __invoke(ControllerManager $controllerManager)
    {
        $serviceLocator = $controllerManager->getServiceLocator();

        /**
         * @var TheseService          $theseService
         * @var FichierService        $fichierService
         * @var VersionFichierService $versionFichierService
         * @var NotifierService       $notificationService
         * @var IndividuService       $individuService
         * @var ValidationService     $validationService
         */
        $theseService = $controllerManager->getServiceLocator()->get('TheseService');
        $fichierService = $controllerManager->getServiceLocator()->get('FichierService');
        $versionFichierService = $controllerManager->getServiceLocator()->get('VersionFichierService');
        $notificationService = $controllerManager->getServiceLocator()->get(NotifierService::class);
        $individuService = $controllerManager->getServiceLocator()->get('IndividuService');
        $theseService = $serviceLocator->get('TheseService');
        $fichierService = $serviceLocator->get('FichierService');
        $versionFichierService = $serviceLocator->get('VersionFichierService');
        $notificationService = $serviceLocator->get(NotifierService::class);
        $individuService = $serviceLocator->get('IndividuService');
        $validationService = $serviceLocator->get('ValidationService');

        $controller = new FichierTheseController();
        $controller->setTheseService($theseService);
@@ -39,6 +44,7 @@ class FichierTheseControllerFactory
        $controller->setVersionFichierService($versionFichierService);
        $controller->setNotifierService($notificationService);
        $controller->setIndividuService($individuService);
        $controller->setValidationService($validationService);

        return $controller;
    }
+13
Changes for module/Application/src/Application/Controller/FichierTheseController.php: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Application\Controller;

use Application\Entity\Db\Fichier;
use Application\Entity\Db\NatureFichier;
use Application\Entity\Db\TypeValidation;
use Application\Entity\Db\VersionFichier;
use Application\Filter\IdifyFilterAwareTrait;
use Application\Filter\NomFichierFormatter;
@@ -14,6 +15,7 @@ use Application\Service\Fichier\FichierServiceAwareTrait;
use Application\Service\Individu\IndividuServiceAwareTrait;
use Application\Service\Notification\NotifierServiceAwareTrait;
use Application\Service\These\TheseServiceAwareTrait;
use Application\Service\Validation\ValidationServiceAwareTrait;
use Application\Service\VersionFichier\VersionFichierServiceAwareTrait;
use Application\View\Helper\Sortable;
use Doctrine\ORM\NonUniqueResultException;
@@ -34,6 +36,7 @@ class FichierTheseController extends AbstractController
    use IdifyFilterAwareTrait;
    use NotifierServiceAwareTrait;
    use IndividuServiceAwareTrait;
    use ValidationServiceAwareTrait;

    const UPLOAD_MAX_FILESIZE = '5M';

@@ -359,6 +362,8 @@ class FichierTheseController extends AbstractController
    {
        $fichier = $this->requestFichier();
        $these = $this->requestedThese();
        $version = $fichier->getVersion();
        $nature = $fichier->getNature();

        if (!$fichier || $fichier->getThese() !== $these) {
            // NB: il a fallu abandonner l'exception car faisait planter la suppression
@@ -368,8 +373,16 @@ class FichierTheseController extends AbstractController
            return [];
        }

        // s'il s'agit de la thèse corrigée, il faudra supprimer l'éventuelle validation du dépôt
        $supprimerValidationDepotTheseCorrigee = $nature->estThesePdf() && $version->estVersionCorrigee();

        $this->fichierService->supprimerFichier($fichier);

        // suppression de l'éventuelle validation du dépôt
        if ($supprimerValidationDepotTheseCorrigee) {
            $this->validationService->unvalidateDepotTheseCorrigee($these);
        }

        return false;
    }

−18
Changes for module/Application/src/Application/Controller/TheseController.php: 0 added lines, 18 removed lines.
Original line number Diff line number Diff line
@@ -855,29 +855,11 @@ class TheseController extends AbstractController
        $these = $this->requestedThese();
        $version = $this->fichierService->fetchVersionFichier($this->params()->fromQuery('version'));

//        $theseFichiers = $these->getFichiersByNatureEtVersion(NatureFichier::CODE_THESE_PDF, $version);
        $theseFichiers = $this->fichierService->getRepository()->fetchFichiers($these, NatureFichier::CODE_THESE_PDF, $version, false);
        /** @var Fichier $fichierThese */
        $fichierThese = current($theseFichiers);

        if ($this->getRequest()->isPost()) {

            //TODO move this to the suppr action
            // retrait de la validation précédente si le fichier est identique afin de pouvoir retester l'archivabilité après effacement
            $qb = $this->validationService->getRepository()->createQueryBuilder('v')
                ->where("t.id = :theseid")
                ->andWhere("tv.code = :type");
            $qb->setParameter(":theseid", $these->getId());
            $qb->setParameter(":type", TypeValidation::CODE_DEPOT_THESE_CORRIGEE);
            $res = $qb->getQuery()->getResult();

            if(isset($res) && count($res) > 0) {
                //echo "something is here !"."<br/>";
                $validation = $res[0];
                $this->validationService->getEntityManager()->remove($validation);
                $this->validationService->getEntityManager()->flush();
            }

            $action = $this->params()->fromPost('action', $this->params()->fromQuery('action'));
            if ('tester' === $action) {
                try {
+2 −1
Changes for module/Application/src/Application/Service/Fichier/FichierService.php: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -426,9 +426,10 @@ class FichierService extends BaseService
    public function supprimerFichier(Fichier $fichier)
    {
        $version = $fichier->getVersion();
        $nature = $fichier->getNature();

        // si c'est le fichier de thèse original qui est supprimé, suppression aussi du fichier retraité éventuel
        $supprimerAussiTheseRetraite = ! $fichier->getEstAnnexe() && $version->estVersionOriginale();
        $supprimerAussiTheseRetraite = $nature->estThesePdf() && $version->estVersionOriginale();

        // suppression du fichier
        // NB: "validites" supprimés en cascade
+13 −4
Changes for module/Application/src/Application/Service/Validation/ValidationService.php: 13 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -107,7 +107,11 @@ class ValidationService extends BaseService
            $individu);

        $this->entityManager->persist($v);
        try {
            $this->entityManager->flush($v);
        } catch (OptimisticLockException $e) {
            throw new RuntimeException("Erreur rencontrée lors de l'enregistrement en bdd", null, $e);
        }

        return $v;
    }
@@ -142,17 +146,22 @@ class ValidationService extends BaseService
            ->andWhereTheseIs($these)
            ->andWhereTypeIs($type = TypeValidation::CODE_DEPOT_THESE_CORRIGEE)
            ->andWhereNotHistorise();
        try {
            /** @var Validation $v */
            $v = $qb->getQuery()->getOneOrNullResult();

        if (!$v) {
        } catch (NonUniqueResultException $e) {
            throw new RuntimeException(
                sprintf("Aucune validation de type '%s' trouvée pour la thèse %s", $type, $these));
                sprintf("Plusieures validations non historisées de type '%s' trouvées pour la thèse '%s'", $type, $these));
        }

        if ($v !== null) {
            $v->historiser();

            try {
                $this->getEntityManager()->flush($v);
            } catch (OptimisticLockException $e) {
                throw new RuntimeException("Erreur rencontrée lors de l'enregistrement en bdd", null, $e);
            }
        }

        return $v;
    }