From 5eb4a66ab7c19abb2fceb39d718f13aae89f6320 Mon Sep 17 00:00:00 2001 From: Matthew Barbour Date: Wed, 19 Jun 2019 19:40:25 -0500 Subject: [PATCH] Added merged indicator to DataUploadEvent and ImageAddEvent Changed merge process so that the ID of the merged image can make it back through the event chanin --- core/extension.php | 1 + core/imageboard/event.php | 2 ++ ext/cron_uploader/main.php | 4 ++-- ext/handle_svg/main.php | 1 + ext/image/main.php | 10 +++++++--- ext/resize/main.php | 4 ---- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/core/extension.php b/core/extension.php index d691bd68..5c8c61fa 100644 --- a/core/extension.php +++ b/core/extension.php @@ -199,6 +199,7 @@ abstract class DataHandlerExtension extends Extension $iae = new ImageAdditionEvent($image); send_event($iae); $event->image_id = $iae->image->id; + $event->merged = $iae->merged; // Rating Stuff. if (!empty($event->metadata['rating'])) { diff --git a/core/imageboard/event.php b/core/imageboard/event.php index 2fc40fef..ec663d6b 100644 --- a/core/imageboard/event.php +++ b/core/imageboard/event.php @@ -11,6 +11,8 @@ class ImageAdditionEvent extends Event /** @var Image */ public $image; + public $merged = false; + /** * Inserts a new image into the database with its associated * information. Also calls TagSetEvent to set the tags for diff --git a/ext/cron_uploader/main.php b/ext/cron_uploader/main.php index a6130e3b..3a6d5e42 100644 --- a/ext/cron_uploader/main.php +++ b/ext/cron_uploader/main.php @@ -388,8 +388,8 @@ class CronUploader extends Extension $infomsg = ""; // Will contain info message if ($event->image_id == -1) { throw new Exception("File type not recognised. Filename: {$filename}"); - } elseif ($event->image_id == null) { - $infomsg = "Image merged. Filename: {$filename}"; + } elseif ($event->merged === true) { + $infomsg = "Image merged. ID: {$event->image_id} Filename: {$filename}"; } else { $infomsg = "Image uploaded. ID: {$event->image_id} - Filename: {$filename}"; } diff --git a/ext/handle_svg/main.php b/ext/handle_svg/main.php index 96dea29a..9998a245 100644 --- a/ext/handle_svg/main.php +++ b/ext/handle_svg/main.php @@ -29,6 +29,7 @@ class SVGFileHandler extends DataHandlerExtension $iae = new ImageAdditionEvent($image); send_event($iae); $event->image_id = $iae->image->id; + $event->merged = $iae->merged; } } diff --git a/ext/image/main.php b/ext/image/main.php index f9b31180..3fc63325 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -88,7 +88,7 @@ class ImageIO extends Extension public function onImageAddition(ImageAdditionEvent $event) { try { - $this->add_image($event->image); + $this->add_image($event); } catch (ImageAdditionException $e) { throw new UploadException($e->error); } @@ -175,10 +175,12 @@ class ImageIO extends Extension // add image {{{ - private function add_image(Image $image) + private function add_image(ImageAdditionEvent $event) { global $user, $database, $config; + $image = $event->image; + /* * Validate things */ @@ -201,7 +203,9 @@ class ImageIO extends Extension if (isset($_GET['source']) && isset($_GET['update'])) { send_event(new SourceSetEvent($existing, $_GET['source'])); } - return null; + $event->merged = true; + $event->image = Image::by_id($existing->id); + return; } else { $error = "Image {$existing->id} ". "already has hash {$image->hash}:

".$this->theme->build_thumb_html($existing); diff --git a/ext/resize/main.php b/ext/resize/main.php index 785fcc31..a998814e 100644 --- a/ext/resize/main.php +++ b/ext/resize/main.php @@ -65,10 +65,6 @@ class ResizeImage extends Extension { global $config, $page; - if($event->image_id==null) { - return; - } - $image_obj = Image::by_id($event->image_id); if ($config->get_bool("resize_upload") == true