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

FileManagerInterface: ajout d'une méthode completed, utilisée par le contrôleur.

Showing with 91 additions and 2 deletions
+91 -2
......@@ -96,7 +96,9 @@ class UploadController extends Controller
$stream->write($request->getContent());
$stream->close();
return $this->createResponse();
$this->fileManager->completed($file);
return $this->createResponse(
);
}
/**
......
......@@ -10,6 +10,8 @@ namespace Irstea\FileUploadBundle\Entity\Repository;
use Doctrine\ORM\EntityRepository;
use Gaufrette\Filesystem;
use Irstea\FileUploadBundle\Entity\UploadedFile;
use Irstea\FileUploadBundle\Event\FileUploadCompleteEvent;
use Irstea\FileUploadBundle\FileUploadEvents;
use Irstea\FileUploadBundle\Service\FileManagerInterface;
use Psr\Log\LogLevel;
use Symfony\Component\EventDispatcher\EventDispatcher;
......@@ -91,6 +93,25 @@ class UploadedFileRepository extends EntityRepository implements FileManagerInte
return $this->findById($id);
}
public function completed(UploadedFile $file)
{
$path = $file->getPath();
$fs = $this->filesystem;
$file
->setChecksum($fs->checksum($path))
->setSize($fs->size($path))
->setMimeType($fs->mimeType($path))
->setEtat(UploadedFile::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]);
}
/**
*
* @param string $level
......
<?php
/*
* Copyright (C) 2015 IRSTEA
* All rights reserved.
*/
namespace Irstea\FileUploadBundle\Event;
use Irstea\FileUploadBundle\Entity\UploadedFile;
use Symfony\Component\EventDispatcher\Event;
/**
* Description of FileUploadCompleteEvent
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class FileUploadCompleteEvent extends Event
{
/**
*
* @var UploadedFile
*/
private $uploadedFile;
/**
*
* @param UploadedFile $uploadedFile
*/
public function __construct(UploadedFile $uploadedFile)
{
$this->uploadedFile = $uploadedFile;
}
/**
*
* @return UploadedFile $uploadedFile
*/
public function getUploadedFile()
{
return $this->uploadedFile;
}
}
<?php
/*
* Copyright (C) 2015 IRSTEA
* All rights reserved.
*/
namespace Irstea\FileUploadBundle;
/**
* Description of FileUploadEvents
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
final class FileUploadEvents
{
const UPLOAD_COMPLETE = 'file_upload.complete';
}
......@@ -7,8 +7,8 @@
namespace Irstea\FileUploadBundle\Service;
use Gaufrette\Stream;
use Irstea\FileUploadBundle\Entity\UploadedFile;
use Symfony\Component\HttpFoundation\Response;
/**
* Description of FileManager
......@@ -35,4 +35,9 @@ interface FileManagerInterface
* @param UploadedFile $file
*/
public function delete(UploadedFile $file);
/**
* @param UploadedFile $file
*/
public function completed(UploadedFile $file);
}
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