<?php
namespace App\EventListener;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Doctrine\ORM\EntityManagerInterface;
use Oneup\UploaderBundle\UploadEvents;
use Oneup\UploaderBundle\Event\PostUploadEvent;
use App\Entity\File;
use App\Entity\Order;
use Symfony\Component\Filesystem\Filesystem;
use App\Override\Xthiago\PDFVersionConverter\src\Converter\GhostscriptConverterCommand;
use App\Override\Xthiago\PDFVersionConverter\src\Converter\GhostscriptConverter;
class UploadListener implements EventSubscriberInterface
{
private $em;
private $projectDir;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public static function getSubscribedEvents()
{
return array(
UploadEvents::POST_UPLOAD => 'onPostUpload',
);
}
public function onPostUpload(PostUploadEvent $event)
{
// get event config
$mappingConfig = $event->getConfig();
$file_sent = $event->getFile();
$request = $event->getRequest();
$name = $file_sent->getFileName();
$file = $this->em->getRepository("App:File")->findOneBy(array('name' => $name));
if (!$file) {
$file = new File();
$file->setName($name);
}
switch ($event->getType()) {
case 'userPic':
$token = $request->query->get('token');
$file->setEntityName('userPic');
$file->setEntityId(null);
$file->setToken($token);
$file->setMappings('userPic');
break;
default:
break;
}
$this->em->persist($file);
$this->em->flush();
}
}