/**
  * TODO: remove this method after the refactoring of the product media manager
  *
  * @param ProductInterface      $product
  * @param ProductValueInterface $fromValue
  * @param ProductValueInterface $toValue
  */
 protected function duplicateMedia(ProductInterface $product, ProductValueInterface $fromValue, ProductValueInterface $toValue)
 {
     if (null === $toValue->getMedia()) {
         $media = $this->mediaFactory->createMedia();
         $toValue->setMedia($media);
     }
     $this->mediaManager->duplicate($fromValue->getMedia(), $toValue->getMedia(), $this->mediaManager->generateFilenamePrefix($product, $fromValue));
 }
 /**
  * @param ProductInterface $product
  */
 public function handleMedia(ProductInterface $product)
 {
     foreach ($product->getValues() as $value) {
         if ($media = $value->getMedia()) {
             if ($id = $media->getCopyFrom()) {
                 $source = $this->objectManager->getRepository('Pim\\Bundle\\CatalogBundle\\Model\\ProductMedia')->find($id);
                 if (!$source) {
                     throw new \Exception(sprintf('Could not find media with id %d', $id));
                 }
                 $this->mediaManager->duplicate($source, $media, $this->mediaManager->generateFilenamePrefix($product, $value));
             } else {
                 $filenamePrefix = $media->getFile() ? $this->mediaManager->generateFilenamePrefix($product, $value) : null;
                 $this->mediaManager->handle($media, $filenamePrefix);
             }
         }
     }
 }