Skip to content

Commit

Permalink
Fixing issue #15
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxist committed Jan 29, 2016
1 parent cb12dbe commit 1440eaf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/Cantiga/Metamodel/FileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
namespace Cantiga\Metamodel;

use Cantiga\Metamodel\Exception\DiskAssetException;
use LogicException;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -53,7 +54,7 @@ public function __construct($targetDirectory)
public function storeFile(UploadedFile $file)
{
$hashedName = sha1($file->getBasename().filemtime($file->getPath()));
$extension = $file->getClientOriginalExtension();
$extension = strtolower($file->getClientOriginalExtension());

$finalName = $hashedName.'.'.$extension;
while(file_exists($this->targetDirectory.DIRECTORY_SEPARATOR.$this->hashToLocation($finalName))) {
Expand All @@ -79,6 +80,15 @@ public function replaceFile($name, UploadedFile $file)
throw new DiskAssetException('Cannot replace a file that does not exist.');
}
$directory = dirname($fullPath);

$extension = strtolower($file->getClientOriginalExtension());
// extension changed, remove the old file and update the name accordingly
if (strpos($name, '.'.$extension) === false) {
unlink($fullPath);
$extStart = strrpos($name, '.');
$name = substr($name, 0, $extStart).'.'.$extension;
}

$file->move($directory, $name);
return $name;
}
Expand Down
2 changes: 1 addition & 1 deletion src/WIO/EdkBundle/Entity/EdkRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ public function updateFiles(FileRepositoryInterface $fileRepository)
if(null === $this->mapFile) {
$this->mapFile = $fileRepository->storeFile($this->getMapFileUpload());
} else {
$fileRepository->replaceFile($this->mapFile, $this->getMapFileUpload());
$this->mapFile = $fileRepository->replaceFile($this->mapFile, $this->getMapFileUpload());
}
}
if (null !== $this->getGpsTrackFileUpload()) {
Expand Down

0 comments on commit 1440eaf

Please sign in to comment.