From c30ec261c93ca8be9127eb12934f8c159fae3a28 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 15 Dec 2025 10:08:09 +0100 Subject: [PATCH] Convert DeleteOrphanVisitsCommand into invokable command --- .../Visit/AbstractDeleteVisitsCommand.php | 34 ------------------- .../Visit/DeleteOrphanVisitsCommand.php | 24 ++++++------- 2 files changed, 12 insertions(+), 46 deletions(-) delete mode 100644 module/CLI/src/Command/Visit/AbstractDeleteVisitsCommand.php diff --git a/module/CLI/src/Command/Visit/AbstractDeleteVisitsCommand.php b/module/CLI/src/Command/Visit/AbstractDeleteVisitsCommand.php deleted file mode 100644 index d8ef98e3..00000000 --- a/module/CLI/src/Command/Visit/AbstractDeleteVisitsCommand.php +++ /dev/null @@ -1,34 +0,0 @@ -confirm($io)) { - $io->info('Operation aborted'); - return self::SUCCESS; - } - - return $this->doExecute($input, $io); - } - - private function confirm(SymfonyStyle $io): bool - { - $io->warning($this->getWarningMessage()); - return $io->confirm('Continue deleting visits?', false); - } - - abstract protected function doExecute(InputInterface $input, SymfonyStyle $io): int; - - abstract protected function getWarningMessage(): string; -} diff --git a/module/CLI/src/Command/Visit/DeleteOrphanVisitsCommand.php b/module/CLI/src/Command/Visit/DeleteOrphanVisitsCommand.php index 77fefaaa..654b92bf 100644 --- a/module/CLI/src/Command/Visit/DeleteOrphanVisitsCommand.php +++ b/module/CLI/src/Command/Visit/DeleteOrphanVisitsCommand.php @@ -4,13 +4,16 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Visit; +use Shlinkio\Shlink\CLI\Command\Util\CommandUtils; use Shlinkio\Shlink\Core\Visit\VisitsDeleterInterface; -use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Attribute\AsCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Style\SymfonyStyle; use function sprintf; -class DeleteOrphanVisitsCommand extends AbstractDeleteVisitsCommand +#[AsCommand(DeleteOrphanVisitsCommand::NAME, 'Deletes all orphan visits')] +class DeleteOrphanVisitsCommand extends Command { public const string NAME = 'visit:orphan-delete'; @@ -19,23 +22,20 @@ class DeleteOrphanVisitsCommand extends AbstractDeleteVisitsCommand parent::__construct(); } - protected function configure(): void + public function __invoke(SymfonyStyle $io): int { - $this - ->setName(self::NAME) - ->setDescription('Deletes all orphan visits'); + return CommandUtils::executeWithWarning( + 'You are about to delete all orphan visits. This operation cannot be undone', + $io, + fn () => $this->deleteVisits($io), + ); } - protected function doExecute(InputInterface $input, SymfonyStyle $io): int + private function deleteVisits(SymfonyStyle $io): int { $result = $this->deleter->deleteOrphanVisits(); $io->success(sprintf('Successfully deleted %s visits', $result->affectedItems)); return self::SUCCESS; } - - protected function getWarningMessage(): string - { - return 'You are about to delete all orphan visits. This operation cannot be undone.'; - } }