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

Extraction du module Fichier

parent 5fbcfff9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ return [
        'UnicaenPdf',
        'UnicaenRenderer',
        'Structure',
        'Fichier',
        'Import',
        'Indicateur',
        'Individu',
+4 −4
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ use Application\Cache\MemcachedFactory;
use Application\Controller\Factory\IndexControllerFactory;
use Application\Controller\Plugin\Forward;
use Application\Controller\Plugin\ForwardFactory;
use Application\Controller\Plugin\Uploader\UploaderPluginFactory;
use Fichier\Controller\Plugin\Uploader\UploaderPluginFactory;
use Application\Entity\Db\Repository\DefaultEntityRepository;
use Application\Entity\UserWrapperFactory;
use Application\Entity\UserWrapperFactoryFactory;
@@ -27,8 +27,8 @@ use Application\View\Helper\EscapeTextHelper;
use Application\View\Helper\FiltersPanel\FiltersPanelHelper;
use Application\View\Helper\Sortable;
use Application\View\Helper\SortableHelperFactory;
use Application\View\Helper\Uploader\UploaderHelper;
use Application\View\Helper\Uploader\UploaderHelperFactory;
use Fichier\View\Helper\Uploader\UploaderHelper;
use Fichier\View\Helper\Uploader\UploaderHelperFactory;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
use Doctrine\DBAL\Driver\PDO\PgSQL\Driver as PgSQL;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
@@ -295,7 +295,7 @@ return array(
    ),
    'form_elements'   => [
        'invokables'   => [
            'UploadForm' => 'Application\Controller\Plugin\Uploader\UploadForm',
            'UploadForm' => 'Fichier\Controller\Plugin\Uploader\UploadForm',
        ],
        'factories' => [
            'EcoleDoctoraleForm' => EcoleDoctoraleFormFactory::class,
+2 −2
Original line number Diff line number Diff line
@@ -6,11 +6,11 @@ use Application\Assertion\Exception\FailedAssertionException;
use Application\Assertion\Interfaces\EntityAssertionInterface;
use Application\Assertion\ThrowsFailedAssertionExceptionTrait;
use Doctorant\Entity\Db\Doctorant;
use Application\Entity\Db\NatureFichier;
use Fichier\Entity\Db\NatureFichier;
use Application\Entity\Db\Role;
use Application\Entity\Db\These;
use Application\Entity\Db\TypeValidation;
use Application\Entity\Db\VersionFichier;
use Fichier\Entity\Db\VersionFichier;
use Application\Entity\Db\VSitu\DepotVersionCorrigeeValidationPresident;
use Application\Service\FichierThese\FichierTheseServiceAwareInterface;
use Application\Service\FichierThese\FichierTheseServiceAwareTrait;
+0 −141
Original line number Diff line number Diff line
<?php

namespace Application\Command;

use InvalidArgumentException;
use UnicaenApp\Exception\RuntimeException;

/**
 * TODO : si encore utilisée, transformer cette classe en ShellCommand (ex: TestArchivabiliteShellCommand).
 */
class CheckWSValidationFichierCinesCommand
{
    const URL = 'https://facile.cines.fr/xml';

    /**
     * Exemples de réponses normales :
     *      "RESPONSE: OK - 893 ms|Response=893ms;1000;5000;0"
     *      "RESPONSE: CRITICAL - 5493 ms|Response=5493ms;1000;5000;0"
     */
    const RESPONSE_FORMAT = '/^RESPONSE: (OK|WARNING|CRITICAL) - (\d+) ms(.+)$/';

    /**
     * Exemple de réponse avec erreur :
     *      "RESPONSE: UNKNOWN - ERROR: /bin/nc does does not exist|Response=ms;1000;5000;0"
     */
    const ERROR_FORMAT = '/ERROR: (.+)\|Response=(.+)/';

    const STATUS_OK = 'OK';
    const STATUS_WARNING = 'WARNING';
    const STATUS_CRITICAL = 'CRITICAL';

    const STATUSES = [
        self::STATUS_OK       => 0,
        self::STATUS_WARNING  => 1,
        self::STATUS_CRITICAL => 2,
    ];

    /**
     * @var string
     */
    protected $scriptFilePath;

    /**
     * @var string
     */
    protected $result;

    /**
     * @var array
     */
    protected $resultMatches;

    /**
     * @param string $scriptFilePath
     */
    public function __construct(string $scriptFilePath)
    {
        $this->scriptFilePath = $scriptFilePath;
    }

    /**
     * Exécute la commande.
     */
    public function execute()
    {
        $args = sprintf("-w 1000 -c 5000 -u %s", self::URL);
        $command = sprintf("sh %s %s", $this->scriptFilePath, $args);

        $runner = new ShellCommandRunner();
        $runner->setCommandAsString($command);
        $this->checkPrerequisites();
        echo sprintf("Lancement de la commande: %s\n", $command);
        $result = $runner->runCommand();
        $this->result = implode(PHP_EOL, $result->getOutput());
        $this->parseResult();
    }

    private function checkPrerequisites()
    {
        $dir = dirname($this->scriptFilePath);
        $samplePdfFilePath = $dir . '/sample.pdf';

        if (! is_readable($samplePdfFilePath)) {
            throw new InvalidArgumentException(
                "Le fichier échantillon 'sample.pdf' doit être présent dans le répertoire " . $dir);
        }
    }

    private function parseResult()
    {
        if (preg_match($pattern = self::ERROR_FORMAT, $this->result, $matches)) {
            throw new RuntimeException(
                "La réponse du script de test du web service de validation indique qu'il a rencontré l'erreur '$matches[1]' : " .
                PHP_EOL . $this->result);
        }

        if (! preg_match($pattern = self::RESPONSE_FORMAT, $this->result, $matches)) {
            throw new RuntimeException(
                "La réponse du script de test du web service de validation n'est pas au format '$pattern' attendu : " .
                PHP_EOL . $this->result);
        }

        $this->resultMatches = $matches;
    }

    /**
     * @return string
     */
    public function getStatusResult()
    {
        return $this->resultMatches[1];
    }

    /**
     * @param string $worstAcceptableStatus
     * @return bool
     */
    public function getBooleanStatusResult($worstAcceptableStatus = self::STATUS_WARNING)
    {
        $worst  = self::STATUSES[$worstAcceptableStatus];
        $actual = self::STATUSES[$this->getStatusResult()];

        return $actual <= $worst;
    }

    /**
     * @return int
     */
    public function getDurationResult()
    {
        return (int) $this->resultMatches[2];
    }

    /**
     * @return string
     */
    public function getResult()
    {
        return $this->result;
    }
}
 No newline at end of file
+0 −21
Original line number Diff line number Diff line
<?php

namespace Application\Command;

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Exception\InvalidArgumentException;

class CheckWSValidationFichierCinesCommandFactory
{
    public function __invoke(ContainerInterface $container)
    {
        $config = $container->get('config');
        if (!isset($config['sygal']['archivabilite']['check_ws_script_path'])) {
            throw new InvalidArgumentException("Option de config sygal.archivabilite.check_ws_script_path introuvable");
        }

        $scriptPath = $config['sygal']['archivabilite']['check_ws_script_path'];

        return new CheckWSValidationFichierCinesCommand($scriptPath);
    }
}
 No newline at end of file
Loading