[core] have ThumbnailGenerationEvent work on an Image
This commit is contained in:
parent
01261b0fa6
commit
0762da54eb
6 changed files with 12 additions and 12 deletions
|
@ -305,7 +305,6 @@ abstract class DataHandlerExtension extends Extension
|
|||
$check_contents = $this->check_contents($event->tmpname);
|
||||
if ($supported_mime && $check_contents) {
|
||||
$this->move_upload_to_archive($event);
|
||||
send_event(new ThumbnailGenerationEvent($event->hash, $event->mime));
|
||||
|
||||
/* Check if we are replacing an image */
|
||||
if (!is_null($event->replace_id)) {
|
||||
|
@ -358,15 +357,15 @@ abstract class DataHandlerExtension extends Extension
|
|||
public function onThumbnailGeneration(ThumbnailGenerationEvent $event)
|
||||
{
|
||||
$result = false;
|
||||
if ($this->supported_mime($event->mime)) {
|
||||
if ($this->supported_mime($event->image->get_mime())) {
|
||||
if ($event->force) {
|
||||
$result = $this->create_thumb($event->hash, $event->mime);
|
||||
$result = $this->create_thumb($event->image->hash, $event->image->get_mime());
|
||||
} else {
|
||||
$outname = warehouse_path(Image::THUMBNAIL_DIR, $event->hash);
|
||||
$outname = $event->image->get_thumb_filename();
|
||||
if (file_exists($outname)) {
|
||||
return;
|
||||
}
|
||||
$result = $this->create_thumb($event->hash, $event->mime);
|
||||
$result = $this->create_thumb($event->image->hash, $event->image->get_mime());
|
||||
}
|
||||
}
|
||||
if ($result) {
|
||||
|
|
|
@ -82,8 +82,7 @@ class ThumbnailGenerationEvent extends Event
|
|||
* Request a thumbnail be made for an image object
|
||||
*/
|
||||
public function __construct(
|
||||
public string $hash,
|
||||
public string $mime,
|
||||
public Image $image,
|
||||
public bool $force = false
|
||||
) {
|
||||
parent::__construct();
|
||||
|
|
|
@ -105,7 +105,7 @@ class AdminPage extends Extension
|
|||
$uid = $event->args[0];
|
||||
$image = Image::by_id_or_hash($uid);
|
||||
if ($image) {
|
||||
send_event(new ThumbnailGenerationEvent($image->hash, $image->get_mime(), true));
|
||||
send_event(new ThumbnailGenerationEvent($image, true));
|
||||
} else {
|
||||
print("No post with ID '$uid'\n");
|
||||
}
|
||||
|
|
|
@ -147,6 +147,8 @@ class ImageIO extends Extension
|
|||
// actually insert the info
|
||||
$image->save_to_db();
|
||||
|
||||
send_event(new ThumbnailGenerationEvent($image));
|
||||
|
||||
log_info("image", "Uploaded >>{$image->id} ({$image->hash})");
|
||||
} catch (ImageAdditionException $e) {
|
||||
throw new UploadException($e->error);
|
||||
|
@ -205,7 +207,7 @@ class ImageIO extends Extension
|
|||
$original->remove_image_only(); // Actually delete the old image file from disk
|
||||
|
||||
/* Generate new thumbnail */
|
||||
send_event(new ThumbnailGenerationEvent($replacement->hash, $replacement->get_mime()));
|
||||
send_event(new ThumbnailGenerationEvent($replacement));
|
||||
|
||||
log_info("image", "Replaced >>{$original->id} with ({$replacement->hash})");
|
||||
} catch (ImageReplaceException $e) {
|
||||
|
|
|
@ -12,7 +12,7 @@ class RegenThumb extends Extension
|
|||
public function regenerate_thumbnail(Image $image, bool $force = true): bool
|
||||
{
|
||||
global $cache;
|
||||
$event = send_event(new ThumbnailGenerationEvent($image->hash, $image->get_mime(), $force));
|
||||
$event = send_event(new ThumbnailGenerationEvent($image, $force));
|
||||
$cache->delete("thumb-block:{$image->id}");
|
||||
return $event->generated;
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ class RegenThumb extends Extension
|
|||
continue;
|
||||
}
|
||||
}
|
||||
$event = send_event(new ThumbnailGenerationEvent($image->hash, $image->mime, $force));
|
||||
$event = send_event(new ThumbnailGenerationEvent($image, $force));
|
||||
if ($event->generated) {
|
||||
$i++;
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ class ResizeImage extends Extension
|
|||
//Need to generate thumbnail again...
|
||||
//This only seems to be an issue if one of the sizes was set to 0.
|
||||
$image_obj = Image::by_id($image_obj->id); //Must be a better way to grab the new hash than setting this again..
|
||||
send_event(new ThumbnailGenerationEvent($image_obj->hash, $image_obj->get_mime(), true));
|
||||
send_event(new ThumbnailGenerationEvent($image_obj, true));
|
||||
|
||||
log_info("resize", ">>{$image_obj->id} has been resized to: ".$width."x".$height);
|
||||
//TODO: Notify user that image has been resized.
|
||||
|
|
Reference in a new issue