Commit c8f8121d authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Utilisation de command plutôt que de route console

parent 855c7fb8
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -8,8 +8,8 @@
        }
    ],
    "require": {
        "unicaen/privilege": "^6",
        "unicaen/console": "^6"
        "laminas/laminas-cli": "*",
        "unicaen/privilege": ">=6.2"
    },
    "autoload": {
        "psr-0": [],
+42 −0
Original line number Diff line number Diff line
<?php


use UnicaenSynchro\Command\SynchroniserCommand;
use UnicaenSynchro\Command\SynchroniserCommandFactory;

return [
    'bjyauthorize' => [
        'guards' => [
        ],
    ],

    'laminas-cli' => [
        'commands' => [
            'synchroniser' => SynchroniserCommand::class,
        ],
    ],

    'controllers' => [
        'factories' => [
        ],
    ],
    'service_manager' => [
        'factories' => [
            SynchroniserCommand::class => SynchroniserCommandFactory::class,
        ],
    ],

    'form_elements' => [
        'factories' => [
        ],
    ],
    'hydrators' => [
        'factories' => [
        ],
    ],
    'view_helpers' => [
        'invokables' => [
        ],
    ],
];
+0 −53
Original line number Diff line number Diff line
@@ -2,62 +2,10 @@

namespace UnicaenSynchro;

use Unicaen\Console\Router\Simple;
use UnicaenPrivilege\Guard\PrivilegeController;
use UnicaenSynchro\Controller\SynchronisationConsoleController;
use UnicaenSynchro\Controller\SynchronisationConsoleControllerFactory;
use UnicaenSynchro\Service\Synchronisation\SynchronisationService;
use UnicaenSynchro\Service\Synchronisation\SynchronisationServiceFactory;

return [
    'bjyauthorize' => [
        'guards' => [
            PrivilegeController::class => [
                [
                    'controller' => SynchronisationConsoleController::class,
                    'action' => [
                        'synchroniser-all',
                        'synchroniser',
                    ],
                    'roles' => [],
                ],
            ],
        ],
    ],

    'console' => [
        'router' => [
            'routes' => [
                'synchroniser-all' => [
                    'type' => Simple::class,
                    'options' => [
                        'route' => 'synchroniser-all',
                        'defaults' => [
                            /** @see SynchronisationConsoleController::synchroniserAllAction() */
                            'controller' => SynchronisationConsoleController::class,
                            'action' => 'synchroniser-all'
                        ],
                    ],
                ],
                'synchroniser' => [
                    'type' => Simple::class,
                    'options' => [
                        'route' => 'synchroniser [--name=]',
                        'defaults' => [
                            /** @see SynchronisationConsoleController::synchroniserAction() */
                            'controller' => SynchronisationConsoleController::class,
                            'action' => 'synchroniser'
                        ],
                    ],
                ],
            ],
        ],
    ],

    'router'          => [
        'routes' => [
        ],
    ],

    'service_manager' => [
        'factories' => [
@@ -66,7 +14,6 @@ return [
    ],
    'controllers' => [
        'factories' => [
            SynchronisationConsoleController::class => SynchronisationConsoleControllerFactory::class
        ],
    ],
    'form_elements' => [
+0 −1
Original line number Diff line number Diff line
@@ -67,7 +67,6 @@ Aucune pour le moment, car aucun log n'est enregistré !
Dépendances extérieures
======================

- **Unicaen\Console** : Utilisation de la console qui n'est plus maintenant depuis le passage à PHP 8.
- **UnicaenPrivilege** : Déclaration des gardes pour les routes (pas sur que cela soit nécessaire).


+53 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenSynchro\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use UnicaenSynchro\Service\Synchronisation\SynchronisationServiceAwareTrait;

class SynchroniserCommand extends Command
{
    use SynchronisationServiceAwareTrait;


    private array $configs;

    public function setConfigs(array $configs): void
    {
        $this->configs = $configs;
    }

    protected static $defaultName = 'synchroniser';

    protected function configure(): void
    {
        $this->setDescription("Synchronisation de données sources");
        $this->addArgument('name', InputArgument::OPTIONAL, "Nom de la synchronisation");
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output);
        $name = $input->getArgument('name');


        if ($name !== null) {
            $io->title("Execution de la synchronisation [" . $name . "]");
            $this->getSynchronisationService()->synchronise($name);
        } else {
            $io->title("Synchronisation de données sources");
            $jobs = $this->configs;
            foreach ($jobs as $name => $job) {
                echo $this->getSynchronisationService()->synchronise($name);
            }
        }


        $io->success("Synchronisation·s effectuée·s");
        return self::SUCCESS;
    }
}
 No newline at end of file
Loading