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/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/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 403e9fc1..28a2ab8c 100644 --- a/config/services.yml +++ b/config/services.yml @@ -9,138 +9,7 @@ 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 ] - - 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 new file mode 100644 index 00000000..3bc6a40c --- /dev/null +++ b/src/Commands/Log/LogClean.php @@ -0,0 +1,58 @@ + + * @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 FOP\Console\Core\Domain\Log\Command\CleanLogCommand; +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 + { + try { + $otto = $this->getContainer()->get('prestashop.core.query_bus'); + $cleanQuery = new CleanLogCommand(); + $otto->handle($cleanQuery); + + $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; +} 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 [