/** * @test */ public function getFilesForGivenDirectoryReturnsFilesForDirectory() { $testingDirectory = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('yag') . 'Tests/Unit/Domain/Import/FilesForCrawlerTest'; $crawledFiles = $this->fixture->getFilesForGivenDirectory($testingDirectory); $this->assertTrue(in_array($testingDirectory . '/test1.jpg', $crawledFiles)); $this->assertTrue(in_array($testingDirectory . '/test2.jpg', $crawledFiles)); $this->assertTrue(in_array($testingDirectory . '/test3.jpeg', $crawledFiles)); $this->assertTrue(!in_array($testingDirectory . '/test4.nonjpg', $crawledFiles)); }
/** * 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(); }