From 9f8a49483fc8411d63528d0ff97a2018e8b34bd1 Mon Sep 17 00:00:00 2001 From: Thasan Date: Thu, 12 Jan 2012 03:54:27 +0200 Subject: [PATCH 1/3] check if thumbnail already exists before regenerating it, way to force regen. --- contrib/regen_thumb/main.php | 2 +- core/extension.class.php | 7 ++++++- ext/handle_pixel/main.php | 9 +++++++++ ext/image/main.php | 3 ++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/contrib/regen_thumb/main.php b/contrib/regen_thumb/main.php index 23aac9a6..cf3e2eb6 100644 --- a/contrib/regen_thumb/main.php +++ b/contrib/regen_thumb/main.php @@ -18,7 +18,7 @@ class RegenThumb extends SimpleExtension { if($event->page_matches("regen_thumb") && $user->is_admin() && isset($_POST['image_id'])) { $image = Image::by_id(int_escape($_POST['image_id'])); - send_event(new ThumbnailGenerationEvent($image->hash, $image->ext)); + send_event(new ThumbnailGenerationEvent($image->hash, $image->ext, true)); $this->theme->display_results($page, $image); } } diff --git a/core/extension.class.php b/core/extension.class.php index d9cd0a18..ccd287d2 100644 --- a/core/extension.class.php +++ b/core/extension.class.php @@ -194,7 +194,12 @@ abstract class DataHandlerExtension implements Extension { } if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) { - $this->create_thumb($event->hash); + if (method_exists($this, 'create_thumb_force') && $event->force == true) { + $this->create_thumb_force($event->hash); + } + else { + $this->create_thumb($event->hash); + } } if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) { diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index 4cea671f..1fcd6d3b 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -48,6 +48,15 @@ class PixelFileHandler extends DataHandlerExtension { } protected function create_thumb($hash) { + $outname = warehouse_path("thumbs", $hash); + if(file_exists($outname)) { + return true; + } + return $this->create_thumb_force($hash); + } + + protected function create_thumb_force($hash) { + echo "x"; $inname = warehouse_path("images", $hash); $outname = warehouse_path("thumbs", $hash); global $config; diff --git a/ext/image/main.php b/ext/image/main.php index a42c7916..931f6f8c 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -97,9 +97,10 @@ class ThumbnailGenerationEvent extends Event { * @param $hash The unique hash of the image * @param $type The type of the image */ - public function ThumbnailGenerationEvent($hash, $type) { + public function ThumbnailGenerationEvent($hash, $type, $force=false) { $this->hash = $hash; $this->type = $type; + $this->force = $force; } } From cd34879cf1e5007bfc1908303bc54368277ea8e2 Mon Sep 17 00:00:00 2001 From: Thasan Date: Thu, 12 Jan 2012 03:59:58 +0200 Subject: [PATCH 2/3] oops, forgot debug code --- ext/handle_pixel/main.php | 1 - 1 file changed, 1 deletion(-) diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index 1fcd6d3b..2e4cd734 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -56,7 +56,6 @@ class PixelFileHandler extends DataHandlerExtension { } protected function create_thumb_force($hash) { - echo "x"; $inname = warehouse_path("images", $hash); $outname = warehouse_path("thumbs", $hash); global $config; From aa452bf8eb3737ad0469283e6a3a66732abaa923 Mon Sep 17 00:00:00 2001 From: Thasan Date: Sat, 14 Jan 2012 11:15:13 +0200 Subject: [PATCH 3/3] Added $force to vars --- ext/image/main.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/image/main.php b/ext/image/main.php index 931f6f8c..d4daf7a0 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -89,8 +89,8 @@ class ImageReplaceException extends SCoreException { * Request a thumbnail be made for an image object. */ class ThumbnailGenerationEvent extends Event { - var $hash, $type; - + var $hash, $type, $force; + /** * Request a thumbnail be made for an image object *