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

UploadedFileRepository: ajout de logs.

Showing with 24 additions and 2 deletions
+24 -2
......@@ -11,6 +11,7 @@ use Doctrine\ORM\EntityRepository;
use Gaufrette\Filesystem;
use Irstea\FileUploadBundle\Entity\UploadedFile;
use Irstea\FileUploadBundle\Service\FileManagerInterface;
use Psr\Log\LogLevel;
/**
* Description of UploadedFileRepository
......@@ -19,8 +20,9 @@ use Irstea\FileUploadBundle\Service\FileManagerInterface;
*/
class UploadedFileRepository extends EntityRepository implements FileManagerInterface
{
use \Psr\Log\LoggerAwareTrait;
/**
*
* @var Filesystem
*/
protected $filesystem;
......@@ -55,6 +57,8 @@ class UploadedFileRepository extends EntityRepository implements FileManagerInte
$this->_em->persist($file);
$this->_em->flush();
$this->log(LogLevel::INFO, 'File created', ['file' => $file]);
return $file;
}
......@@ -62,10 +66,25 @@ class UploadedFileRepository extends EntityRepository implements FileManagerInte
{
$this->_em->remove($file);
$this->filesystem->delete($file->getPath());
$this->log(LogLevel::INFO, 'File deleted', ['file' => $file]);
}
public function get($id)
{
return $this->findById($id);
}
/**
*
* @param string $level
* @param string $message
* @param array $context
*/
protected function log($level, $message, array $context = [])
{
if(null !== $this->logger) {
$this->logger->log($level, $message, $context);
}
}
}
......@@ -16,7 +16,10 @@ services:
arguments:
- %irstea_file_upload.entity%
calls:
- [ setFilesystem, [ @?irstea_file_upload.filesystem ] ]
- [ setFilesystem, [ @irstea_file_upload.filesystem ] ]
- [ setLogger, [ @logger ] ]
tags:
- { name: monolog.logger, channel: irstea_file_upload }
# Le contrôleur qui gère les uploads
irstea_file_upload.upload_controller:
......
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