From 99ff45a818828425ef9765aeac973a8821fd4194 Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Mon, 21 Jan 2019 17:56:14 +1300 Subject: [PATCH 1/3] MINOR Remove ImageBackendFactory Injector override from ImageThumbnailHelper --- code/Helper/ImageThumbnailHelper.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/code/Helper/ImageThumbnailHelper.php b/code/Helper/ImageThumbnailHelper.php index 0242d79d2..e9c22ff32 100644 --- a/code/Helper/ImageThumbnailHelper.php +++ b/code/Helper/ImageThumbnailHelper.php @@ -3,10 +3,7 @@ use SilverStripe\AssetAdmin\Controller\AssetAdmin; use SilverStripe\Assets\File; -use SilverStripe\Assets\ImageBackendFactory; use SilverStripe\Core\Injector\Injectable; -use SilverStripe\Core\Injector\InjectionCreator; -use SilverStripe\Core\Injector\Injector; class ImageThumbnailHelper { @@ -15,11 +12,6 @@ class ImageThumbnailHelper public function run() { $assetAdmin = AssetAdmin::singleton(); - $creator = new InjectionCreator(); - Injector::inst()->registerService( - $creator, - ImageBackendFactory::class - ); $files = File::get(); set_time_limit(0); From 13b847501f117a6286cf079550f7c0031c4edf14 Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Wed, 23 Jan 2019 18:55:58 +1300 Subject: [PATCH 2/3] NEW add a memory limit to the ImageThumbnailHelper --- code/Helper/ImageThumbnailHelper.php | 40 +++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/code/Helper/ImageThumbnailHelper.php b/code/Helper/ImageThumbnailHelper.php index e9c22ff32..eda8f0018 100644 --- a/code/Helper/ImageThumbnailHelper.php +++ b/code/Helper/ImageThumbnailHelper.php @@ -3,20 +3,58 @@ use SilverStripe\AssetAdmin\Controller\AssetAdmin; use SilverStripe\Assets\File; +use SilverStripe\Core\Convert; use SilverStripe\Core\Injector\Injectable; +use SilverStripe\ORM\DB; class ImageThumbnailHelper { use Injectable; + /** + * @var int + */ + private $maxImageFileSize; + + /** + * @param mixed $maxImageSize Maximum file size for which thumbnails will be generated + */ + public function __construct($maxImageFileSize = '9M') + { + $this->setMaxImageFileSize($maxImageFileSize); + } + + /** + * @return int + */ + public function getMaxImageFileSize() + { + return $this->maxImageFileSize; + } + + /** + * @param mixed $size + * @return $this + */ + public function setMaxImageFileSize($size) + { + $this->maxImageFileSize = Convert::memstring2bytes($size); + return $this; + } + public function run() { $assetAdmin = AssetAdmin::singleton(); + /** @var File[] $files */ $files = File::get(); set_time_limit(0); + + $maxSize = $this->getMaxImageFileSize(); foreach ($files as $file) { - $assetAdmin->generateThumbnails($file, true); + if ($maxSize == 0 || $file->getAbsoluteSize() < $maxSize) { + $assetAdmin->generateThumbnails($file, true); + } } } } From ca5e80baeeda64ed7fe1fe526be316ffe6532781 Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Tue, 29 Jan 2019 15:13:40 +1300 Subject: [PATCH 3/3] Implement PR feedback #905 --- code/Helper/ImageThumbnailHelper.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/code/Helper/ImageThumbnailHelper.php b/code/Helper/ImageThumbnailHelper.php index eda8f0018..c1b4de3d6 100644 --- a/code/Helper/ImageThumbnailHelper.php +++ b/code/Helper/ImageThumbnailHelper.php @@ -17,7 +17,8 @@ class ImageThumbnailHelper private $maxImageFileSize; /** - * @param mixed $maxImageSize Maximum file size for which thumbnails will be generated + * @param mixed $maxImageSize Maximum file size for which thumbnails will be generated. Set to `0` to disable the + * limit. */ public function __construct($maxImageFileSize = '9M') { @@ -25,6 +26,7 @@ public function __construct($maxImageFileSize = '9M') } /** + * Get the maximum file size for which thumbnails will be generated. Set to `0` to disable the limit. * @return int */ public function getMaxImageFileSize() @@ -33,6 +35,7 @@ public function getMaxImageFileSize() } /** + * Set the maximum file size for which thumbnails will be generated. Set to `0` to disable the limit. * @param mixed $size * @return $this */