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

UploadedFile: déplace le fichier hors de l'orphelinat lorsqu'il passe de...

UploadedFile: déplace le fichier hors de l'orphelinat lorsqu'il passe de l'état "orphelin" à "normal".
Showing with 9 additions and 3 deletions
+9 -3
......@@ -13,7 +13,6 @@ use Gaufrette\Exception\FileNotFound;
use Gaufrette\Filesystem;
use Gaufrette\StreamMode;
use InvalidArgumentException;
use Irstea\FileUploadBundle\Entity\Repository\UploadedFileRepository;
use Irstea\FileUploadBundle\Model\UploadedFileInterface;
use Irstea\FileUploadBundle\Utils\MimeTypeIcon;
use Rhumsaa\Uuid\Uuid;
......@@ -27,6 +26,8 @@ class UploadedFile implements UploadedFileInterface
// Taille de bloc utilisé pour les copies
static public $copyBlockSize = 8192;
const ORPHAN_PREFIX = "orphan/";
/**
* @ORM\Id
* @ORM\Column(type="guid")
......@@ -120,7 +121,7 @@ class UploadedFile implements UploadedFileInterface
public function __construct($createdBy = null, $createdFrom = null)
{
$this->id = Uuid::uuid4()->toString();
$this->path = "orphan/".$this->id;
$this->path = self::ORPHAN_PREFIX.$this->id;
$this->createdAt = new DateTime('now');
$this->createdBy = $createdBy;
$this->createdFrom = $createdFrom;
......@@ -285,6 +286,12 @@ class UploadedFile implements UploadedFileInterface
)) {
throw new InvalidArgumentException(sprintf("Etat invalide: '%s'", (string)$etat));
}
// Déplace le fichier hors de l'orphelinat quand on passe d'orphelin à nouveau
if($this->etat === self::ETAT_ORPHELIN && $etat === self::ETAT_NORMAL && 0 === strpos($this->path, self::ORPHAN_PREFIX)) {
$this->path = substr($this->path, strlen($this->path));
}
$this->etat = $etat;
return $this;
......@@ -488,7 +495,6 @@ class UploadedFile implements UploadedFileInterface
$stream->open(new StreamMode('rb'));
$stream->seek($readOffset);
if(false !== $fileHandle = $stream->cast(STREAM_CAST_AS_STREAM)) {
// Utilise stream_copy_to_stream si le Stream nous renvoie un filehandle
$copied = $this->stream_copy_to_stream($fileHandle, $dest, $actualLength);
......
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