Improve CustomerCountsCommand with description and output formatting
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
<?php
|
||||
|
||||
use Console\ApplicationFactory;
|
||||
use Console\Commands\CustomerCountsCommand;
|
||||
use Console\Commands\PulseSendEventsCommand;
|
||||
use Console\Commands\ScheduleListCommand;
|
||||
use Console\Commands\ScheduleRunCommand;
|
||||
@@ -98,4 +99,5 @@ $console->add($app->get(ScheduleListCommand::class));
|
||||
$console->add($app->get(PulseSendEventsCommand::class));
|
||||
$console->add($app->get(ImagesWarmupCacheCommand::class));
|
||||
$console->add($app->get(ImagesCacheClearCommand::class));
|
||||
$console->add($app->get(CustomerCountsCommand::class));
|
||||
$console->run();
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Console\Commands;
|
||||
|
||||
use Openguru\OpenCartFramework\QueryBuilder\Connections\ConnectionInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class CustomerCountsCommand extends TeleCartCommand
|
||||
{
|
||||
protected static $defaultName = 'customer:counts';
|
||||
protected static $defaultDescription = 'Обновление счетчиков заказов для всех клиентов';
|
||||
|
||||
private ConnectionInterface $database;
|
||||
|
||||
public function __construct(ConnectionInterface $database)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$io->title('Обновление счетчиков заказов клиентов');
|
||||
$io->writeln('Выполняется пересчёт счетчиков заказов...');
|
||||
|
||||
$sql = <<<SQL
|
||||
update telecart_customers
|
||||
set orders_count = (select count(*) from oc_order where oc_order.customer_id = telecart_customers.oc_customer_id)
|
||||
where true;
|
||||
SQL;
|
||||
|
||||
$this->database->statement($sql);
|
||||
|
||||
$io->success('Счетчики заказов успешно обновлены!');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user