示例#1
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);
 }