diff --git a/Module.php b/Module.php index e4ce9e99875f496fc7c4ee2b4224600b79e13ad1..99807de4c7bb3232d0121a1bf0650d7c93c298ab 100755 --- a/Module.php +++ b/Module.php @@ -2,16 +2,22 @@ namespace UnicaenIndicateur; +use Laminas\Config\Config; use Laminas\Config\Factory as ConfigFactory; use Laminas\Mvc\ModuleRouteListener; use Laminas\Mvc\MvcEvent; use Laminas\Stdlib\ArrayUtils; use Laminas\Stdlib\Glob; -use Unicaen\Console\Console; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; class Module { - public function onBootstrap(MvcEvent $e) + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function onBootstrap(MvcEvent $e): void { $e->getApplication()->getServiceManager()->get('translator'); $eventManager = $e->getApplication()->getEventManager(); @@ -20,7 +26,7 @@ class Module } - public function getConfig() + public function getConfig(): array|Config { $configInit = [ __DIR__ . '/config/module.config.php' @@ -34,23 +40,15 @@ class Module } - public function getAutoloaderConfig() + public function getAutoloaderConfig(): array { - return array( - 'Laminas\Loader\StandardAutoloader' => array( - 'namespaces' => array( + return [ + 'Laminas\Loader\StandardAutoloader' => [ + 'namespaces' => [ __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, - ), - ), - ); + ], + ], + ]; } -// public function getConsoleUsage(Console $console) -// { -// return [ -// 'indicateur-refresh' => "Rafraichir la liste des indicateurs", -// -// 'indicateur-notifier' => "Notifier les personnes abonnées à des indicateurs avec les données du dernier rafraichissement", -// ]; -// } } diff --git a/composer.json b/composer.json index 7441ad8c3d5486ab443fcf1c2da322ccab5f0fd1..0e9661d8c7899c7d81f989b907337794e0a8e218 100755 --- a/composer.json +++ b/composer.json @@ -8,11 +8,11 @@ } ], "require": { - "unicaen/app": "^4|^5|^6", - "unicaen/utilisateur": "^4|^5|^6", - "unicaen/privilege": "^4|^5|^6", - "unicaen/mail": "^5|^6|^7", - "unicaen/console": "^6" + "laminas/laminas-cli": "*", + "unicaen/app": ">=6.2", + "unicaen/utilisateur": ">=6.2", + "unicaen/privilege": ">=6.2", + "unicaen/mail": ">7" }, "autoload": { "psr-0": [], diff --git a/config/merged/abonnement.config.php b/config/merged/abonnement.config.php index b8763175a91512ff10b3645e56f442dead06120b..c9188fc0eb3ec17c60eeadc80e5829edce814f4f 100644 --- a/config/merged/abonnement.config.php +++ b/config/merged/abonnement.config.php @@ -1,6 +1,7 @@ <?php -use Unicaen\Console\Router\Simple; +use Laminas\Router\Http\Literal; +use Laminas\Router\Http\Segment; use UnicaenIndicateur\Controller\AbonnementController; use UnicaenIndicateur\Controller\AbonnementControllerFactory; use UnicaenIndicateur\Provider\Privilege\AbonnementPrivileges; @@ -8,9 +9,6 @@ use UnicaenIndicateur\Service\Abonnement\AbonnementService; use UnicaenIndicateur\Service\Abonnement\AbonnementServiceFactory; use UnicaenPrivilege\Guard\PrivilegeController; -use Laminas\Router\Http\Literal; -use Laminas\Router\Http\Segment; - return [ 'bjyauthorize' => [ 'guards' => [ @@ -37,12 +35,12 @@ return [ ], ], - 'router' => [ + 'router' => [ 'routes' => [ 'abonnement' => [ - 'type' => Literal::class, + 'type' => Literal::class, 'options' => [ - 'route' => '/abonnement', + 'route' => '/abonnement', 'defaults' => [ 'controller' => AbonnementController::class, ], @@ -50,33 +48,33 @@ return [ 'may_terminate' => false, 'child_routes' => [ 'souscrire' => [ - 'type' => Segment::class, + 'type' => Segment::class, 'options' => [ - 'route' => '/souscrire/:indicateur', + 'route' => '/souscrire/:indicateur', 'defaults' => [ - 'controller' => AbonnementController::class, + /** @see AbonnementController::souscrireAction() */ 'action' => 'souscrire' ], ], 'may_terminate' => true, ], 'resilier' => [ - 'type' => Segment::class, + 'type' => Segment::class, 'options' => [ - 'route' => '/resilier/:indicateur', + 'route' => '/resilier/:indicateur', 'defaults' => [ - 'controller' => AbonnementController::class, + /** @see AbonnementController::resilierAction() */ 'action' => 'resilier' ], ], 'may_terminate' => true, ], 'notifier' => [ - 'type' => Literal::class, + 'type' => Literal::class, 'options' => [ - 'route' => '/notifier', + 'route' => '/notifier', 'defaults' => [ - 'controller' => AbonnementController::class, + /** @see AbonnementController::notifierAction() */ 'action' => 'notifier' ], ], @@ -87,28 +85,12 @@ return [ ], ], - 'console' => [ - 'router' => [ - 'routes' => [ - 'indicateur-notifier' => [ - 'type' => Simple::class, - 'options' => [ - 'route' => 'indicateur-notifier', - 'defaults' => [ - 'controller' => AbonnementController::class, - 'action' => 'notifier-console' - ], - ], - ], - ], - ], - ], 'service_manager' => [ 'factories' => [ AbonnementService::class => AbonnementServiceFactory::class, ], ], - 'controllers' => [ + 'controllers' => [ 'factories' => [ AbonnementController::class => AbonnementControllerFactory::class, ], diff --git a/config/merged/command.config.php b/config/merged/command.config.php new file mode 100644 index 0000000000000000000000000000000000000000..f83085a5c2e55c7e293e83f0b88f03f30cec725b --- /dev/null +++ b/config/merged/command.config.php @@ -0,0 +1,54 @@ +<?php + + +use UnicaenIndicateur\Command\NotifyIndicateurCommand; +use UnicaenIndicateur\Command\NotifyIndicateurCommandFactory; +use UnicaenIndicateur\Command\NotifyIndicateursCommand; +use UnicaenIndicateur\Command\NotifyIndicateursCommandFactory; +use UnicaenIndicateur\Command\RefreshIndicateurCommand; +use UnicaenIndicateur\Command\RefreshIndicateurCommandFactory; +use UnicaenIndicateur\Command\RefreshIndicateursCommand; +use UnicaenIndicateur\Command\RefreshIndicateursCommandFactory; + +return [ + 'bjyauthorize' => [ + 'guards' => [ + ], + ], + + 'laminas-cli' => [ + 'commands' => [ + 'notify-indicateur' => NotifyIndicateurCommand::class, + 'notify-indicateurs' => NotifyIndicateursCommand::class, + 'refresh-indicateur' => RefreshIndicateurCommand::class, + 'refresh-indicateurs' => RefreshIndicateursCommand::class, + ], + ], + + 'controllers' => [ + 'factories' => [ + ], + ], + 'service_manager' => [ + 'factories' => [ + NotifyIndicateurCommand::class => NotifyIndicateurCommandFactory::class, + NotifyIndicateursCommand::class => NotifyIndicateursCommandFactory::class, + RefreshIndicateurCommand::class => RefreshIndicateurCommandFactory::class, + RefreshIndicateursCommand::class => RefreshIndicateursCommandFactory::class, + ], + ], + + 'form_elements' => [ + 'factories' => [ + ], + ], + 'hydrators' => [ + 'factories' => [ + ], + ], + 'view_helpers' => [ + 'invokables' => [ + ], + ], +]; + diff --git a/config/merged/indicateur.config.php b/config/merged/indicateur.config.php index ed2b0e660f835a5b5182c1dc6dc52f2822e7dc52..f443eaa49cc8efe4558d73046a6feaba0e581d26 100644 --- a/config/merged/indicateur.config.php +++ b/config/merged/indicateur.config.php @@ -1,7 +1,5 @@ <?php -use UnicaenIndicateur\Controller\IndicateurConsoleController; -use UnicaenIndicateur\Controller\IndicateurConsoleControllerFactory; use UnicaenIndicateur\Controller\IndicateurController; use UnicaenIndicateur\Controller\IndicateurControllerFactory; use UnicaenIndicateur\Form\Indicateur\IndicateurForm; @@ -14,7 +12,6 @@ use UnicaenIndicateur\Service\Indicateur\IndicateurServiceFactory; use UnicaenIndicateur\View\Helper\DefaultItemViewHelper; use UnicaenIndicateur\View\Helper\IndicateurViewHelperFactory; use UnicaenPrivilege\Guard\PrivilegeController; -use Unicaen\Console\Router\Simple; use Laminas\Router\Http\Literal; use Laminas\Router\Http\Segment; @@ -62,15 +59,7 @@ return [ IndicateurPrivileges::DETRUIRE_INDICATEUR, ], ], - [ - 'controller' => IndicateurConsoleController::class, - 'action' => [ - 'rafraichir-console', - ], - 'roles' => [], - ], ], - ], ], @@ -81,6 +70,7 @@ return [ 'options' => [ 'route' => '/indicateurs', 'defaults' => [ + /** @see IndicateurController::indexAction() */ 'controller' => IndicateurController::class, 'action' => 'index', ], @@ -91,6 +81,10 @@ return [ 'type' => Literal::class, 'options' => [ 'route' => '/indicateur', + 'defaults' => [ + /** @see IndicateurController::indexAction() */ + 'controller' => IndicateurController::class, + ], ], 'may_terminate' => false, 'child_routes' => [ @@ -99,7 +93,7 @@ return [ 'options' => [ 'route' => '/afficher/:indicateur', 'defaults' => [ - 'controller' => IndicateurController::class, + /** @see IndicateurController::afficherAction() */ 'action' => 'afficher', ], ], @@ -110,7 +104,7 @@ return [ 'options' => [ 'route' => '/rafraichir/:indicateur', 'defaults' => [ - 'controller' => IndicateurController::class, + /** @see IndicateurController::rafraichirAction() */ 'action' => 'rafraichir', ], ], @@ -121,7 +115,7 @@ return [ 'options' => [ 'route' => '/regenerer/:indicateur', 'defaults' => [ - 'controller' => IndicateurController::class, + /** @see IndicateurController::regenererAction() */ 'action' => 'regenerer', ], ], @@ -132,7 +126,7 @@ return [ 'options' => [ 'route' => '/creer', 'defaults' => [ - 'controller' => IndicateurController::class, + /** @see IndicateurController::creerAction() */ 'action' => 'creer', ], ], @@ -143,7 +137,7 @@ return [ 'options' => [ 'route' => '/modifier/:indicateur', 'defaults' => [ - 'controller' => IndicateurController::class, + /** @see IndicateurController::modifierAction() */ 'action' => 'modifier', ], ], @@ -154,7 +148,7 @@ return [ 'options' => [ 'route' => '/detruire/:indicateur', 'defaults' => [ - 'controller' => IndicateurController::class, + /** @see IndicateurController::detruireAction() */ 'action' => 'detruire', ], ], @@ -165,7 +159,7 @@ return [ 'options' => [ 'route' => '/exporter/:indicateur', 'defaults' => [ - 'controller' => IndicateurController::class, + /** @see IndicateurController::exporterAction() */ 'action' => 'exporter', ], ], @@ -176,23 +170,6 @@ return [ ], ], - 'console' => [ - 'router' => [ - 'routes' => [ - 'indicateur-refresh' => [ - 'type' => Simple::class, - 'options' => [ - 'route' => 'indicateur-refresh', - 'defaults' => [ - 'controller' => IndicateurConsoleController::class, - 'action' => 'rafraichir-console' - ], - ], - ], - ], - ], - ], - 'service_manager' => [ 'factories' => [ IndicateurService::class => IndicateurServiceFactory::class, @@ -201,7 +178,6 @@ return [ 'controllers' => [ 'factories' => [ IndicateurController::class => IndicateurControllerFactory::class, - IndicateurConsoleController::class => IndicateurConsoleControllerFactory::class, ], ], 'form_elements' => [ diff --git a/src/UnicaenIndicateur/Command/NotifyIndicateurCommand.php b/src/UnicaenIndicateur/Command/NotifyIndicateurCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..948e78129d264d4a2b2a651e2ed32c370a531a44 --- /dev/null +++ b/src/UnicaenIndicateur/Command/NotifyIndicateurCommand.php @@ -0,0 +1,76 @@ +<?php + +namespace UnicaenIndicateur\Command; + +use DateTime; +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 UnicaenIndicateur\Service\Abonnement\AbonnementServiceAwareTrait; +use UnicaenIndicateur\Service\Indicateur\IndicateurServiceAwareTrait; +use UnicaenMail\Service\Mail\MailServiceAwareTrait; + +class NotifyIndicateurCommand extends Command +{ + use AbonnementServiceAwareTrait; + use IndicateurServiceAwareTrait; + use MailServiceAwareTrait; + + protected static $defaultName = 'notify-indicateur'; + + protected function configure(): void + { + $this->setDescription("Notification d'un indicateur aux abonné·es"); + $this->addArgument('code', InputArgument::REQUIRED, "Code de l'indicateur"); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + $code = $input->getArgument('code'); + + $io->title("Notification de l'indicateur [" . $code . "] aux abonné·es"); + + $indicateur = $this->getIndicateurService()->getIndicateurByCode($code); + + if ($indicateur === null) { + $io->error("Aucun indicateur pour ce code [" . $code . "]"); + return self::FAILURE; + } + + $abonnements = $indicateur->getAbonnements(); + $io->text(count($abonnements) . " abonnements"); + + $titre = "Publication de l'indicateur [" . $indicateur->getTitre() . "] (" . (new DateTime())->format("d/m/Y à H:i:s") . ")"; + $result = $this->getIndicateurService()->getIndicateurData($indicateur); + $texte = "<table>"; + $texte .= "<thead>"; + $texte .= "<tr>"; + foreach ($result[0] as $rubrique) $texte .= "<th>" . $rubrique . "</th>"; + $texte .= "</tr>"; + $texte .= "</thead>"; + $texte .= "<tbody>"; + foreach ($result[1] as $item) { + $texte .= "<tr>"; + foreach ($item as $value) $texte .= "<td>" . $value . "</td>"; + $texte .= "</tr>"; + } + $texte .= "</tbody>"; + $texte .= "</table>"; + + foreach ($abonnements as $abonnement) { + $adresse = $abonnement->getUser()->getEmail(); + $mail = $this->getMailService()->sendMail($adresse, $titre, $texte); + $mail->setMotsClefs([$indicateur->generateTag()]); + $this->getMailService()->update($mail); + $abonnement->setDernierEnvoi(new DateTime()); + $this->getAbonnementService()->update($abonnement); + } + + + $io->success("Notifications des abonnements de l'indicateur [" . $code . "] effectuées"); + return self::SUCCESS; + } +} \ No newline at end of file diff --git a/src/UnicaenIndicateur/Command/NotifyIndicateurCommandFactory.php b/src/UnicaenIndicateur/Command/NotifyIndicateurCommandFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..8382490b4e493ebfd0ef6a2e6c175eb401a4c8ce --- /dev/null +++ b/src/UnicaenIndicateur/Command/NotifyIndicateurCommandFactory.php @@ -0,0 +1,36 @@ +<?php + +namespace UnicaenIndicateur\Command; + +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\ContainerInterface; +use Psr\Container\NotFoundExceptionInterface; +use Symfony\Component\Console\Command\Command; +use UnicaenIndicateur\Service\Abonnement\AbonnementService; +use UnicaenIndicateur\Service\Indicateur\IndicateurService; +use UnicaenMail\Service\Mail\MailService; + +class NotifyIndicateurCommandFactory extends Command +{ + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function __invoke(ContainerInterface $container): NotifyIndicateurCommand + { + /** + * @see AbonnementService $abonnementService + * @see IndicateurService $indicateurService + * @see MailService $mailService + */ + $abonnementService = $container->get(AbonnementService::class); + $indcateurService = $container->get(IndicateurService::class); + $mailService = $container->get(MailService::class); + + $command = new NotifyIndicateurCommand(); + $command->setAbonnementService($abonnementService); + $command->setIndicateurService($indcateurService); + $command->setMailService($mailService); + return $command; + } +} diff --git a/src/UnicaenIndicateur/Command/NotifyIndicateursCommand.php b/src/UnicaenIndicateur/Command/NotifyIndicateursCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..96089733bd5b9cbf6345744996f8f4f0d4ae9ed0 --- /dev/null +++ b/src/UnicaenIndicateur/Command/NotifyIndicateursCommand.php @@ -0,0 +1,75 @@ +<?php + +namespace UnicaenIndicateur\Command; + +use DateTime; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; +use UnicaenIndicateur\Service\Abonnement\AbonnementServiceAwareTrait; +use UnicaenIndicateur\Service\Indicateur\IndicateurServiceAwareTrait; +use UnicaenMail\Service\Mail\MailServiceAwareTrait; + +class NotifyIndicateursCommand extends Command +{ + use AbonnementServiceAwareTrait; + use IndicateurServiceAwareTrait; + use MailServiceAwareTrait; + + protected static $defaultName = 'notify-indicateurs'; + + protected function configure(): void + { + $this->setDescription("Notification des indicateurs aux abonné·es"); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + + $io->title("Notification des indicateurs aux abonné·es"); + + $indicateurs = $this->getIndicateurService()->getIndicateurs(); + $nbIndicateurs = count($indicateurs); + $io->text($nbIndicateurs . " indicateurs à notifier"); + + $position = 1; + foreach ($indicateurs as $indicateur) { + $io->text($position ."/". $nbIndicateurs. " : indicateur [".$indicateur->getCode()."]"); + + $abonnements = $indicateur->getAbonnements(); + $io->text($position ."/". $nbIndicateurs. " : ".count($abonnements)." abonnements pour cet indicateur" ); + + $titre = "Publication de l'indicateur [".$indicateur->getTitre()."] (". (new DateTime())->format("d/m/Y à H:i:s").")"; + $result = $this->getIndicateurService()->getIndicateurData($indicateur); + $texte = "<table>"; + $texte .= "<thead>"; + $texte .= "<tr>"; + foreach ($result[0] as $rubrique) $texte .= "<th>" . $rubrique . "</th>"; + $texte .= "</tr>"; + $texte .= "</thead>"; + $texte .= "<tbody>"; + foreach ($result[1] as $item) { + $texte .="<tr>"; + foreach ($item as $value) $texte .="<td>". $value ."</td>"; + $texte .="</tr>"; + } + $texte .= "</tbody>"; + $texte .= "</table>"; + + foreach ($abonnements as $abonnement) { + $adresse = $abonnement->getUser()->getEmail(); + $mail = $this->getMailService()->sendMail($adresse, $titre, $texte); + $mail->setMotsClefs([$indicateur->generateTag()]); + $this->getMailService()->update($mail); + $abonnement->setDernierEnvoi(new DateTime()); + $this->getAbonnementService()->update($abonnement); + } + $position++; + } + + $io->success("Notifications des abonnements des indicateurs effectuées"); + return self::SUCCESS; + } +} \ No newline at end of file diff --git a/src/UnicaenIndicateur/Command/NotifyIndicateursCommandFactory.php b/src/UnicaenIndicateur/Command/NotifyIndicateursCommandFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..4fe11f0b3404f029259c0b5ac2d2c70b2debcab5 --- /dev/null +++ b/src/UnicaenIndicateur/Command/NotifyIndicateursCommandFactory.php @@ -0,0 +1,36 @@ +<?php + +namespace UnicaenIndicateur\Command; + +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\ContainerInterface; +use Psr\Container\NotFoundExceptionInterface; +use Symfony\Component\Console\Command\Command; +use UnicaenIndicateur\Service\Abonnement\AbonnementService; +use UnicaenIndicateur\Service\Indicateur\IndicateurService; +use UnicaenMail\Service\Mail\MailService; + +class NotifyIndicateursCommandFactory extends Command +{ + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function __invoke(ContainerInterface $container): NotifyIndicateursCommand + { + /** + * @see AbonnementService $abonnementService + * @see IndicateurService $indicateurService + * @see MailService $mailService + */ + $abonnementService = $container->get(AbonnementService::class); + $indcateurService = $container->get(IndicateurService::class); + $mailService = $container->get(MailService::class); + + $command = new NotifyIndicateursCommand(); + $command->setAbonnementService($abonnementService); + $command->setIndicateurService($indcateurService); + $command->setMailService($mailService); + return $command; + } +} diff --git a/src/UnicaenIndicateur/Command/RefreshIndicateurCommand.php b/src/UnicaenIndicateur/Command/RefreshIndicateurCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..4e868a4e48b372f6dc19d12bd9d48d490694a08d --- /dev/null +++ b/src/UnicaenIndicateur/Command/RefreshIndicateurCommand.php @@ -0,0 +1,43 @@ +<?php + +namespace UnicaenIndicateur\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 UnicaenIndicateur\Service\Indicateur\IndicateurServiceAwareTrait; + +class RefreshIndicateurCommand extends Command +{ + use IndicateurServiceAwareTrait; + + protected static $defaultName = 'refresh-indicateur'; + + protected function configure(): void + { + $this->setDescription("Rafraichissement d'un indicateur (dont le code est passé en argument)"); + $this->addArgument('code', InputArgument::REQUIRED, "Code de l'indicateur"); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + $code = $input->getArgument('code'); + + $io->title("Rafraichissement de l'indicateur [" . $code . "]"); + + $indicateur = $this->getIndicateurService()->getIndicateurByCode($code); + + if ($indicateur === null) { + $io->error("Aucun indicateur pour ce code [" . $code . "]"); + return self::FAILURE; + } + + $this->getIndicateurService()->refresh($indicateur); + + $io->success("Rafraichissements de l'indicateur effectué"); + return self::SUCCESS; + } +} \ No newline at end of file diff --git a/src/UnicaenIndicateur/Command/RefreshIndicateurCommandFactory.php b/src/UnicaenIndicateur/Command/RefreshIndicateurCommandFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..46965b170623a101b0ed01b2db7bd9173136f556 --- /dev/null +++ b/src/UnicaenIndicateur/Command/RefreshIndicateurCommandFactory.php @@ -0,0 +1,28 @@ +<?php + +namespace UnicaenIndicateur\Command; + +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\ContainerInterface; +use Psr\Container\NotFoundExceptionInterface; +use Symfony\Component\Console\Command\Command; +use UnicaenIndicateur\Service\Indicateur\IndicateurService; + +class RefreshIndicateurCommandFactory extends Command +{ + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function __invoke(ContainerInterface $container): RefreshIndicateurCommand + { + /** + * @see IndicateurService $indicateurService + */ + $indcateurService = $container->get(IndicateurService::class); + + $command = new RefreshIndicateurCommand(); + $command->setIndicateurService($indcateurService); + return $command; + } +} diff --git a/src/UnicaenIndicateur/Command/RefreshIndicateursCommand.php b/src/UnicaenIndicateur/Command/RefreshIndicateursCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..08dfce65cf2c38d462fc2e96583935934a81ea8c --- /dev/null +++ b/src/UnicaenIndicateur/Command/RefreshIndicateursCommand.php @@ -0,0 +1,42 @@ +<?php + +namespace UnicaenIndicateur\Command; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; +use UnicaenIndicateur\Service\Indicateur\IndicateurServiceAwareTrait; + +class RefreshIndicateursCommand extends Command +{ + use IndicateurServiceAwareTrait; + + protected static $defaultName = 'refresh-indicateurs'; + + protected function configure(): void + { + $this->setDescription("Rafraichissement des indicateurs"); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + + $io->title("Rafraichissement des indicateurs"); + + $indicateurs = $this->getIndicateurService()->getIndicateurs(); + $nbIndicateurs = count($indicateurs); + $io->text($nbIndicateurs . " indicateurs à rafraichir"); + + $position = 1; + foreach ($indicateurs as $indicateur) { + $io->text($position . "/" . $nbIndicateurs . " : indicateur [" . $indicateur->getCode() . "]"); + $this->getIndicateurService()->refresh($indicateur); + $position++; + } + + $io->success("Rafraichissements des indicateurs effectués"); + return self::SUCCESS; + } +} \ No newline at end of file diff --git a/src/UnicaenIndicateur/Command/RefreshIndicateursCommandFactory.php b/src/UnicaenIndicateur/Command/RefreshIndicateursCommandFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..7e0be8359366efad541b0364fcf149f27ea3f7da --- /dev/null +++ b/src/UnicaenIndicateur/Command/RefreshIndicateursCommandFactory.php @@ -0,0 +1,28 @@ +<?php + +namespace UnicaenIndicateur\Command; + +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\ContainerInterface; +use Psr\Container\NotFoundExceptionInterface; +use Symfony\Component\Console\Command\Command; +use UnicaenIndicateur\Service\Indicateur\IndicateurService; + +class RefreshIndicateursCommandFactory extends Command +{ + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function __invoke(ContainerInterface $container): RefreshIndicateursCommand + { + /** + * @see IndicateurService $indicateurService + */ + $indcateurService = $container->get(IndicateurService::class); + + $command = new RefreshIndicateursCommand(); + $command->setIndicateurService($indcateurService); + return $command; + } +} diff --git a/src/UnicaenIndicateur/Controller/AbonnementController.php b/src/UnicaenIndicateur/Controller/AbonnementController.php index 4a53f7f20a14d19f3d20f1c4226abdbc919c78e1..c4435238d8221b887bfeab1c160ae5e2fd7a9155 100644 --- a/src/UnicaenIndicateur/Controller/AbonnementController.php +++ b/src/UnicaenIndicateur/Controller/AbonnementController.php @@ -3,12 +3,12 @@ namespace UnicaenIndicateur\Controller; use Laminas\Http\Response; +use Laminas\Mvc\Controller\AbstractActionController; +use Laminas\View\Model\ViewModel; use UnicaenIndicateur\Entity\Db\Abonnement; use UnicaenIndicateur\Service\Abonnement\AbonnementServiceAwareTrait; use UnicaenIndicateur\Service\Indicateur\IndicateurServiceAwareTrait; use UnicaenUtilisateur\Service\User\UserServiceAwareTrait; -use Laminas\Mvc\Controller\AbstractActionController; -use Laminas\View\Model\ViewModel; class AbonnementController extends AbstractActionController { use AbonnementServiceAwareTrait; @@ -57,8 +57,4 @@ class AbonnementController extends AbstractActionController { return $this->redirect()->toRoute('indicateurs', [], [], true); } - public function notifierConsoleAction() : void - { - $this->getAbonnementService()->notifyAbonnements(); - } } \ No newline at end of file diff --git a/src/UnicaenIndicateur/Controller/AbonnementControllerFactory.php b/src/UnicaenIndicateur/Controller/AbonnementControllerFactory.php index 3797e5fcbebd2396bce3baaa334264c0f0f845dc..bcb5b8d61ea73d2808cca6baf66f443dc5a85418 100644 --- a/src/UnicaenIndicateur/Controller/AbonnementControllerFactory.php +++ b/src/UnicaenIndicateur/Controller/AbonnementControllerFactory.php @@ -2,14 +2,17 @@ namespace UnicaenIndicateur\Controller; +use Interop\Container\ContainerInterface; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use UnicaenIndicateur\Service\Abonnement\AbonnementService; use UnicaenIndicateur\Service\Indicateur\IndicateurService; -use Interop\Container\ContainerInterface; -use UnicaenUtilisateur\Service\User\UserService;; +use UnicaenUtilisateur\Service\User\UserService; + +; -class AbonnementControllerFactory { +class AbonnementControllerFactory +{ /** * @param ContainerInterface $container diff --git a/src/UnicaenIndicateur/Controller/IndicateurConsoleController.php b/src/UnicaenIndicateur/Controller/IndicateurConsoleController.php deleted file mode 100644 index 8e68db01558b8d8cb0945f1e06494f988bea5815..0000000000000000000000000000000000000000 --- a/src/UnicaenIndicateur/Controller/IndicateurConsoleController.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php - -namespace UnicaenIndicateur\Controller; - -use Unicaen\Console\Controller\AbstractConsoleController; -use UnicaenIndicateur\Service\Indicateur\IndicateurServiceAwareTrait; - -class IndicateurConsoleController extends AbstractConsoleController -{ - use IndicateurServiceAwareTrait; - - public function rafraichirConsoleAction(): void - { - $indicateurs = $this->getIndicateurService()->getIndicateurs(); - foreach ($indicateurs as $indicateur) { - $this->getIndicateurService()->refresh($indicateur); - } - } -} \ No newline at end of file diff --git a/src/UnicaenIndicateur/Controller/IndicateurConsoleControllerFactory.php b/src/UnicaenIndicateur/Controller/IndicateurConsoleControllerFactory.php deleted file mode 100644 index 49b71d523e4121dd17f269dcfe917f12cea0e53a..0000000000000000000000000000000000000000 --- a/src/UnicaenIndicateur/Controller/IndicateurConsoleControllerFactory.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -namespace UnicaenIndicateur\Controller; - -use Psr\Container\ContainerInterface; -use Unicaen\Console\Controller\AbstractConsoleController; -use UnicaenIndicateur\Service\Indicateur\IndicateurService; -use UnicaenIndicateur\Service\Indicateur\IndicateurServiceAwareTrait; - -class IndicateurConsoleControllerFactory -{ - - public function __invoke(ContainerInterface $container): IndicateurConsoleController - { - /** - * @var IndicateurService $indicateurService - */ - $indicateurService = $container->get(IndicateurService::class); - - $controller = new IndicateurConsoleController(); - $controller->setIndicateurService($indicateurService); - return $controller; - } -} \ No newline at end of file diff --git a/src/UnicaenIndicateur/Controller/IndicateurController.php b/src/UnicaenIndicateur/Controller/IndicateurController.php index bc407ade4bffb0aac85ddfcb10abf711fa44c76e..e929f87b0cb439363729da56db0e8bce13de0018 100644 --- a/src/UnicaenIndicateur/Controller/IndicateurController.php +++ b/src/UnicaenIndicateur/Controller/IndicateurController.php @@ -222,11 +222,4 @@ class IndicateurController extends AbstractActionController { } } - public function rafraichirConsoleAction() : void - { - $indicateurs = $this->getIndicateurService()->getIndicateurs(); - foreach ($indicateurs as $indicateur) { - $this->getIndicateurService()->refresh($indicateur); - } - } } \ No newline at end of file diff --git a/src/UnicaenIndicateur/Service/Indicateur/IndicateurService.php b/src/UnicaenIndicateur/Service/Indicateur/IndicateurService.php index e96c0bb6fd77a6e0392fb3fa1d832d65f6be9a46..08d3cf2cdc898a3ed181f3510a5e7eaea2da792a 100644 --- a/src/UnicaenIndicateur/Service/Indicateur/IndicateurService.php +++ b/src/UnicaenIndicateur/Service/Indicateur/IndicateurService.php @@ -230,7 +230,7 @@ class IndicateurService return $this->getIndicateur($id); } - public function getIndicateurByCode(string $code): ?Indicateur + public function getIndicateurByCode(string $code)//: ?Indicateur { $qb = $this->createQueryBuilder() ->andWhere('indicateur.code = :code')->setParameter('code', $code);