/**
  * Moves a file from given filepath to directory for original images for album
  *
  * If an item is given, UID of item is used as filename for item in original items directory
  *
  * @param string $filePath Full qualified filepath of file to move
  * @param Tx_Yag_Domain_Model_Item $item Item that should hold file (not modified, make sure to set sourceuri manually!
  * @return string
  * @throws Exception
  */
 protected function moveFileToOrigsDirectory($filePath, Tx_Yag_Domain_Model_Item $item = null)
 {
     // Create path to move file to
     $origsFilePath = $this->fileManager->getOrigFileDirectoryPathForAlbum($this->album);
     $fileSuffix = pathinfo($filePath, PATHINFO_EXTENSION);
     if ($item !== null) {
         if ($item->getOriginalFilename()) {
             $origsFilePath .= $item->getUid() . '_' . $this->fileSystemDiv->cleanFileName($item->getOriginalFilename());
         } else {
             $origsFilePath .= $item->getUid() . '.' . $fileSuffix;
             // if we get an item, we use UID of item as a part of the filename
         }
     } else {
         $origsFilePath .= Tx_Yag_Domain_FileSystem_Div::getFilenameFromFilePath($filePath);
         // if we do not get one, we use filename of given filepart
     }
     if (!rename($filePath, $origsFilePath)) {
         throw new Exception('Could not move file ' . $filePath . ' to ' . $origsFilePath, 1294176900);
     }
     // Set appropriate file mask
     $this->setFileMask($origsFilePath);
     return $origsFilePath;
 }
Exemple #2
0
 /**
  * Runs actual import.
  *
  * Crawls given directory for images using file crawler.
  * Each image found in this directory is added to the given album.
  */
 public function runImport()
 {
     $files = $this->fileCrawler->getFilesForGivenDirectory($this->directory, $this->crawlRecursive);
     $this->initItemSorting();
     foreach ($files as $filePath) {
         // Prevent import, if noDuplicates is set to true and we already have item imported in album
         if ($this->noDuplicates && $this->album->containsItemByHash(md5_file($filePath))) {
             continue;
         }
         $origFilePath = $filePath;
         $item = null;
         if ($this->moveFilesToOrigsDirectory) {
             $item = $this->getNewPersistedItem();
             $filePath = $this->moveFileToOrigsDirectory($filePath, $item);
         } else {
             $item = $this->objectManager->get('Tx_Yag_Domain_Model_Item');
         }
         $item->setOriginalFilename(Tx_Yag_Domain_FileSystem_Div::getFilenameFromFilePath($origFilePath));
         // We increase item sorting with each item that has to be imported
         $item->setSorting(++$this->itemSorting);
         $this->importFileByFilename($filePath, $item);
         $this->itemsImported++;
     }
     $this->runPostImportAction();
 }