public function find($path) { try { $binaryFile = $this->ioService->loadBinaryFile($path); } catch (NotFoundException $e) { throw new NotLoadableException("Source image not found in {$path}", 0, $e); } $mimeType = $binaryFile->mimeType; return new Binary($this->ioService->getFileContents($binaryFile), $mimeType, $this->extensionGuesser->guess($mimeType)); }
public function find($path) { try { $binaryFile = $this->ioService->loadBinaryFile($path); // Treat a MissingBinaryFile as a not loadable file. if ($binaryFile instanceof MissingBinaryFile) { throw new NotLoadableException("Source image not found in {$path}"); } $mimeType = $this->ioService->getMimeType($path); return new Binary($this->ioService->getFileContents($binaryFile), $mimeType, $this->extensionGuesser->guess($mimeType)); } catch (NotFoundException $e) { throw new NotLoadableException("Source image not found in {$path}", 0, $e); } }
/** * @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 = $this->extractFiles($xml); if ($storedFiles === null) { continue; } if ($this->aliasCleaner) { $this->aliasCleaner->removeAliases($this->IOService->getExternalPath($storedFiles['original'])); } foreach ($storedFiles as $storedFilePath) { $gateway->removeImageReferences($storedFilePath, $versionInfo->versionNo, $fieldId); if ($gateway->countImageReferences($storedFilePath) === 0) { try { $binaryFile = $this->IOService->loadBinaryFile($storedFilePath); $this->IOService->deleteBinaryFile($binaryFile); } catch (NotFoundException $e) { if (isset($this->logger)) { $this->logger->error("Image with id {$storedFilePath} not found"); } } } } } }
/** * Purge all variations generated for aliases in $aliasName. * * @param array $aliasNames */ public function purge(array $aliasNames) { foreach ($this->imageFileList as $originalImageId) { foreach ($aliasNames as $aliasName) { $variationImageId = $this->variationPathGenerator->getVariationPath($originalImageId, $aliasName); if (!$this->ioService->exists($variationImageId)) { continue; } $binaryFile = $this->ioService->loadBinaryFile($variationImageId); $this->ioService->deleteBinaryFile($binaryFile); if (isset($this->logger)) { $this->logger->info("Purging {$aliasName} variation {$variationImageId} for original image {$originalImageId}"); } } } }
/** * @param string[] $paths The paths where the original files are expected to be. * @param string[] $filters The imagine filters in effect. * * @return void */ public function remove(array $paths, array $filters) { // TODO: $paths may be empty, meaning that all generated images corresponding to $filters need to be removed. if (empty($filters)) { $filters = array_keys($this->filterConfiguration->all()); } foreach ($paths as $path) { foreach ($filters as $filter) { $filteredImagePath = $this->getFilePath($path, $filter); if (!$this->ioService->exists($filteredImagePath)) { continue; } $binaryFile = $this->ioService->loadBinaryFile($filteredImagePath); $this->ioService->deleteBinaryFile($binaryFile); } } }
public function getFieldData(VersionInfo $versionInfo, Field $field, array $context) { if ($field->value->data !== null) { $field->value->data['imageId'] = $versionInfo->contentInfo->id . '-' . $field->id; $binaryFile = $this->IOService->loadBinaryFile($field->value->data['id']); $field->value->data['id'] = $binaryFile->id; $field->value->data['fileSize'] = $binaryFile->size; $field->value->data['uri'] = $binaryFile->uri; } }
public function loadBinaryFile($binaryFileId) { // If the id is an internal (absolute) path to a draft image, use the draft service to get external path & load if ($this->isDraftImagePath($binaryFileId)) { return $this->draftIOService->loadBinaryFile($this->draftIOService->getExternalPath($binaryFileId)); } // If the id is an internal path (absolute) to a published image, replace with the internal path if ($this->isPublishedImagePath($binaryFileId)) { $binaryFileId = $this->publishedIOService->getExternalPath($binaryFileId); } return $this->publishedIOService->loadBinaryFile($binaryFileId); }
/** * Deletes all referenced external data * * @param VersionInfo $versionInfo * @param array $fieldIds * @param array $context * * @return boolean */ public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds, array $context) { if (empty($fieldIds)) { return; } $gateway = $this->getGateway($context); $referencedFiles = $gateway->getReferencedFiles($fieldIds, $versionInfo->versionNo); $gateway->removeFileReferences($fieldIds, $versionInfo->versionNo); $referenceCountMap = $gateway->countFileReferences($referencedFiles); foreach ($referenceCountMap as $filePath => $count) { if ($count === 0) { $binaryFile = $this->IOService->loadBinaryFile($filePath); $this->IOService->deleteBinaryFile($binaryFile); } } }
/** * @param string[] $paths The paths where the original files are expected to be. * @param string[] $filters The imagine filters in effect. */ public function remove(array $paths, array $filters) { if (empty($filters)) { $filters = array_keys($this->filterConfiguration->all()); } if (empty($paths)) { $this->variationPurger->purge($filters); } foreach ($paths as $path) { foreach ($filters as $filter) { $filteredImagePath = $this->getFilePath($path, $filter); if (!$this->ioService->exists($filteredImagePath)) { continue; } $binaryFile = $this->ioService->loadBinaryFile($filteredImagePath); $this->ioService->deleteBinaryFile($binaryFile); } } }
/** * Deletes all referenced external data * * @param VersionInfo $versionInfo * @param array $fieldIds * @param array $context * * @return boolean */ public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds, array $context) { if (empty($fieldIds)) { return; } $gateway = $this->getGateway($context); $referencedFiles = $gateway->getReferencedFiles($fieldIds, $versionInfo->versionNo); $gateway->removeFileReferences($fieldIds, $versionInfo->versionNo); $referenceCountMap = $gateway->countFileReferences($referencedFiles); foreach ($referenceCountMap as $filePath => $count) { if ($count === 0) { try { $binaryFile = $this->IOService->loadBinaryFile($filePath); $this->IOService->deleteBinaryFile($binaryFile); } catch (NotFoundException $e) { if (isset($this->logger)) { $filePath = $this->IOService->getInternalPath($filePath); $this->logger->error("BinaryFile with ID {$filePath} not found"); } } } } }
/** * Deletes the binary file stored in the field. * * @param $content * * @return mixed */ protected function deleteStoredFile($content) { return $this->ioService->deleteBinaryFile($this->ioService->loadBinaryFile($content->fields[1]->value->externalData['id'])); }