Commit 13dbfe82 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Appel du WS d'import: possibilité de détecter qu'un service appelé n'existe...

Appel du WS d'import: possibilité de détecter qu'un service appelé n'existe pas (ex: financement) ; possibilité de ne pas stopper l'import total lorsqu'un service n'existe pas.
parent 641b9826
Loading
Loading
Loading
Loading
Loading
+1 −0
Changes for module/Import/Module.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ class Module
            'import-all --etablissement= [--synchronize=]' => "Importer toutes les données de tous les serviceq d'un établissement.",
            // parameters
            ['--etablissement',          "Requis. Identifiant de l'établissement, ex: 'UCN'"],
            ['--breakOnServiceNotFound', "Facultatif. Faut-il stopper si un service appelé n'existe pas. Valeurs possibles: 0, 1. Valeur par défaut: 1."],
            ['--synchronize',            "Facultatif. Réaliser ou non la synchro SRC_XXX => XXX. Valeurs possibles: 0, 1. Valeur par défaut: 1."],

            // command
+1 −1
Changes for module/Import/config/import.config.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ return [
                'import-all-console' => [
                    'type' => Simple::class,
                    'options' => [
                        'route'    => 'import-all --etablissement= [--synchronize=]',
                        'route'    => 'import-all --etablissement= [--breakOnServiceNotFound=] [--synchronize=]',
                        'defaults' => [
                            'controller' => Import\Controller\ImportController::class,
                            'action'     => 'import-all-console',
+5 −4
Changes for module/Import/src/Import/Controller/ImportController.php: 5 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -229,7 +229,7 @@ class ImportController extends AbstractActionController
        $service = $this->params('service');
        $codeStructure = $this->params('etablissement'); // ex: 'UCN'
        $sourceCode = $this->params('source_code');
        $synchronize = $this->params('synchronize', true);
        $synchronize = (bool) $this->params('synchronize', 1);

        $this->setLoggerStream('php://output');

@@ -242,14 +242,15 @@ class ImportController extends AbstractActionController

    public function importAllConsoleAction()
    {
        $codeStructure = $this->params('etablissement');
        $synchronize = $this->params('synchronize', true); // ex: 'UCN'
        $codeStructure = $this->params('etablissement'); // ex: 'UCN'
        $breakOnServiceNotFound = (bool) $this->params('breakOnServiceNotFound', 1);
        $synchronize = (bool) $this->params('synchronize', 1);

        $etablissement = $this->fetchEtablissementByCodeStructure($codeStructure);

        $this->setLoggerStream('php://output');

        $this->importService->importAll($etablissement, $synchronize);
        $this->importService->importAll($etablissement, $synchronize, $breakOnServiceNotFound);

        echo "Importation de toutes les données de l'établissement '$etablissement' effectuée." . PHP_EOL;
    }
+2 −2
Changes for module/Import/src/Import/Exception/CallException.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ use Zend\Http\Response;

class CallException extends RuntimeException
{
    static public function error($uri, \Exception $previous = null)
    static public function unexpectedError($uri, \Exception $previous = null)
    {
        return new self("Erreur inattendue rencontrée lors de l'envoi de la requête au WS (URI '$uri')", null, $previous);
    }
@@ -37,7 +37,7 @@ class CallException extends RuntimeException

    static public function clientError(ClientException $error)
    {
        return new self("Erreur ClientException rencontrée lors de l'envoi de la requête au WS", null, $error);
        return new self("Erreur ClientException rencontrée lors de l'envoi de la requête au WS", $error->getCode(), $error);
    }

    static public function serverError(ServerException $error)
+5 −2
Changes for module/Import/src/Import/Service/CallService.php: 5 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\ServerException;
use Import\Exception\CallException;
use Import\Exception\ServiceNotFoundException;
use Zend\Http\Response;
use Zend\Log\LoggerAwareTrait;

@@ -80,8 +81,10 @@ class CallService
    {
        try {
            $response = $this->sendRequest($uri);
        } catch (CallException $ce) {
            throw $ce;
        } catch (\Exception $e) {
            throw CallException::error($uri, $e);
            throw CallException::unexpectedError($uri, $e);
        }
        if ($response->getStatusCode() !== Response::STATUS_CODE_200) {
            throw CallException::unexpectedResponse($uri, $response);
@@ -175,7 +178,7 @@ class CallService
        } catch (RequestException $e) {
            throw CallException::networkError($e);
        } catch (GuzzleException $e) {
            throw CallException::error($uri, $e);
            throw CallException::unexpectedError($uri, $e);
        }

        return $response;
Loading