From fa5ac4f541a2b954780f7340cbbf529add52e93c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Monterisi?= Date: Thu, 2 Jun 2022 22:02:51 +0200 Subject: [PATCH 1/4] fop:log:clean - start --- config/services.yml | 3 +++ src/Commands/Log/LogClean.php | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/Commands/Log/LogClean.php diff --git a/config/services.yml b/config/services.yml index 403e9fc1..674b482b 100644 --- a/config/services.yml +++ b/config/services.yml @@ -141,6 +141,9 @@ services: class: FOP\Console\Commands\About\AboutVersion tags: [ console.command ] + fop.console.log.clean.command: + class: FOP\Console\Commands\Log\LogClean + tags: [ console.command ] imports: - { resource: overriders.yml } diff --git a/src/Commands/Log/LogClean.php b/src/Commands/Log/LogClean.php new file mode 100644 index 00000000..3a971c4c --- /dev/null +++ b/src/Commands/Log/LogClean.php @@ -0,0 +1,43 @@ + + * @copyright since 2020 Friends of Presta + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License ("AFL") v. 3.0 + * + */ + +declare(strict_types=1); + +namespace FOP\Console\Commands\Log; + +use FOP\Console\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +final class LogClean extends Command +{ + protected function configure(): void + { + $this->setName('fop:log:clean') + ->setDescription('Clears the PrestaShop (legacy) logs.'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $this->io->comment('not implemented'); + + return 7; + } +} From a41b5173a903c44ab10b83b38769034957d1a645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Monterisi?= Date: Fri, 3 Jun 2022 22:33:57 +0200 Subject: [PATCH 2/4] refactored yaml files - get ready for cqrs --- config/console_commands.yml | 105 +++++++++++++++++++++++++++ config/services.yml | 137 +----------------------------------- 2 files changed, 106 insertions(+), 136 deletions(-) create mode 100644 config/console_commands.yml diff --git a/config/console_commands.yml b/config/console_commands.yml new file mode 100644 index 00000000..d6aadaa7 --- /dev/null +++ b/config/console_commands.yml @@ -0,0 +1,105 @@ +services: + _defaults: + tags: [ console.command ] + + fop.console.cache.clear.command: + class: FOP\Console\Commands\Cache\CacheClear + + fop.console.category.clean.command: + class: FOP\Console\Commands\Category\CategoryClean + + fop.console.category.products_count.command: + class: FOP\Console\Commands\Category\CategoryProductsCount + + fop.console.configuration.export.command: + class: FOP\Console\Commands\Configuration\ConfigurationExport + + fop.console.configuration.import.command: + class: FOP\Console\Commands\Configuration\ConfigurationImport + + fop.console.container.check.command: + class: FOP\Console\Commands\Container\ContainerCheck + + fop.console.employee.list.command: + class: FOP\Console\Commands\Employee\EmployeeList + + fop.console.employee.change_password.command: + class: FOP\Console\Commands\Employee\EmployeeChangePassword + + fop.console.environment.debug.command: + class: FOP\Console\Commands\Environment\EnvironmentDebug + + fop.console.environment.get_parameters.command: + class: FOP\Console\Commands\Environment\EnvironmentGetParameters + + fop.console.environment.setup_dev.command: + class: FOP\Console\Commands\Environment\EnvironmentSetupDev + + fop.console.export.data.command: + class: FOP\Console\Commands\Export\ExportData + + fop.console.generate.htaccess.command: + class: FOP\Console\Commands\Generate\GenerateHtaccess + + fop.console.generate.robots.command: + class: FOP\Console\Commands\Generate\GenerateRobots + + fop.console.group.transfer_customers.command: + class: FOP\Console\Commands\Group\GroupTransferCustomers + + fop.console.hook.add.command: + class: FOP\Console\Commands\Hook\HookAdd + + fop.console.image.generate_products.command: + class: FOP\Console\Commands\Image\ImageGenerateProducts + + fop.console.image.generate_categories.command: + class: FOP\Console\Commands\Image\ImageGenerateCategories + + fop.console.image.generate_manufacturers.command: + class: FOP\Console\Commands\Image\ImageGenerateManufacturers + + fop.console.image.generate_suppliers.command: + class: FOP\Console\Commands\Image\ImageGenerateSuppliers + + fop.console.image.generate_stores.command: + class: FOP\Console\Commands\Image\ImageGenerateStores + + fop.console.module.unhook.command: + class: FOP\Console\Commands\Module\ModuleUnhook + + fop.console.module.hook.command: + class: FOP\Console\Commands\Module\ModuleHook + + fop.console.module.hooks.command: + class: FOP\Console\Commands\Module\ModuleHooks + + fop.console.module.rename.command: + class: FOP\Console\Commands\Module\ModuleRename + + fop.console.module.non_essential.command: + class: FOP\Console\Commands\Module\ModuleNonEssential + + fop.console.module.generate.command: + class: FOP\Console\Commands\Module\ModuleGenerate + + fop.console.override.make.command: + class: FOP\Console\Commands\Override\OverrideMake + + fop.console.product.latest.command: + class: FOP\Console\Commands\Product\ProductLatest + + fop.console.shop.status.command: + class: FOP\Console\Commands\Shop\ShopStatus + + fop.console.shop.maintenance.command: + class: FOP\Console\Commands\Shop\ShopMaintenance + + fop.console.theme.reset_layout.command: + class: FOP\Console\Commands\Theme\ThemeResetLayout + + fop.console.about.version.command: + class: FOP\Console\Commands\About\AboutVersion + + fop.console.log.clean.command: + class: FOP\Console\Commands\Log\LogClean diff --git a/config/services.yml b/config/services.yml index 674b482b..9ab7c66f 100644 --- a/config/services.yml +++ b/config/services.yml @@ -9,141 +9,6 @@ services: - "@prestashop.adapter.shop.context" - "%kernel.root_dir%" - fop.console.cache.clear.command: - class: FOP\Console\Commands\Cache\CacheClear - tags: [ console.command ] - - fop.console.category.clean.command: - class: FOP\Console\Commands\Category\CategoryClean - tags: [ console.command ] - - fop.console.category.products_count.command: - class: FOP\Console\Commands\Category\CategoryProductsCount - tags: [ console.command ] - - fop.console.configuration.export.command: - class: FOP\Console\Commands\Configuration\ConfigurationExport - tags: [ console.command ] - - fop.console.configuration.import.command: - class: FOP\Console\Commands\Configuration\ConfigurationImport - tags: [ console.command ] - - fop.console.container.check.command: - class: FOP\Console\Commands\Container\ContainerCheck - tags: [ console.command ] - - fop.console.employee.list.command: - class: FOP\Console\Commands\Employee\EmployeeList - tags: [ console.command ] - - fop.console.employee.change_password.command: - class: FOP\Console\Commands\Employee\EmployeeChangePassword - tags: [ console.command ] - - fop.console.environment.debug.command: - class: FOP\Console\Commands\Environment\EnvironmentDebug - tags: [ console.command ] - - fop.console.environment.get_parameters.command: - class: FOP\Console\Commands\Environment\EnvironmentGetParameters - tags: [ console.command ] - - fop.console.environment.setup_dev.command: - class: FOP\Console\Commands\Environment\EnvironmentSetupDev - tags: [ console.command ] - - fop.console.export.data.command: - class: FOP\Console\Commands\Export\ExportData - tags: [ console.command ] - - fop.console.generate.htaccess.command: - class: FOP\Console\Commands\Generate\GenerateHtaccess - tags: [ console.command ] - - fop.console.generate.robots.command: - class: FOP\Console\Commands\Generate\GenerateRobots - tags: [ console.command ] - - fop.console.group.transfer_customers.command: - class: FOP\Console\Commands\Group\GroupTransferCustomers - tags: [ console.command ] - - fop.console.hook.add.command: - class: FOP\Console\Commands\Hook\HookAdd - tags: [ console.command ] - - fop.console.image.generate_products.command: - class: FOP\Console\Commands\Image\ImageGenerateProducts - tags: [ console.command ] - - fop.console.image.generate_categories.command: - class: FOP\Console\Commands\Image\ImageGenerateCategories - tags: [ console.command ] - - fop.console.image.generate_manufacturers.command: - class: FOP\Console\Commands\Image\ImageGenerateManufacturers - tags: [ console.command ] - - fop.console.image.generate_suppliers.command: - class: FOP\Console\Commands\Image\ImageGenerateSuppliers - tags: [ console.command ] - - fop.console.image.generate_stores.command: - class: FOP\Console\Commands\Image\ImageGenerateStores - tags: [ console.command ] - - fop.console.module.unhook.command: - class: FOP\Console\Commands\Module\ModuleUnhook - tags: [ console.command ] - - fop.console.module.hook.command: - class: FOP\Console\Commands\Module\ModuleHook - tags: [ console.command ] - - fop.console.module.hooks.command: - class: FOP\Console\Commands\Module\ModuleHooks - tags: [ console.command ] - - fop.console.module.rename.command: - class: FOP\Console\Commands\Module\ModuleRename - tags: [ console.command ] - - fop.console.module.non_essential.command: - class: FOP\Console\Commands\Module\ModuleNonEssential - tags: [ console.command ] - - fop.console.module.generate.command: - class: FOP\Console\Commands\Module\ModuleGenerate - tags: [ console.command ] - - fop.console.override.make.command: - class: FOP\Console\Commands\Override\OverrideMake - tags: [ console.command ] - - fop.console.product.latest.command: - class: FOP\Console\Commands\Product\ProductLatest - tags: [ console.command ] - - fop.console.shop.status.command: - class: FOP\Console\Commands\Shop\ShopStatus - tags: [ console.command ] - - fop.console.shop.maintenance.command: - class: FOP\Console\Commands\Shop\ShopMaintenance - tags: [ console.command ] - - fop.console.theme.reset_layout.command: - class: FOP\Console\Commands\Theme\ThemeResetLayout - tags: [ console.command ] - - fop.console.about.version.command: - class: FOP\Console\Commands\About\AboutVersion - tags: [ console.command ] - - fop.console.log.clean.command: - class: FOP\Console\Commands\Log\LogClean - tags: [ console.command ] - imports: + - { resource: console_commands.yml } - { resource: overriders.yml } From 8f671fa0eb662f7ad783d01180324553fb55d79c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Monterisi?= Date: Fri, 3 Jun 2022 23:05:15 +0200 Subject: [PATCH 3/4] refactored yaml files - fix PhpStanNamesConsistencyService --- .devtools/fop_names_rules.neon | 2 +- tests/Validator/PhpStanNamesConsistencyService.php | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.devtools/fop_names_rules.neon b/.devtools/fop_names_rules.neon index cd89a3b0..5755cc49 100755 --- a/.devtools/fop_names_rules.neon +++ b/.devtools/fop_names_rules.neon @@ -8,4 +8,4 @@ services: - class: FOP\Console\Tests\Validator\PhpStanNamesConsistencyService arguments: - yamlServicesFilePath: '%currentWorkingDirectory%/config/services.yml' + yamlServicesFilePath: '%currentWorkingDirectory%/config/console_commands.yml' diff --git a/tests/Validator/PhpStanNamesConsistencyService.php b/tests/Validator/PhpStanNamesConsistencyService.php index a2a7cf0b..9fd2c392 100644 --- a/tests/Validator/PhpStanNamesConsistencyService.php +++ b/tests/Validator/PhpStanNamesConsistencyService.php @@ -61,7 +61,8 @@ private function getServiceNameForFQCN(string $fullyQualifiedClassName): string $services = $this->getServicesNames(); if (!isset($services[$fullyQualifiedClassName])) { // dump($fullyQualifiedClassName, $services); - throw new Exception('Service not found in service.yaml.' . PHP_EOL . 'Maybe unsupported syntax.' . PHP_EOL . 'Use this form :' . PHP_EOL . '' . PHP_EOL . ' fop.console.domain.action.command:' . PHP_EOL . ' class: FOP\\Console\\Commands\\Domain\\DomainAction' . PHP_EOL . ' tags: [ console.command ]'); + throw new Exception('Service not found for class ' . $fullyQualifiedClassName . ' in ' . $this->yamlServicesFilePath . PHP_EOL . 'Maybe unsupported syntax.' . PHP_EOL . 'Use this form :' . PHP_EOL . PHP_EOL . ' + fop.console.domain.action.command:' . PHP_EOL . ' class: FOP\\Console\\Commands\\Domain\\DomainAction' . PHP_EOL . ' tags: [ console.command ]'); } return $services[$fullyQualifiedClassName] ?? ''; @@ -90,10 +91,12 @@ private function getServicesNames(): array if (!isset($yaml['services'])) { throw new RuntimeException('Unexpected Symfony config file content : "services" section not found.'); } - $filterServicesWithConsoleTag = static function (array $service) { - return isset($service['tags']) && in_array('console.command', $service['tags']); // direct form - }; - $commands = array_filter($yaml['services'], $filterServicesWithConsoleTag); + // filtering not needed anymore, the commands declarations are isolated in a separated file. +// $filterServicesWithConsoleTag = static function (array $service) { +// return isset($service['tags']) && in_array('console.command', $service['tags']); // direct form +// }; +// $commands = array_filter($yaml['services'], $filterServicesWithConsoleTag); + $commands = array_filter($yaml['services']); $servicesWithServiceField = array_map( static function (string $service, array $classDefinition) { return [ From c555d800e132865954fd9c9dacb348988ced2548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Monterisi?= Date: Fri, 3 Jun 2022 23:07:56 +0200 Subject: [PATCH 4/4] architecture for (CQRS) command. --- config/bus.yml | 8 +++++ config/services.yml | 1 + .../Log/CommandHandler/CleanLogHandler.php | 34 +++++++++++++++++++ src/Commands/Log/LogClean.php | 19 +++++++++-- .../Domain/Log/Command/CleanLogCommand.php | 31 +++++++++++++++++ .../CleanLogHandlerInterface.php | 28 +++++++++++++++ 6 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 config/bus.yml create mode 100644 src/Adapter/Log/CommandHandler/CleanLogHandler.php create mode 100644 src/Core/Domain/Log/Command/CleanLogCommand.php create mode 100644 src/Core/Domain/Log/CommandHandler/CleanLogHandlerInterface.php diff --git a/config/bus.yml b/config/bus.yml new file mode 100644 index 00000000..ca44f11e --- /dev/null +++ b/config/bus.yml @@ -0,0 +1,8 @@ +services: + + prestashop.adapter.category.command_handler.add_root_category_handler: + class: FOP\Console\Adapter\Log\CommandHandler\CleanLogHandler + public: true + tags: + - name: tactician.handler + command: FOP\Console\Core\Domain\Log\Command\CleanLogCommand diff --git a/config/services.yml b/config/services.yml index 9ab7c66f..28a2ab8c 100644 --- a/config/services.yml +++ b/config/services.yml @@ -12,3 +12,4 @@ services: imports: - { resource: console_commands.yml } - { resource: overriders.yml } + - { resource: bus.yml } diff --git a/src/Adapter/Log/CommandHandler/CleanLogHandler.php b/src/Adapter/Log/CommandHandler/CleanLogHandler.php new file mode 100644 index 00000000..476c84e0 --- /dev/null +++ b/src/Adapter/Log/CommandHandler/CleanLogHandler.php @@ -0,0 +1,34 @@ + + * @copyright since 2020 Friends of Presta + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License ("AFL") v. 3.0 + * + */ + +declare(strict_types=1); + +namespace FOP\Console\Adapter\Log\CommandHandler; + +use FOP\Console\Core\Domain\Log\Command\CleanLogCommand; +use FOP\Console\Core\Domain\Log\CommandHandler\CleanLogHandlerInterface; + +final class CleanLogHandler implements CleanLogHandlerInterface +{ + public function handle(CleanLogCommand $command): void + { + throw new \Exception('implement me'); + } +} diff --git a/src/Commands/Log/LogClean.php b/src/Commands/Log/LogClean.php index 3a971c4c..3bc6a40c 100644 --- a/src/Commands/Log/LogClean.php +++ b/src/Commands/Log/LogClean.php @@ -23,6 +23,7 @@ namespace FOP\Console\Commands\Log; use FOP\Console\Command; +use FOP\Console\Core\Domain\Log\Command\CleanLogCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -36,8 +37,22 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $this->io->comment('not implemented'); + try { + $otto = $this->getContainer()->get('prestashop.core.query_bus'); + $cleanQuery = new CleanLogCommand(); + $otto->handle($cleanQuery); - return 7; + $this->io->warning('Not implemented.'); +// $this->io->success('Logs cleaned.'); + + return 0; + } catch (\Throwable $throwable) { + if (_PS_MODE_DEV_ || $output->isVerbose()) { + throw $throwable; + } + $this->io->error(sprintf('%s failed : %s', $this->getName(), $throwable->getMessage())); + + return 1; + } } } diff --git a/src/Core/Domain/Log/Command/CleanLogCommand.php b/src/Core/Domain/Log/Command/CleanLogCommand.php new file mode 100644 index 00000000..decda4cf --- /dev/null +++ b/src/Core/Domain/Log/Command/CleanLogCommand.php @@ -0,0 +1,31 @@ + + * @copyright since 2020 Friends of Presta + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License ("AFL") v. 3.0 + * + */ + +declare(strict_types=1); + +namespace FOP\Console\Core\Domain\Log\Command; + +class CleanLogCommand +{ + public function __construct() + { + throw new \Exception('implement me'); + } +} diff --git a/src/Core/Domain/Log/CommandHandler/CleanLogHandlerInterface.php b/src/Core/Domain/Log/CommandHandler/CleanLogHandlerInterface.php new file mode 100644 index 00000000..e7c6e12e --- /dev/null +++ b/src/Core/Domain/Log/CommandHandler/CleanLogHandlerInterface.php @@ -0,0 +1,28 @@ + + * @copyright since 2020 Friends of Presta + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License ("AFL") v. 3.0 + * + */ + +namespace FOP\Console\Core\Domain\Log\CommandHandler; + +use FOP\Console\Core\Domain\Log\Command\CleanLogCommand; + +interface CleanLogHandlerInterface +{ + public function handle(CleanLogCommand $command): void; +}