feat: add cache:clear CLI command for module cache clearing (#46)

This commit is contained in:
2026-01-05 20:56:20 +03:00
committed by Nikita Kiselev
parent 647e20c6b0
commit 3d0a7536a6
2 changed files with 45 additions and 0 deletions

View File

@@ -2,6 +2,7 @@
<?php
use Console\ApplicationFactory;
use Console\Commands\CacheClearCommand;
use Console\Commands\CustomerCountsCommand;
use Console\Commands\PulseSendEventsCommand;
use Console\Commands\ScheduleListCommand;
@@ -99,5 +100,6 @@ $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(CacheClearCommand::class));
$console->add($app->get(CustomerCountsCommand::class));
$console->run();

View File

@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace Console\Commands;
use Openguru\OpenCartFramework\Cache\CacheInterface;
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 CacheClearCommand extends TeleCartCommand
{
protected static $defaultName = 'cache:clear';
protected static $defaultDescription = 'Очистка кеша модуля TeleCart';
private CacheInterface $cache;
public function __construct(CacheInterface $cache)
{
parent::__construct();
$this->cache = $cache;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Очистка кеша модуля TeleCart');
try {
$this->cache->clear();
$io->success('Кеш успешно очищен!');
return Command::SUCCESS;
} catch (\Exception $e) {
$io->error('Ошибка при очистке кеша: ' . $e->getMessage());
return Command::FAILURE;
}
}
}