Exemplo n.º 1
0
 public function testDuplicateImages()
 {
     $image = new Media();
     $image->setFilename($this->faker->numberBetween(0, 10000));
     $image->setMainImage(false);
     $this->dm->persist($image);
     $this->dm->flush();
     $this->assertNotNull($image->getId());
     $product = new Product();
     $product->setLocale('en');
     $product->setName($this->faker->sentence(1));
     $product->setDescriptionShort($this->faker->sentence(10));
     $product->setDescription($this->faker->sentence(10));
     $product->setStatus(true);
     $product->setCommentStatus(true);
     $product->setMetaUrl('url_' . time());
     $product->addMedia($image);
     $product->addMedia($image);
     $this->dm->persist($product);
     $this->dm->flush();
     $this->assertNotNull($product->getId());
     $this->assertEquals(count($product->getMedias()), 1);
     $this->dm->remove($image);
     $this->dm->flush();
     $this->dm->remove($product);
     $this->dm->flush();
 }
Exemplo n.º 2
0
 /**
  * createMediaFromFile
  *
  * @param string $pathOld
  * @param string $type
  * @param boolean $move
  *
  * @return Media $media
  */
 public function createMediaFromFile($pathOld, $type, $move = true)
 {
     $media = new Media();
     $media->setType($type);
     $media->setMainImage(false);
     $this->dm->persist($media);
     $this->dm->flush();
     $newName = $media->getId() . '.' . pathinfo($pathOld, PATHINFO_EXTENSION);
     $fileDir = realpath($this->uploadPath) . '/' . date("Y") . '/' . date("m") . '/' . date("d");
     $pathNew = $fileDir . '/' . $newName;
     $pathWeb = $this->mediaPath . '/' . date("Y") . '/' . date("m") . '/' . date("d") . '/' . $newName;
     $fs = new Filesystem();
     $fs->mkdir($fileDir);
     if ($move) {
         $fs->rename($pathOld, $pathNew);
     } else {
         $fs->copy($pathOld, $pathNew);
     }
     //Update document
     $media->setFilename($pathWeb);
     $this->dm->persist($media);
     $this->dm->flush();
     return $media;
 }