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