Example #1
0
 public function load(ObjectManager $manager)
 {
     foreach ($this->data as $fileData) {
         $file = new File();
         $file->setDirectory($this->getReference($fileData['directory_reference']));
         $file->setName($fileData['name']);
         $file->setParams(new UploadedFileParametersModel());
         $file->setPath($fileData['path']);
         $manager->persist($file);
         $this->addReference($fileData['file_reference'], $file);
     }
     $manager->flush();
 }
Example #2
0
 /**
  * @param string       $filename
  * @param UploadedFile $uploadedFile
  * @param Directory    $directory
  *
  * @return File
  */
 public function save($filename, UploadedFile $uploadedFile, Directory $directory = null)
 {
     if (!$this->isAllowMimeTypes($uploadedFile)) {
         throw new UploadException(sprintf('File type %s is not allowed to upload', $uploadedFile->getMimeType()));
     }
     $newFilePath = $this->uploadDirectoryManager->getNewPath($filename);
     $size = $uploadedFile->getSize();
     $mimeType = $uploadedFile->getMimeType();
     $uploadedFile->move($this->webDir . dirname($newFilePath), basename($newFilePath));
     $path = $this->webDir . $newFilePath;
     if ($this->doResize) {
         $this->resizeImage($path);
     }
     $fileParams = $this->createFileParams($size, $mimeType, $path);
     $file = new File();
     $file->setName($filename);
     $file->setDirectory($directory);
     $file->setPath($newFilePath);
     $file->setChecksum($this->getChecksum($newFilePath));
     $file->setParams($fileParams);
     $this->entityManager->persist($file);
     $this->entityManager->flush();
     return $file;
 }
 /**
  * Set necessary mocks
  */
 private function setMocks()
 {
     $directory1 = new Directory();
     $directory1->setName('first');
     $directory2 = new Directory();
     $directory2->setName('second');
     $directory3 = new Directory();
     $directory3->setName('subfirst');
     $this->directories = array(self::DIR_ID_1 => $directory1, self::DIR_ID_2 => $directory2, self::DIR_ID_1_1 => $directory3);
     $file1 = new File();
     $file1->setDirectory($directory1);
     $file1->setPath('/../../web/abc.jpg');
     $file2 = new File();
     $file2->setDirectory($directory2);
     $file2->setPath('/../../web/xyz.jpg');
     $this->files = array();
     $this->files[self::FILE_ID_1] = $file1;
     $this->files[self::FILE_ID_2] = $file2;
 }