/** * Test related method */ public function testRemoveAFileIfMediaIsRemoved() { $this->filesystem->expects($this->any())->method('has')->will($this->returnValue(true)); $this->filesystem->expects($this->once())->method('delete'); $media = $this->getMediaMock(); $media->expects($this->any())->method('isRemoved')->will($this->returnValue(true)); $media->expects($this->any())->method('getFilename')->will($this->returnValue('foo.jpg')); $this->manager->handle($media, ''); }
/** * Handles the media of the given product template * * @param ProductTemplateInterface $template */ public function handleProductTemplateMedia(ProductTemplateInterface $template) { $mediaHandled = false; foreach ($template->getValues() as $value) { if (null !== ($media = $value->getMedia())) { $mediaHandled = true; $filenamePrefix = $media->getFile() ? $this->generateFilenamePrefix($value) : null; $this->mediaManager->handle($media, $filenamePrefix); } } if ($mediaHandled) { $this->updateNormalizedValues($template); } }
/** * @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); } } } }