Skip to content

Commit

Permalink
fix: cli commands compatibility with Magento 2.4.6+
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanaugustobds committed Jul 12, 2023
1 parent 766aff2 commit 076beda
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
15 changes: 12 additions & 3 deletions Console/Command/Clear.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Clear extends Command
/** @var ProgressBarFactory */
private $progressBarFactory;

// phpcs:ignore
public function __construct(
ConfirmationQuestionFactory $confirmationQuestionFactory,
CoreHelper $coreHelper,
Expand All @@ -45,7 +46,9 @@ public function __construct(
$this->progressBarFactory = $progressBarFactory;
}

/** @inheritDoc */
/**
* @inheritDoc
*/
protected function configure()
{
$this->setName('discorgento:queue:clear');
Expand All @@ -54,14 +57,18 @@ protected function configure()
parent::configure();
}

/** @inheritDoc */
/**
* @inheritDoc
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$messages = $this->messagesCollectionFactory->create();

$totalMessages = $messages->getSize();
if ($totalMessages < 1) {
return $output->writeln("<error>There's no pending jobs.</error>");
$output->writeln("<error>There's no pending jobs.</error>");

return self::SUCCESS;
}

if ($this->coreHelper->isProductionMode()) {
Expand Down Expand Up @@ -89,5 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$output->writeln(PHP_EOL . '<info>Done.</info>');

return self::SUCCESS;
}
}
15 changes: 12 additions & 3 deletions Console/Command/Execute.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Execute extends Command
/** @var ProgressBarFactory */
private $progressBarFactory;

// phpcs:ignore
public function __construct(
MessageManagementInterface $messageManagement,
ProgressBarFactory $progressBarFactory,
Expand All @@ -27,7 +28,9 @@ public function __construct(
$this->progressBarFactory = $progressBarFactory;
}

/** @inheritDoc */
/**
* @inheritDoc
*/
protected function configure()
{
$this->setName('discorgento:queue:execute');
Expand All @@ -36,14 +39,18 @@ protected function configure()
parent::configure();
}

/** @inheritDoc */
/**
* @inheritDoc
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$pendingMessages = $this->messageManagement->getPending();

$totalMessages = $pendingMessages->getTotalCount();
if ($totalMessages < 1) {
return $output->writeln("There's no pending jobs.");
$output->writeln("There's no pending jobs.");

return self::SUCCESS;
}

$output->writeln('Executing the jobs in queue..');
Expand All @@ -62,5 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$progressBar->finish();
$output->writeln(PHP_EOL . '<info>Done.</info>');

return self::SUCCESS;
}
}
15 changes: 12 additions & 3 deletions Console/Command/Retry.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Retry extends Command
/** @var ProgressBarFactory */
private $progressBarFactory;

// phpcs:ignore
public function __construct(
MessageManagementInterface $messageManagement,
ProgressBarFactory $progressBarFactory,
Expand All @@ -27,7 +28,9 @@ public function __construct(
$this->progressBarFactory = $progressBarFactory;
}

/** @inheritDoc */
/**
* @inheritDoc
*/
protected function configure()
{
$this->setName('discorgento:queue:retry');
Expand All @@ -36,14 +39,18 @@ protected function configure()
parent::configure();
}

/** @inheritDoc */
/**
* @inheritDoc
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$failedJobs = $this->messageManagement->getToBeRetried();

$totalMessages = count($failedJobs);
if ($totalMessages < 1) {
return $output->writeln("There's no jobs waiting to be retried.");
$output->writeln("There's no jobs waiting to be retried.");

return self::SUCCESS;
}

$output->writeln('Retrying the failed jobs..');
Expand All @@ -61,5 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$progressBar->finish();
$output->writeln(PHP_EOL . '<info>Done.</info>');

return self::SUCCESS;
}
}

0 comments on commit 076beda

Please sign in to comment.