Skip to content

Commit

Permalink
Improve naming of commands and use AsCommand Attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
aryaantony92 committed Sep 18, 2023
1 parent e9d3ac2 commit 3c73e7c
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 31 deletions.
11 changes: 5 additions & 6 deletions src/Command/CleanupPendingOrdersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@
use Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\Cart;
use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
use Pimcore\Console\AbstractCommand;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @internal
*/
#[AsCommand(
name: 'ecommerce:cleanup-pending-orders',
description: 'Cleans up orders with state pending payment after 1h -> delegates this to commit order processor',
)]
class CleanupPendingOrdersCommand extends AbstractCommand
{
protected function configure(): void
{
$this->setName('ecommerce:cleanup-pending-orders');
$this->setDescription('Cleans up orders with state pending payment after 1h -> delegates this to commit order processor');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$checkoutManager = Factory::getInstance()->getCheckoutManager(new Cart());
Expand Down
13 changes: 11 additions & 2 deletions src/Command/IndexService/BootstrapCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@
use Pimcore\Console\Traits\Timeout;
use Pimcore\Model\DataObject;
use Pimcore\Model\DataObject\Listing;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @internal
*/
#[AsCommand(
name: 'ecommerce:index:create-or-update-indices',
description: 'Bootstrap tasks creating/updating index (for all tenants), use one of the options --create-or-update-index-structure or --update-index',
aliases: ['ecommerce:indexservice:bootstrap']
)]
class BootstrapCommand extends AbstractIndexServiceCommand
{
use Timeout;
Expand Down Expand Up @@ -56,8 +62,6 @@ protected function configure(): void
self::configureCommand($this);
self::configureTimeout($this);
$this
->setName('ecommerce:indexservice:bootstrap')
->setDescription('Bootstrap tasks creating/updating index (for all tenants), use one of the options --create-or-update-index-structure or --update-index')
->addOption('create-or-update-index-structure', null, InputOption::VALUE_NONE, 'Use to create or update the index structure')
->addOption('update-index', null, InputOption::VALUE_NONE, 'Use to rebuild the index data')
->addOption('object-list-class', null, InputOption::VALUE_REQUIRED, 'The object list class to use', '\\Pimcore\\Model\\DataObject\\Product\\Listing')
Expand All @@ -74,6 +78,11 @@ protected function runBeforeFirstCommand(InputInterface $input, OutputInterface

protected function fetchItems(InputInterface $input, OutputInterface $output): array
{
// Remove in Version 2.0
if($input->getArguments()['command'] == 'ecommerce:indexservice:bootstrap') {
$output->writeln('The command "ecommerce:indexservice:bootstrap" is deprecated and will be removed in Version 2.0. Please use "ecommerce:index:create-or-update-indices" instead.');

}
$updateIndex = $input->getOption('update-index');
$createOrUpdateIndexStructure = $input->getOption('create-or-update-index-structure');

Expand Down
9 changes: 5 additions & 4 deletions src/Command/IndexService/EsSyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\Worker\ElasticSearch\AbstractElasticSearch;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -27,6 +28,10 @@
/**
* @internal
*/
#[AsCommand(
name: 'ecommerce:indexservice:elasticsearch-sync',
description: 'Refresh elastic search (ES) index settings, mappings via native ES-API.'
)]
class EsSyncCommand extends AbstractIndexServiceCommand
{
/**
Expand All @@ -36,10 +41,6 @@ protected function configure(): void
{
parent::configure();
$this
->setName('ecommerce:indexservice:elasticsearch-sync')
->setDescription(
'Refresh elastic search (ES) index settings, mappings via native ES-API.'
)
->addArgument('mode', InputArgument::REQUIRED,
'reindex: Reindexes ES indices based on the their native reindexing API. Might be necessary when mapping has changed.'.PHP_EOL.
'update-synonyms: Activate changes in synonym files, by closing and reopening the ES index.'
Expand Down
7 changes: 5 additions & 2 deletions src/Command/IndexService/ProcessPreparationQueueCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@
use Pimcore\Bundle\EcommerceFrameworkBundle\Model\IndexableInterface;
use Pimcore\Console\Traits\Parallelization;
use Pimcore\Console\Traits\Timeout;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @internal
*/
#[AsCommand(
name: 'ecommerce:indexservice:process-preparation-queue',
description: 'Processes the ecommerce preparation queue based on the store table(s).',
)]
class ProcessPreparationQueueCommand extends AbstractIndexServiceCommand
{
use Timeout;
Expand Down Expand Up @@ -66,8 +71,6 @@ protected function configure(): void
self::configureTimeout($this);

$this
->setName('ecommerce:indexservice:process-preparation-queue')
->setDescription('Processes the ecommerce preparation queue based on the store table(s).')
->addOption('tenant', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Tenant to perform action on (defaults to all)')
;
}
Expand Down
9 changes: 6 additions & 3 deletions src/Command/IndexService/ProcessUpdateIndexQueueCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@
use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\Worker\ProductCentricBatchProcessingWorker;
use Pimcore\Console\Traits\Parallelization;
use Pimcore\Console\Traits\Timeout;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @internal
*/
#[AsCommand(
name: 'ecommerce:indexservice:process-update-index-queue',
description: 'Processes the ecommerce queue / store table and updates the (search) index..',
)]
class ProcessUpdateIndexQueueCommand extends AbstractIndexServiceCommand
{
use Timeout;
Expand Down Expand Up @@ -70,9 +75,7 @@ protected function configure(): void
self::configureTimeout($this);

$this
->setName('ecommerce:indexservice:process-update-queue')
->setDescription('Processes the ecommerce queue / store table and updates the (search) index.')
->addOption('tenant', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Tenant to perform action on (defaults to all)')
->addOption('tenant', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Tenant to perform action on (defaults to all)')
;
}

Expand Down
12 changes: 10 additions & 2 deletions src/Command/IndexService/ResetQueueCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\Worker\ProductCentricBatchProcessingWorker;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -26,6 +27,11 @@
/**
* @internal
*/
#[AsCommand(
name: 'ecommerce:index:reset-indices',
description: 'Resets the preparation or index-update queue (ONLY NEEDED if store table is out of sync)',
aliases: ['ecommerce:indexservice:reset-queue']
)]
class ResetQueueCommand extends AbstractIndexServiceCommand
{
/**
Expand All @@ -36,8 +42,6 @@ protected function configure(): void
parent::configure();

$this
->setName('ecommerce:indexservice:reset-queue')
->setDescription('Resets the preparation or index-update queue (ONLY NEEDED if store table is out of sync)')
->addArgument('queue', InputArgument::REQUIRED, 'Queue to reset (preparation|update-index)')
->addOption('tenant', null, InputOption::VALUE_REQUIRED, 'Tenant to perform action on. "*" means all tenants.');
}
Expand All @@ -47,6 +51,10 @@ protected function configure(): void
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
// Remove in version 2.0
if($input->getArguments()['command'] == 'ecommerce:indexservice:reset-queue') {
$output->writeln('The command "portal-engine:update:index-recreate" is deprecated and will be removed in Version 2.0. Please use "ecommerce:index:reset-indices" instead.');
}
if (!($tenant = $input->getOption('tenant'))) {
throw new \Exception('No tenant given');
}
Expand Down
11 changes: 5 additions & 6 deletions src/Command/Voucher/CleanupReservationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@

use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
use Pimcore\Console\AbstractCommand;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @internal
*/
#[AsCommand(
name: 'ecommerce:voucher:cleanup-reservations',
description: 'Cleans the token reservations due to sysConfig duration settings',
)]
class CleanupReservationsCommand extends AbstractCommand
{
protected function configure(): void
{
$this->setName('ecommerce:voucher:cleanup-reservations');
$this->setDescription('Cleans the token reservations due to sysConfig duration settings');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->output->writeln('<comment>*</comment> Cleaning up <info>reservations</info>');
Expand Down
11 changes: 5 additions & 6 deletions src/Command/Voucher/CleanupStatisticsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@

use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
use Pimcore\Console\AbstractCommand;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* @internal
*/
#[AsCommand(
name: 'ecommerce:voucher:cleanup-statistics',
description: 'House keeping for Voucher Usage Statistics - cleans up all old data.',
)]
class CleanupStatisticsCommand extends AbstractCommand
{
protected function configure(): void
{
$this->setName('ecommerce:voucher:cleanup-statistics');
$this->setDescription('House keeping for Voucher Usage Statistics - cleans up all old data.');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->output->writeln('<comment>*</comment> Cleaning up <info>statistics</info>');
Expand Down

0 comments on commit 3c73e7c

Please sign in to comment.