Skip to content

Commit

Permalink
Do not delete original after scaling if legacy_filenames:true, fixes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
axllent committed Jan 18, 2019
1 parent 273dbbc commit c4800ce
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ScaledUploads.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit c4800ce

Please sign in to comment.