From 8f86ddaa750a3622c492b589164bd77932dacedc Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 17 Mar 2024 21:55:55 +0000 Subject: [PATCH] [regen-thumb] have regen-thumb ext handle the regen-thumb command --- ext/admin/main.php | 13 ------------- ext/regen_thumb/main.php | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/ext/admin/main.php b/ext/admin/main.php index c9e50518..6bf5d0ef 100644 --- a/ext/admin/main.php +++ b/ext/admin/main.php @@ -110,19 +110,6 @@ class AdminPage extends Extension $output->writeln($user->get_auth_token()); return Command::SUCCESS; }); - $event->app->register('regen-thumb') - ->addArgument('id_or_hash', InputArgument::REQUIRED) - ->setDescription("Regenerate a post's thumbnail") - ->setCode(function (InputInterface $input, OutputInterface $output): int { - $uid = $input->getArgument('id_or_hash'); - $image = Image::by_id_or_hash($uid); - if ($image) { - send_event(new ThumbnailGenerationEvent($image, true)); - } else { - $output->writeln("No post with ID '$uid'\n"); - } - return Command::SUCCESS; - }); $event->app->register('cache:get') ->addArgument('key', InputArgument::REQUIRED) ->setDescription("Get a cache value") diff --git a/ext/regen_thumb/main.php b/ext/regen_thumb/main.php index 70538f75..e0ee1d45 100644 --- a/ext/regen_thumb/main.php +++ b/ext/regen_thumb/main.php @@ -4,6 +4,10 @@ declare(strict_types=1); namespace Shimmie2; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\{InputInterface,InputArgument}; +use Symfony\Component\Console\Output\OutputInterface; + class RegenThumb extends Extension { /** @var RegenThumbTheme */ @@ -160,4 +164,21 @@ class RegenThumb extends Extension break; } } + + public function onCliGen(CliGenEvent $event): void + { + $event->app->register('regen-thumb') + ->addArgument('id_or_hash', InputArgument::REQUIRED) + ->setDescription("Regenerate a post's thumbnail") + ->setCode(function (InputInterface $input, OutputInterface $output): int { + $uid = $input->getArgument('id_or_hash'); + $image = Image::by_id_or_hash($uid); + if ($image) { + send_event(new ThumbnailGenerationEvent($image, true)); + } else { + $output->writeln("No post with ID '$uid'\n"); + } + return Command::SUCCESS; + }); + } }