/** * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) { return; } $uri = $event->getRequest()->attributes->get('semanticPathinfo'); if (!$this->isIoUri($uri)) { return; } // Will throw an API 404 if not found, we can let it pass $event->setResponse(new BinaryStreamResponse($this->ioService->loadBinaryFileByUri($uri), $this->ioService)); }
/** * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) { return; } $uri = $event->getRequest()->attributes->get('semanticPathinfo'); if (!$this->isIoUri($uri)) { return; } $binaryFile = $this->ioService->loadBinaryFileByUri($uri); if ($binaryFile instanceof MissingBinaryFile) { throw new NotFoundHttpException("Could not find 'BinaryFile' with identifier '{$uri}'"); } $event->setResponse(new BinaryStreamResponse($binaryFile, $this->ioService)); }
/** * Parses the XML from the legacy database. * * Returns only the data required by the FieldType, nothing more. * * @param string $xml * * @return array */ protected function parseLegacyXml($xml) { $extractedData = array(); $dom = new \DOMDocument(); $dom->loadXml($xml); $ezimageTag = $dom->documentElement; if (!$ezimageTag->hasAttribute('url')) { throw new \RuntimeException('Missing attribute "url" in <ezimage/> tag.'); } if (($legacyUrl = $ezimageTag->getAttribute('url')) === '') { // Detected XML considered "empty" by the legacy storage return null; } $url = $this->urlRedecorator->redecorateFromTarget($legacyUrl); $extractedData['id'] = $this->imageIoService->loadBinaryFileByUri($url)->id; if (!$ezimageTag->hasAttribute('filename')) { throw new \RuntimeException('Missing attribute "filename" in <ezimage/> tag.'); } $extractedData['fileName'] = $ezimageTag->getAttribute('filename'); $extractedData['width'] = $ezimageTag->getAttribute('width'); $extractedData['height'] = $ezimageTag->getAttribute('height'); $extractedData['mime'] = $ezimageTag->getAttribute('mime_type'); if (!$ezimageTag->hasAttribute('alternative_text')) { throw new \RuntimeException('Missing attribute "alternative_text" in <ezimage/> tag.'); } $extractedData['alternativeText'] = $ezimageTag->getAttribute('alternative_text'); return $extractedData; }
/** * @param array $fieldIds * @param array $context * * @return boolean */ public function deleteFieldData( VersionInfo $versionInfo, array $fieldIds, array $context ) { /** @var \eZ\Publish\Core\FieldType\Image\ImageStorage\Gateway $gateway */ $gateway = $this->getGateway( $context ); $fieldXmls = $gateway->getXmlForImages( $versionInfo->versionNo, $fieldIds ); foreach ( $fieldXmls as $fieldId => $xml ) { $storedFiles = $gateway->extractFilesFromXml( $xml ); if ( $storedFiles === null ) { continue; } if ( $this->aliasCleaner ) { $this->aliasCleaner->removeAliases( $storedFiles['original'] ); } foreach ( $storedFiles as $storedFilePath ) { $gateway->removeImageReferences( $storedFilePath, $versionInfo->versionNo, $fieldId ); if ( $gateway->countImageReferences( $storedFilePath ) === 0 ) { $binaryFile = $this->IOService->loadBinaryFileByUri( $storedFilePath ); $this->IOService->deleteBinaryFile( $binaryFile ); } } } }
/** * Since both services should use the same uri, we can use any of them to *GET* the URI */ public function loadBinaryFileByUri($binaryFileUri) { try { return $this->publishedIOService->loadBinaryFileByUri($binaryFileUri); } catch (InvalidArgumentException $prefixException) { try { return $this->draftIOService->loadBinaryFileByUri($binaryFileUri); } catch (InvalidArgumentException $e) { throw $prefixException; } } }
/** * Since both services should use the same uri, we can use any of them to *GET* the URI. */ public function loadBinaryFileByUri($binaryFileUri) { try { return $this->publishedIOService->loadBinaryFileByUri($binaryFileUri); } catch (InvalidArgumentException $prefixException) { // InvalidArgumentException means that the prefix didn't match, NotFound can pass through try { return $this->draftIOService->loadBinaryFileByUri($binaryFileUri); } catch (InvalidArgumentException $e) { throw $prefixException; } } }
public function removeAliases($originalPath) { $this->innerAliasCleaner->removeAliases($this->ioService->loadBinaryFileByUri($this->urlRedecorator->redecorateFromTarget($originalPath))); }