Exemple #1
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $rootPath = $this->container->get('kernel')->getRootDir() . '/../web/themes/wellcommerce/assets/prod/';
     $uploader = $this->container->get('media.manager.admin');
     $uploadPath = $uploader->getUploadRootDir('images');
     $filesystem = $this->container->get('filesystem');
     foreach (self::$samples as $photo) {
         $image = new UploadedFile($rootPath . $photo, $photo, 'image/jpeg', filesize($rootPath . $photo));
         $media = new Media();
         $media->setName($image->getClientOriginalName());
         $media->setExtension($image->guessClientExtension());
         $media->setMime($image->getClientMimeType());
         $media->setSize($image->getClientSize());
         $manager->persist($media);
         $filesystem->copy($rootPath . $photo, $uploadPath . '/' . $media->getPath());
         $this->setReference('photo_' . $photo, $media);
     }
     $manager->flush();
 }