[regen-thumb] have regen-thumb ext handle the regen-thumb command

This commit is contained in:
Shish 2024-03-17 21:55:55 +00:00 committed by Shish
parent 74ad1bf86d
commit 8f86ddaa75
2 changed files with 21 additions and 13 deletions

View file

@ -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")

View file

@ -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;
});
}
}