From 4564fd4092c4f8cca9fbf37c0c69a91a30564816 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 4 Oct 2019 20:48:21 +0100 Subject: [PATCH] by_id_or_hash for more elegant CLI use --- core/imageboard/image.php | 5 +++++ ext/admin/main.php | 10 +++++----- ext/admin/theme.php | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/core/imageboard/image.php b/core/imageboard/image.php index a133010d..4277443c 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -104,6 +104,11 @@ class Image return ($row ? new Image($row) : null); } + public static function by_id_or_hash(string $id): ?Image + { + return (is_numeric($id) && strlen($id) != 32) ? Image::by_id((int)$id) : Image::by_hash($id); + } + public static function by_random(array $tags=[], int $limit_range=0): ?Image { $max = Image::count_images($tags); diff --git a/ext/admin/main.php b/ext/admin/main.php index 6e13a76b..bc97347e 100644 --- a/ext/admin/main.php +++ b/ext/admin/main.php @@ -61,9 +61,9 @@ class AdminPage extends Extension public function onCommand(CommandEvent $event) { if ($event->cmd == "help") { - print "\tget-page [query string]\n"; + print "\tget-page \n"; print "\t\teg 'get-page post/list'\n\n"; - print "\tregen-thumb [hash]\n"; + print "\tregen-thumb \n"; print "\t\tregenerate a thumbnail\n\n"; } if ($event->cmd == "get-page") { @@ -72,12 +72,12 @@ class AdminPage extends Extension $page->display(); } if ($event->cmd == "regen-thumb") { - $image = Image::by_hash($event->args[0]); + $uid = $event->args[0]; + $image = Image::by_id_or_hash($uid); if ($image) { - print("Regenerating thumb for image {$image->id} ({$image->hash})\n"); send_event(new ThumbnailGenerationEvent($image->hash, $image->ext, true)); } else { - print("Can't find image with hash {$event->args[0]}\n"); + print("No post with ID '$uid'\n"); } } } diff --git a/ext/admin/theme.php b/ext/admin/theme.php index 055006b3..5fca85f2 100644 --- a/ext/admin/theme.php +++ b/ext/admin/theme.php @@ -66,7 +66,7 @@ class AdminPageTheme extends Themelet $warning = "This delete method will bypass the trash
"; } - $h_reason = ""; + $h_reason = ""; if (class_exists("ImageBan")) { $h_reason = ""; }