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
This commit is contained in:
Matthew Barbour 2019-06-19 19:40:25 -05:00 committed by matthew
parent 5a30ce1c83
commit 5eb4a66ab7
6 changed files with 13 additions and 9 deletions

View file

@ -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'])) {

View file

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

View file

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

View file

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

View file

@ -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 <a href='".make_link("post/view/{$existing->id}")."'>{$existing->id}</a> ".
"already has hash {$image->hash}:<p>".$this->theme->build_thumb_html($existing);

View file

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