Ejemplo n.º 1
0
 /**
  * Create a new command instance.
  * @param string $folder
  * @param string $fileType
  * @param int    $depth
  * @throws FileException
  */
 public function __construct($folder, $fileType = '*jpg', $depth = 0)
 {
     $this->folder = $folder;
     $this->fileType = $fileType;
     /** @var \Symfony\Component\Finder\Finder $directoriesFound */
     $filesFound = $this->findFiles($this->folder, $this->fileType, $depth);
     if ($filesFound) {
         try {
             /** @var \Symfony\Component\Finder\SplFileInfo $file */
             foreach ($filesFound as $file) {
                 array_push($this->results, $file);
             }
         } catch (\Exception $e) {
             echo 'not accessible' . PHP_EOL;
         }
     } else {
         throw FileException::noFilesFound($this->folder);
         return false;
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * @throws FileException
  */
 private function indexFiles()
 {
     $this->startIndexerRun();
     $fileNumber = 0;
     /** @var \Symfony\Component\Finder\Finder $file */
     foreach ($this->files as $file) {
         $uploadedFile = $file->getPathName();
         // check for integrity
         if (!$this->jpegIntegrity($uploadedFile)) {
             throw FileException::fileCorrupt($uploadedFile);
             continue;
         }
         // check for files that are too new, trying to identify just uploaded files. Cannot tell if completely uploaded.
         if (!$this->fileIsOlderThan($uploadedFile, 120)) {
             throw FileException::filePremature($uploadedFile);
             continue;
         }
         $this->ImageHandler->setFile($file);
         // set relative and absolute path for later reference
         $filename = $this->ImageHandler->getFile()->getFilename();
         $this->ImageHandler->setRelativePath($this->getRelativePath() . '/' . $filename);
         $this->ImageHandler->setAbsolutePath($this->getAbsolutePath() . '/' . $filename);
         // save the picture to db, number of picture for reference
         $picture = $this->savePictureToDatabase($fileNumber);
         if ($picture) {
             $this->saveFileToDisk();
             // if no thumbnail exist OR reindexing should occur
             if (!$picture->thumbnail_max || !$picture->thumbnail_med || !$picture->thumbnail_min || $this->reindex) {
                 $this->saveThumbnails($picture, $fileNumber);
             }
             $this->numberOfFiles++;
         }
         if ($this->deleteIndexedFiles) {
             $this->removeFileFromDisk($uploadedFile);
         }
         $fileNumber++;
     }
     $this->endIndexerRun();
     unset($file);
 }