/**
  * {@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->mountManager->getFilesystem(FileStorage::CATALOG_STORAGE_ALIAS);
             $rawFile = $this->rawFileFetcher->fetch($filesystem, $fromValue->getMedia()->getKey());
             $file = $this->rawFileStorer->store($rawFile, FileStorage::CATALOG_STORAGE_ALIAS, false);
             $file->setOriginalFilename($fromValue->getMedia()->getOriginalFilename());
         }
         $toValue->setMedia($file);
     }
 }
 function it_copies_when_a_product_value_has_a_media_but_not_the_target_value($builder, $attrValidatorHelper, FileInterface $fromMedia, FileInterface $toMedia, \SplFileInfo $rawFile, FileInterface $file, ProductMediaInterface $fromMedia, ProductMediaInterface $toMedia, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product, ProductValueInterface $fromProductValue, RawFileStorerInterface $rawFileStorer, ProductValueInterface $toProductValue, RawFileFetcherInterface $rawFileFetcher, 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);
     $rawFileFetcher->fetch($fileSystem, 'key')->willReturn($rawFile);
     $rawFileStorer->store($rawFile, FileStorage::CATALOG_STORAGE_ALIAS, false)->willReturn($file);
     $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($file)->shouldBeCalled();
     $this->copyAttributeData($product, $product, $fromAttribute, $toAttribute, ['from_locale' => $fromLocale, 'to_locale' => $toLocale, 'from_scope' => $fromScope, 'to_scope' => $toScope]);
 }