/** * @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()); } }
/** * {@inheritDoc} */ public function checksum($key) { return Util\Checksum::fromContent($this->read($key)); }
/** * 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)); }
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() : ''); }
/** * @param $media * @return string */ public function getChecksum($media) { if ($media->getBinaryContent() instanceof UploadedFile) { return Util\Checksum::fromFile($media->getBinaryContent()->getPathName()); } return false; }
/** * {@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); }
/** * 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)); }
/** * {@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)); }
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')); }
/** * {@inheritDoc} */ public function checksum($key) { $this->assertExists($key); return Util\Checksum::fromFile($this->computePath($key)); }