The drivers in FAL are capable of retrieving files recursively.
This might be sinful in some cases and custom usages. Anyhow,
the parameter $recursive is not passed up until Storage and
Folder objects. With that users are forced to work with the
driver directly.
As it is highly discouraged to work directly on the driver,
just pass up the parameter within the abstraction layers.
Change-Id: Ibe8f9aa9e906617a42a9a7d5edba43f24f613587
Releases: 6.0
Fixes: #43249
Reviewed-on: http://review.typo3.org/16697
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
* @param array $filterMethods The filter methods used to filter the directory items
* @param string $itemHandlerMethod
* @param array $itemRows
+ * @param boolean $recursive
* @return array
*/
- protected function getDirectoryItemList($path, $start, $numberOfItems, array $filterMethods, $itemHandlerMethod, $itemRows = array()) {
+ protected function getDirectoryItemList($path, $start, $numberOfItems, array $filterMethods, $itemHandlerMethod, $itemRows = array(), $recursive = FALSE) {
}
* @param integer $numberOfItems The number of items to list; if not set, return all items
* @param array $filenameFilterCallbacks The method callbacks to use for filtering the items
* @param array $fileData Two-dimensional, identifier-indexed array of file index records from the database
+ * @param boolean $recursive
* @return array
*/
// TODO add unit tests
- public function getFileList($path, $start = 0, $numberOfItems = 0, array $filenameFilterCallbacks = array(), $fileData = array()) {
- return $this->getDirectoryItemList($path, $start, $numberOfItems, $filenameFilterCallbacks, $this->fileListCallbackMethod, $fileData);
+ public function getFileList($path, $start = 0, $numberOfItems = 0, array $filenameFilterCallbacks = array(), $fileData = array(), $recursive = FALSE) {
+ return $this->getDirectoryItemList($path, $start, $numberOfItems, $filenameFilterCallbacks, $this->fileListCallbackMethod, $fileData, $recursive);
}
/**
* @param integer $start The position to start the listing; if not set, start from the beginning
* @param integer $numberOfItems The number of items to list; if not set, return all items
* @param array $foldernameFilterCallbacks The method callbacks to use for filtering the items
+ * @param boolean $recursive
* @return array
*/
- public function getFolderList($path, $start = 0, $numberOfItems = 0, array $foldernameFilterCallbacks = array()) {
- return $this->getDirectoryItemList($path, $start, $numberOfItems, $foldernameFilterCallbacks, $this->folderListCallbackMethod);
+ public function getFolderList($path, $start = 0, $numberOfItems = 0, array $foldernameFilterCallbacks = array(), $recursive = FALSE) {
+ return $this->getDirectoryItemList($path, $start, $numberOfItems, $foldernameFilterCallbacks, $this->folderListCallbackMethod, $recursive);
}
/**
* @param array $filterMethods The filter methods used to filter the directory items
* @param string $itemHandlerMethod The method (in this class) that handles the single iterator elements.
* @param array $itemRows
+ * @param boolean $recursive
* @return array
*/
// TODO add unit tests
- protected function getDirectoryItemList($path, $start, $numberOfItems, array $filterMethods, $itemHandlerMethod, $itemRows = array()) {
+ protected function getDirectoryItemList($path, $start, $numberOfItems, array $filterMethods, $itemHandlerMethod, $itemRows = array(), $recursive = FALSE) {
$realPath = rtrim(($this->absoluteBasePath . trim($path, '/')), '/') . '/';
if (!is_dir($realPath)) {
throw new \InvalidArgumentException('Cannot list items in directory ' . $path . ' - does not exist or is no directory', 1314349666);
// Fetch the files and folders and sort them by name; we have to do
// this here because the directory iterator does return them in
// an arbitrary order
- $items = $this->getFileAndFoldernamesInPath($realPath);
+ $items = $this->getFileAndFoldernamesInPath($realPath, $recursive);
natcasesort($items);
$iterator = new \ArrayIterator($items);
if ($iterator->count() == 0) {
* @param integer $start The item to start at
* @param integer $numberOfItems The number of items to return
* @param integer $filterMode The filter mode to use for the file list.
+ * @param boolean $recursive
* @return \TYPO3\CMS\Core\Resource\File[]
*/
- public function getFiles($start = 0, $numberOfItems = 0, $filterMode = self::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS) {
+ public function getFiles($start = 0, $numberOfItems = 0, $filterMode = self::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, $recursive = FALSE) {
$useFilters = TRUE;
// Fallback for compatibility with the old method signature variable $useFilters that was used instead of $filterMode
/** @var $factory \TYPO3\CMS\Core\Resource\ResourceFactory */
$factory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
- $fileArray = $this->storage->getFileList($this->identifier, $start, $numberOfItems, $useFilters);
+ $fileArray = $this->storage->getFileList($this->identifier, $start, $numberOfItems, $useFilters, TRUE, $recursive);
$fileObjects = array();
foreach ($fileArray as $fileInfo) {
$fileObjects[$fileInfo['name']] = $factory->createFileObject($fileInfo);
* @param array $filterMethods
* @return integer
*/
- public function getFileCount(array $filterMethods = array()) {
+ public function getFileCount(array $filterMethods = array(), $recursive = FALSE) {
// TODO replace by call to count()
- return count($this->storage->getFileList($this->identifier, 0, 0, $filterMethods));
+ return count($this->storage->getFileList($this->identifier, 0, 0, $filterMethods, FALSE, $recursive));
}
/**
* @param integer $numberOfItems The number of items to list; if not set, return all items
* @param bool $useFilters If FALSE, the list is returned without any filtering; otherwise, the filters defined for this storage are used.
* @param bool $loadIndexRecords If set to TRUE, the index records for all files are loaded from the database. This can greatly improve performance of this method, especially with a lot of files.
+ * @param boolean $recursive
* @return array Information about the files found.
*/
// TODO check if we should use a folder object instead of $path
// TODO add unit test for $loadIndexRecords
- public function getFileList($path, $start = 0, $numberOfItems = 0, $useFilters = TRUE, $loadIndexRecords = TRUE) {
+ public function getFileList($path, $start = 0, $numberOfItems = 0, $useFilters = TRUE, $loadIndexRecords = TRUE, $recursive = FALSE) {
$rows = array();
if ($loadIndexRecords) {
/** @var $repository \TYPO3\CMS\Core\Resource\FileRepository */
$rows = $repository->getFileIndexRecordsForFolder($this->getFolder($path));
}
$filters = $useFilters == TRUE ? $this->fileAndFolderNameFilters : array();
- $items = $this->driver->getFileList($path, $start, $numberOfItems, $filters, $rows);
+ $items = $this->driver->getFileList($path, $start, $numberOfItems, $filters, $rows, $recursive);
uksort($items, 'strnatcasecmp');
return $items;
}
* @param int $start
* @param int $numberOfItems
* @param array $folderFilterCallbacks
+ * @param boolean $recursive
* @return array
*/
- public function fetchFolderListFromDriver($path, $start = 0, $numberOfItems = 0, array $folderFilterCallbacks = array()) {
- $items = $this->driver->getFolderList($path, $start, $numberOfItems, $folderFilterCallbacks);
+ public function fetchFolderListFromDriver($path, $start = 0, $numberOfItems = 0, array $folderFilterCallbacks = array(), $recursive = FALSE) {
+ $items = $this->driver->getFolderList($path, $start, $numberOfItems, $folderFilterCallbacks, $recursive);
// Exclude the _processed_ folder, so it won't get indexed etc
$processingFolder = $this->getProcessingFolder();
if ($processingFolder && $path == '/') {
$this->assertEquals(array('somefile.png', 'somefile.jpg'), array_keys($fileList));
}
+ /**
+ * @test
+ */
+ public function getFilesHandsOverRecursiveFALSEifNotExplicitlySet() {
+ $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
+ $mockedStorage
+ ->expects($this->once())
+ ->method('getFileList')
+ ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), FALSE)
+ ->will($this->returnValue(array()));
+
+ $fixture = $this->createFolderFixture('/somePath', 'someName', $mockedStorage);
+ $fixture->getFiles();
+ }
+
+ /**
+ * @test
+ */
+ public function getFilesHandsOverRecursiveTRUEifSet() {
+ $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
+ $mockedStorage
+ ->expects($this->once())
+ ->method('getFileList')
+ ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), TRUE)
+ ->will($this->returnValue(array()));
+
+ $fixture = $this->createFolderFixture('/somePath', 'someName', $mockedStorage);
+ $fixture->getFiles(0, 0, \TYPO3\CMS\Core\Resource\Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, TRUE);
+ }
+
/**
* @test
*/
$this->fixture->replaceFile($mockedFile, PATH_site . uniqid());
}
+ /**
+ * @test
+ */
+ public function getFileListHandsOverRecursiveFALSEifNotExplicitlySet() {
+ $this->prepareFixture(array());
+ $driver = $this->createDriverMock(array('basePath' => $this->getMountRootUrl()), $this->fixture, array('getFileList'));
+ $driver->expects($this->once())
+ ->method('getFileList')
+ ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), FALSE)
+ ->will($this->returnValue(array()));
+ $this->fixture->getFileList('/');
+ }
+
+ /**
+ * @test
+ */
+ public function getFileListHandsOverRecursiveTRUEifSet() {
+
+ $this->prepareFixture(array());
+ $driver = $this->createDriverMock(array('basePath' => $this->getMountRootUrl()), $this->fixture, array('getFileList'));
+ $driver->expects($this->once())
+ ->method('getFileList')
+ ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), TRUE)
+ ->will($this->returnValue(array()));
+ $this->fixture->getFileList('/', 0, 0, TRUE, TRUE, TRUE);
+ }
+
}
?>
\ No newline at end of file