From c4800ced674712a8bbbd4b2e074f822c5cf505ea Mon Sep 17 00:00:00 2001 From: Ralph Slooten Date: Sat, 19 Jan 2019 12:09:10 +1300 Subject: [PATCH] Do not delete original after scaling if legacy_filenames:true, fixes #9 --- src/ScaledUploads.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ScaledUploads.php b/src/ScaledUploads.php index edadb4f..c4db660 100644 --- a/src/ScaledUploads.php +++ b/src/ScaledUploads.php @@ -2,6 +2,8 @@ namespace Axllent\ScaledUploads; +use SilverStripe\Assets\Flysystem\FlysystemAssetStore; +use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Extension; @@ -139,9 +141,11 @@ private function scaleUploadedImage($file) // write to tmp file and then overwrite original if ($transformed && $modified) { - $orig_hash = $file->getHash(); $transformed->writeTo($tmp_image); - $file->File->deleteFile(); // delete original else a rogue copy is left + // if !legacy_filenames then delete original, else rogue copies are left on filesystem + if (!Config::inst()->get(FlysystemAssetStore::class, 'legacy_filenames')) { + $file->File->deleteFile(); + } $file->setFromLocalFile($tmp_image, $file->FileName); // set new image $file->write(); }