/**
  * @param $file
  * @param ResponseInterface $response
  * @param Request $request
  */
 protected function handleUpload($file, ResponseInterface $response, Request $request)
 {
     /** @var $mediaAdmin \Sonata\MediaBundle\Admin\ORM\MediaAdmin */
     $mediaAdmin = $this->container->get('sonata.media.admin.media');
     $mediaAdmin->setRequest($request);
     /** @var Media $media */
     $media = $mediaAdmin->getNewInstance();
     $media->setEnabled(true);
     $media->setName($file->getClientOriginalName());
     $media->setBinaryContent($file);
     $checksum = Util\Checksum::fromFile($file->getPathName());
     $duplicate = $mediaAdmin->checkForDuplicate($media, $checksum);
     if ($duplicate) {
         $path = $mediaAdmin->generateObjectUrl('edit', $duplicate);
         $response->offsetSet('url', $path);
         $response->offsetSet('id', $duplicate->getId());
         throw new DuplicateMediaException('File is duplicate');
     }
     try {
         $mediaAdmin->create($media);
         $path = $mediaAdmin->generateObjectUrl('edit', $media);
         $response->offsetSet('url', $path);
         $response->offsetSet('id', $media->getId());
     } catch (\Exception $e) {
         throw new UploadException($e->getMessage());
     }
 }
 /**
  * @param $file
  * @param ResponseInterface $response
  * @param Request $request
  */
 protected function handleUpload($file, ResponseInterface $response, Request $request)
 {
     /** @var $mediaAdmin \Sonata\MediaBundle\Admin\ORM\MediaAdmin */
     $mediaAdmin = $this->container->get('sonata.media.admin.media');
     $mediaAdmin->setRequest($request);
     /** @var Media $media */
     $media = $mediaAdmin->getNewInstance();
     $media->setEnabled(true);
     $media->setName($file->getClientOriginalName());
     $media->setBinaryContent($file);
     $tags = explode(',', $request->get('tags'));
     $tagCollection = new ArrayCollection();
     foreach ($tags as $tagId) {
         $tag = $this->container->get('doctrine')->getRepository('NetworkingInitCmsBundle:Tag')->find($tagId);
         if ($tag) {
             $tagCollection->add($tag);
         }
     }
     $media->setTags($tagCollection);
     $checksum = Util\Checksum::fromFile($file->getPathName());
     $duplicate = $mediaAdmin->checkForDuplicate($media, $checksum);
     if ($duplicate) {
         $path = $mediaAdmin->generateObjectUrl('edit', $duplicate);
         $response->offsetSet('url', $path);
         $response->offsetSet('id', $duplicate->getId());
         throw new DuplicateMediaException('File is duplicate');
     }
     try {
         $mediaAdmin->create($media);
         $path = $mediaAdmin->generateObjectUrl('edit', $media);
         $response->offsetSet('url', $path);
         $response->offsetSet('id', $media->getId());
     } catch (\Exception $e) {
         throw new UploadException($e->getMessage());
     }
 }
예제 #3
0
 /**
  * {@inheritDoc}
  */
 public function checksum($key)
 {
     return Util\Checksum::fromContent($this->read($key));
 }
예제 #4
0
 /**
  * Returns the checksum of the specified file's content.
  *
  * @param string $key
  *
  * @return string A MD5 hash
  */
 public function checksum($key)
 {
     $this->assertHasFile($key);
     if ($this->adapter instanceof Adapter\ChecksumCalculator) {
         return $this->adapter->checksum($key);
     }
     return Util\Checksum::fromContent($this->read($key));
 }
예제 #5
0
 public function checksum($key)
 {
     return Util\Checksum::fromFile($this->computePath($key));
 }
 /**
  * {@inheritdoc}
  */
 public function checksum($key)
 {
     $file = $this->find($key);
     return Util\Checksum::fromContent($file ? $file->getContentAsString() : '');
 }
예제 #7
0
 /**
  * @param $media
  * @return string
  */
 public function getChecksum($media)
 {
     if ($media->getBinaryContent() instanceof UploadedFile) {
         return Util\Checksum::fromFile($media->getBinaryContent()->getPathName());
     }
     return false;
 }
예제 #8
0
 /**
  * {@inheritDoc}
  */
 public function write($key, $content, array $metadata = null)
 {
     $this->files[$key]['content'] = $content;
     $this->files[$key]['mtime'] = time();
     $this->files[$key]['checksum'] = Util\Checksum::fromContent($content);
     return Util\Size::fromContent($content);
 }
예제 #9
0
파일: Zip.php 프로젝트: novatex/Gaufrette
 /**
  * Returns the checksum of the file
  *
  * @param  string $key
  *
  * @return string
  */
 public function checksum($key)
 {
     $this->assertExists($key);
     return Util\Checksum::fromContent($this->read($key));
 }
예제 #10
0
 /**
  * {@inheritdoc}
  */
 public function write($key, $content)
 {
     $values = array($this->getQuotedColumn('content') => $content, $this->getQuotedColumn('mtime') => time(), $this->getQuotedColumn('checksum') => Util\Checksum::fromContent($content));
     if ($this->exists($key)) {
         $this->connection->update($this->table, $values, array($this->getQuotedColumn('key') => $key));
     } else {
         $values[$this->getQuotedColumn('key')] = $key;
         $this->connection->insert($this->table, $values);
     }
     return Util\Size::fromContent($content);
 }
 /**
  * {@inheritDoc}
  */
 public function checksum($key)
 {
     return Checksum::fromFile($this->repository->resolveFullPath($key));
 }
예제 #12
0
 public function testChecksumIsUpdatedOnWrite()
 {
     $adapter = new InMemory(array('foobar' => array('content' => 'Some content', 'checksum' => 'abcd')));
     $adapter->write('foobar', 'Changed content');
     $this->assertEquals(Checksum::fromContent('Changed content'), $adapter->checksum('foobar'));
 }
예제 #13
0
파일: Local.php 프로젝트: novatex/Gaufrette
 /**
  * {@inheritDoc}
  */
 public function checksum($key)
 {
     $this->assertExists($key);
     return Util\Checksum::fromFile($this->computePath($key));
 }