/** * @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 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 ); } } } }
/** * @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); } } }
/** * 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"); } } } } }
public function deleteBinaryFile(BinaryFile $binaryFile) { $this->publishedIOService->deleteBinaryFile($binaryFile); }
/** * 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'])); }