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

UploadedFileRepository: gère RejectedFileException dans completed().

Showing with 15 additions and 4 deletions
+15 -4
......@@ -11,6 +11,7 @@ use Doctrine\ORM\EntityRepository;
use Gaufrette\Filesystem;
use Irstea\FileUploadBundle\Entity\UploadedFile;
use Irstea\FileUploadBundle\Event\FileUploadCompleteEvent;
use Irstea\FileUploadBundle\Exception\RejectedFileException;
use Irstea\FileUploadBundle\FileUploadEvents;
use Irstea\FileUploadBundle\Model\FileManagerInterface;
use Irstea\FileUploadBundle\Model\UploadedFileInterface;
......@@ -105,12 +106,22 @@ class UploadedFileRepository extends EntityRepository implements FileManagerInte
->setMimeType($fs->mimeType($path))
->setEtat(UploadedFileInterface::ETAT_ORPHELIN);
$this->eventDispatcher->dispatch(FileUploadEvents::UPLOAD_COMPLETE, new FileUploadCompleteEvent($file));
$this->_em->persist($file);
$this->_em->flush();
$this->log(LogLevel::INFO, 'File completed', ['file' => $file]);
try {
$this->eventDispatcher->dispatch(FileUploadEvents::UPLOAD_COMPLETE, new FileUploadCompleteEvent($file));
$this->_em->flush();
$this->log(LogLevel::INFO, 'File completed', ['file' => $file]);
} catch(RejectedFileException $ex) {
$file->setEtat(UploadedFileInterface::ETAT_REJETE);
$this->_em->flush();
$this->log(LogLevel::WARNING, 'File rejected', ['file' => $file, 'exception' => $ex]);
throw $ex;
}
}
/**
......
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