Commit 2b2c6d94 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Module StepStar : log supplémentaire de synthèse des envois

parent 19c6a626
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ class Log
{
    const OPERATION__ENVOI = 'ENVOI';
    const OPERATION__GENERATION_XML = 'GENERATION_XML';
    const OPERATION__SYNTHESE = 'SYNTHESE';

    private int $id;
    private string $operation;
+15 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ class EnvoiFacade
         * (Un Log par thèse est créé.)
         */
        $operation = Log::OPERATION__ENVOI;
        $nbEnvoisReussis = $nbEnvoisEchoues = $nbEnvoisInutiles = 0;
        $tefFilesPaths = $this->listXmlFilesInDirectory($outputDir);
        foreach ($tefFilesPaths as $i => $tefFilePath) {
            $theseId = $this->extractTheseIdFromTefFilePath($tefFilePath);
@@ -100,12 +101,15 @@ class EnvoiFacade
                $this->appendToLog($message);
                try {
                    $this->envoyer($tefFilePath);
                    $nbEnvoisReussis++;
                } catch (Exception $e) {
                    $nbEnvoisEchoues++;
                    $success = false;
                    $this->appendToLog("  :-( " . $e->getMessage());
                    $this->log->setTefFileContent(file_get_contents($tefFilePath)); // conservation du TEF envoyé
                }
            } else {
                $nbEnvoisInutiles++;
                $message = sprintf(
                    "> Envoi %d/%d inutile : These %d (%s) - Fichier '%s' - Inutile car identique au dernier envoi du %s.",
                    $i + 1, count($tefFilesPaths), $theseId, $doctorantIdentite, $tefFilePath, $lastLog->getStartedOnToString()
@@ -116,6 +120,17 @@ class EnvoiFacade
            $this->saveCurrentLog();
            yield $this->log;
        }

        $operation = Log::OPERATION__SYNTHESE;
        $this->newLog($operation, $command, $tag);
        $this->log->setSuccess(true);
        $message = sprintf(
            "Synthèse des envois : %d envois prévus / %d envois réussis / %d envois échoués / %d envois inutiles.",
            count($tefFilesPaths), $nbEnvoisReussis, $nbEnvoisEchoues, $nbEnvoisInutiles
        );
        $this->appendToLog($message);
        $this->saveCurrentLog();
        yield $this->log;
    }

    private function saveCurrentLog()
+3 −3
Original line number Diff line number Diff line
@@ -33,13 +33,13 @@ class LogService
    public function newLog(?string $operation = null, ?string $command = null, ?string $tag = null): Log
    {
        $log = new Log();
        if ($operation) {
        if ($operation !== null) {
            $log->setOperation($operation);
        }
        if ($command) {
        if ($command !== null) {
            $log->setCommand($command);
        }
        if ($tag) {
        if ($tag !== null) {
            $log->setTag($tag);
        }
        $log->setStartedOn();
+2 −2
Original line number Diff line number Diff line
@@ -14,10 +14,10 @@ trait LogServiceAwareTrait
     * Instancie un nouveau Log tout nu, qui devient le Log courant.
     *
     * @param string|null $operation
     * @param string|null $command
     * @param string $command
     * @param string|null $tag
     */
    protected function newLog(?string $operation = null, ?string $command = null, ?string $tag = null)
    protected function newLog(?string $operation = null, string $command = '', ?string $tag = null)
    {
        $this->log = $this->logService->newLog($operation, $command, $tag);
    }