Commit 7c50bb92 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Correction de la méthode UploadedFileRepository::duplicate.

Showing with 7 additions and 6 deletions
+7 -6
......@@ -10,6 +10,8 @@ namespace Irstea\FileUploadBundle\Entity\Repository;
use DateTime;
use Doctrine\ORM\EntityRepository;
use Gaufrette\Filesystem;
use Gaufrette\StreamMode;
use InvalidArgumentException;
use Irstea\FileUploadBundle\Entity\UploadedFile;
use Irstea\FileUploadBundle\Event\FileUploadCompleteEvent;
use Irstea\FileUploadBundle\Exception\RejectedFileException;
......@@ -17,9 +19,9 @@ use Irstea\FileUploadBundle\FileUploadEvents;
use Irstea\FileUploadBundle\Model\FileManagerInterface;
use Irstea\FileUploadBundle\Model\UploadedFileInterface;
use Psr\Log\LogLevel;
use Rhumsaa\Uuid\Uuid;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Rhumsaa\Uuid\Uuid;
/**
* Description of UploadedFileRepository
......@@ -87,7 +89,7 @@ class UploadedFileRepository extends EntityRepository implements FileManagerInte
public function duplicate(UploadedFileInterface $original)
{
if (!$original->isValid()) {
throw new \InvalidArgumentException("Impossible de dupliquer le fichier ".$original->getId()." car il est invalide !");
throw new InvalidArgumentException("Impossible de dupliquer le fichier ".$original->getId()." car il est invalide !");
}
$new = new UploadedFile();
......@@ -109,12 +111,11 @@ class UploadedFileRepository extends EntityRepository implements FileManagerInte
->setSize($original->getSize());
$stream = $this->filesystem->createStream($new->getPath());
$stream->open("cb");
$original->copyTo($stream);
$stream->open(new StreamMode("cb"));
$original->copyTo($stream->cast(STREAM_CAST_AS_STREAM));
$stream->close();
$this->_em->persist($new);
$this->_em->flush();
return $new;
}
......@@ -133,7 +134,7 @@ class UploadedFileRepository extends EntityRepository implements FileManagerInte
return null;
}
if (!is_string($uuid) || !Uuid::isValid($uuid)) {
throw new \InvalidArgumentException(sprintf("Identifiant invalide: %s", (string)$uuid));
throw new InvalidArgumentException(sprintf("Identifiant invalide: %s", (string)$uuid));
}
return $this->findOneById($uuid);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment