/** * {@inheritdoc} */ public function export($key, $localPathname, $storageAlias) { if (!is_dir(dirname($localPathname))) { throw new \LogicException(sprintf('The export directory "%s" does not exist.', dirname($localPathname))); } $storageFs = $this->mountManager->getFilesystem($storageAlias); $rawFile = $this->fileFetcher->fetch($storageFs, $key); $copied = $this->copyFile($rawFile->getPathname(), $localPathname); //TODO: files should also be copied in the archive folder to be able to generate the ZIP file on the fly $this->localFs->remove($rawFile->getPathname()); return $copied; }
/** * @param ProductInterface $fromProduct * @param ProductInterface $toProduct * @param AttributeInterface $fromAttribute * @param AttributeInterface $toAttribute * @param string $fromLocale * @param string $toLocale * @param string $fromScope * @param string $toScope */ protected function copySingleValue(ProductInterface $fromProduct, ProductInterface $toProduct, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, $fromLocale, $toLocale, $fromScope, $toScope) { $fromValue = $fromProduct->getValue($fromAttribute->getCode(), $fromLocale, $fromScope); if (null !== $fromValue) { $toValue = $toProduct->getValue($toAttribute->getCode(), $toLocale, $toScope); if (null === $toValue) { $toValue = $this->productBuilder->addProductValue($toProduct, $toAttribute, $toLocale, $toScope); } $file = null; if (null !== $fromValue->getMedia()) { $filesystem = $this->filesystemProvider->getFilesystem(FileStorage::CATALOG_STORAGE_ALIAS); $rawFile = $this->fileFetcher->fetch($filesystem, $fromValue->getMedia()->getKey()); $file = $this->fileStorer->store($rawFile, FileStorage::CATALOG_STORAGE_ALIAS, false); $file->setOriginalFilename($fromValue->getMedia()->getOriginalFilename()); } $toValue->setMedia($file); } }
/** * Fetch a media to the target * * @param array $media */ protected function fetch(array $media) { try { $filesystem = $this->filesystemProvider->getFilesystem($media['storage']); $this->mediaFetcher->fetch($filesystem, $media['from'], $media['to']); } catch (FileTransferException $e) { $this->addError($media, sprintf('The media has not been found or is not currently available', $e->getMessage())); } catch (\LogicException $e) { $this->addError($media, sprintf('The media has not been copied. %s', $e->getMessage())); } }
function it_copies_when_a_product_value_has_a_media_but_not_the_target_value($builder, $attrValidatorHelper, FileInfoInterface $fromMedia, FileInfoInterface $toMedia, \SplFileInfo $rawFile, FileInfoInterface $fileInfo, FileInfoInterface $fromMedia, FileInfoInterface $toMedia, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product, ProductValueInterface $fromProductValue, FileStorerInterface $fileStorer, ProductValueInterface $toProductValue, FileFetcherInterface $fileFetcher, MountManager $mountManager, FilesystemInterface $fileSystem) { $fromLocale = 'fr_FR'; $toLocale = 'fr_FR'; $toScope = 'mobile'; $fromScope = 'mobile'; $fromAttribute->getCode()->willReturn('fromAttributeCode'); $toAttribute->getCode()->willReturn('toAttributeCode'); $attrValidatorHelper->validateLocale(Argument::cetera())->shouldBeCalled(); $attrValidatorHelper->validateScope(Argument::cetera())->shouldBeCalled(); $fromProductValue->getMedia()->willReturn($fromMedia); $fromMedia->getOriginalFilename()->willReturn('akeneo.jpg'); $fromMedia->getKey()->willReturn('key'); $mountManager->getFilesystem(FileStorage::CATALOG_STORAGE_ALIAS)->willReturn($fileSystem); $fileFetcher->fetch($fileSystem, 'key')->willReturn($rawFile); $fileStorer->store($rawFile, FileStorage::CATALOG_STORAGE_ALIAS, false)->willReturn($fileInfo); $product->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue); $product->getValue('toAttributeCode', $toLocale, $toScope)->willReturn(null); $builder->addProductValue($product, $toAttribute, $toLocale, $toScope)->willReturn($toProductValue); $toProductValue->getMedia()->willReturn($toMedia); $toProductValue->setMedia($fileInfo)->shouldBeCalled(); $this->copyAttributeData($product, $product, $fromAttribute, $toAttribute, ['from_locale' => $fromLocale, 'to_locale' => $toLocale, 'from_scope' => $fromScope, 'to_scope' => $toScope]); }