Commit 39a93ee0 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Correction cycle dans les dépendances de services

parent d80baa00
Loading
Loading
Loading
Loading
Loading
+3 −20
Changes for module/Application/src/Application/Command/ValidationFichierCinesCommand.php: 3 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -3,16 +3,12 @@
namespace Application\Command;

use Application\Command\Exception\CommandExecutionException;
use Application\Entity\Db\Fichier;
use Application\Service\Fichier\FichierServiceAwareTrait;
use Application\Validator\Exception\CinesErrorException;
use DOMDocument;
use UnicaenApp\Exception\RuntimeException;

class ValidationFichierCinesCommand
{
    use FichierServiceAwareTrait;

    const XML_TAG_VALIDATOR = 'validator';

    const XML_TAG_VALID = 'valid';
@@ -62,26 +58,13 @@ class ValidationFichierCinesCommand
    }

    /**
     * @param Fichier|string $fichier
     * @param string $filepath Chemin vers le fichier sur le disque
     * @param string $url URL du web service, si différente de celle par défaut
     * @param int    $maxExecutionTime
     */
    public function execute($fichier, $url = null, $maxExecutionTime = null)
    public function execute($filepath, $url = null, $maxExecutionTime = null)
    {
        if ($fichier instanceof Fichier) {
            // création du fichier temporaire sur le disque à partir de la bdd
            $filePath = $this->fichierService->writeFichierToDisk($fichier);
        }
        else {
            $filePath = $fichier;
        }

        $this->execValidationRequest($filePath, $url, $maxExecutionTime);

        if ($fichier instanceof Fichier) {
            // suppression du fichier temporaire sur le disque
            unlink($filePath);
        }
        $this->execValidationRequest($filepath, $url, $maxExecutionTime);
    }

    /**
+1 −8
Changes for module/Application/src/Application/Command/ValidationFichierCinesCommandFactory.php: 1 added line, 8 removed lines.
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Application\Command;

use Application\Service\Fichier\FichierService;
use Zend\ServiceManager\Exception\InvalidArgumentException;
use Zend\ServiceManager\ServiceLocatorInterface;

@@ -17,12 +16,6 @@ class ValidationFichierCinesCommandFactory

        $scriptPath = $config['sodoct']['archivabilite']['script_path'];

        /** @var FichierService $fichierService */
        $fichierService = $serviceLocator->get(FichierService::class);

        $command = new ValidationFichierCinesCommand($scriptPath);
        $command->setFichierService($fichierService);

        return $command;
        return new ValidationFichierCinesCommand($scriptPath);
    }
}
 No newline at end of file
+11 −2
Changes for module/Application/src/Application/Service/Fichier/FichierService.php: 11 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -196,8 +196,11 @@ class FichierService extends BaseService
    {
        $exceptionThrown = null;

        // création du fichier temporaire sur le disque
        $filePath = $this->writeFichierToDisk($fichier);

        try {
            $estArchivable = $this->fichierCinesValidator->isValid($fichier);
            $estArchivable = $this->fichierCinesValidator->isValid($filePath);
            $message = $estArchivable ? "Le fichier est archivable" : current($this->fichierCinesValidator->getMessages());
        }
        catch (CinesErrorException $cee) { // erreur possible à identifier
@@ -211,6 +214,9 @@ class FichierService extends BaseService
            $exceptionThrown = $re;
        }

        // suppression du fichier temporaire sur le disque
        unlink($filePath);

        $resultat = [
            'estArchivable' => $estArchivable,
            'resultat'      => $this->fichierCinesValidator->getResult(),
@@ -277,9 +283,12 @@ class FichierService extends BaseService
     */
    public function creerFichierRetraite(Fichier $fichier, $timeout = null)
    {
        $outputFilePath = $this->retraitementService->retraiterFichier($fichier, $timeout);
        $inputFilePath = $this->writeFichierToDisk($fichier);
        $outputFilePath = $this->retraitementService->retraiterFichier($inputFilePath, $timeout);
        // Si le timout éventuel est atteint, une exception TimedOutCommandException est levée.

        unlink($inputFilePath);

        $outputFileContent = file_get_contents($outputFilePath);
        unlink($outputFilePath);

+3 −3
Changes for module/Application/src/Application/Validator/FichierCinesValidator.php: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -35,13 +35,13 @@ class FichierCinesValidator extends AbstractValidator
    }

    /**
     * @param Fichier|string $fichier
     * @param string $filepath Chemin vers le fichier sur le disque
     * @return bool
     * @throws CinesErrorException
     */
    public function isValid($fichier)
    public function isValid($filepath)
    {
        $this->command->execute($fichier);
        $this->command->execute($filepath);

        $result = $this->command->getArrayResult();

+3 −9
Changes for module/Retraitement/src/Retraitement/Service/RetraitementService.php: 3 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -2,16 +2,12 @@

namespace Retraitement\Service;

use Application\Entity\Db\Fichier;
use Application\Service\Fichier\FichierServiceAwareTrait;
use Retraitement\Exception\TimedOutCommandException;
use Retraitement\Filter\Command\CommandInterface;
use RuntimeException;

class RetraitementService
{
    use FichierServiceAwareTrait;

    /**
     * FichierStarCorrector constructor.
     *
@@ -46,7 +42,7 @@ class RetraitementService
     * @return string Chemin du fichier retraité généré
     * @throws TimedOutCommandException Le timout a été atteint
     */
    public function retraiterFichierByPath($inputFilePath, $timeout = null)
    private function retraiterFichierByPath($inputFilePath, $timeout = null)
    {
        $outputFilePath = $this->generateOutputFilePath($inputFilePath);
        $this->command->generate($outputFilePath, $inputFilePath, $errorFilePath);
@@ -86,16 +82,14 @@ class RetraitementService
    /**
     * Crée un fichier retraité à partir du Fichier spécifié.
     *
     * @param Fichier $fichier Fichier à retraiter
     * @param string $inputFilePath Chemin sur le disque vers le fichier à retraiter
     * @param string $timeout  Timeout à appliquer au lancement du script de retraitement.
     * @return string Chemin du fichier retraité généré
     * @throws TimedOutCommandException Le timout a été atteint
     */
    public function retraiterFichier(Fichier $fichier, $timeout = null)
    public function retraiterFichier($inputFilePath, $timeout = null)
    {
        $inputFilePath = $this->fichierService->writeFichierToDisk($fichier);
        $outputFilePath = $this->retraiterFichierByPath($inputFilePath, $timeout);
        unlink($inputFilePath);

        return $outputFilePath;
    }
Loading