diff --git a/t3lib/file/Driver/AbstractDriver.php b/t3lib/file/Driver/AbstractDriver.php index 7f7327215a1fb249a4b0aa666d8b82aa110cf8d5..1745a77a4b0d1bf6cce351880e6ee15db2ef0aa0 100644 --- a/t3lib/file/Driver/AbstractDriver.php +++ b/t3lib/file/Driver/AbstractDriver.php @@ -450,21 +450,6 @@ abstract class t3lib_file_Driver_AbstractDriver { */ abstract public function getFolderInFolder($name, t3lib_file_Folder $parentFolder); - /** - * Returns TRUE if a file should be excluded from a file listing. - * - * @param string $identifier - * @param string $filename - * @return boolean - */ - protected function isHiddenFile($identifier, $filename) { - if (substr($filename, 0, 1) == '.') { - return TRUE; - } - - return FALSE; - } - /** * Applies a set of filter methods to a file name to find out if it should be used or not. This is e.g. used by * directory listings. diff --git a/t3lib/file/Driver/LocalDriver.php b/t3lib/file/Driver/LocalDriver.php index 66ac5dfb11e2a03ac7216b1b2724d305a69ca72a..f46f97bca07ca58686b9cb0f8d533faea53be7fa 100644 --- a/t3lib/file/Driver/LocalDriver.php +++ b/t3lib/file/Driver/LocalDriver.php @@ -401,7 +401,6 @@ class t3lib_file_Driver_LocalDriver extends t3lib_file_Driver_AbstractDriver { if (!is_file($filePath)) { return array('', array()); } - // TODO add unit test for existing file row case if (!empty($fileRow) && filemtime($filePath) <= $fileRow['modification_date']) { return array($fileName, $fileRow); @@ -935,7 +934,7 @@ class t3lib_file_Driver_LocalDriver extends t3lib_file_Driver_AbstractDriver { $current = $iterator->current(); $itemSubPath = $iterator->getSubPathname(); - if ($current->isDir()) { + if ($current->isDir() && !($itemSubPath === '..' || $itemSubPath === '.')) { mkdir($targetFolderPath . $itemSubPath); } elseif ($current->isFile()) { $result = copy($sourceFolderPath . $itemSubPath, $targetFolderPath . $itemSubPath); diff --git a/t3lib/file/Factory.php b/t3lib/file/Factory.php index 34bbec1ab6a41fd06ae949a30eb207a5562258f0..7b75341b3be2f8367f09f3bbbc902803393de2bc 100644 --- a/t3lib/file/Factory.php +++ b/t3lib/file/Factory.php @@ -101,6 +101,7 @@ class t3lib_file_Factory implements t3lib_Singleton { if (!$this->storageInstances[$uid]) { $storageConfiguration = NULL; + $storageObject = NULL; // If the built-in storage with UID=0 is requested: if (intval($uid) === 0) { @@ -126,14 +127,14 @@ class t3lib_file_Factory implements t3lib_Singleton { // If any other (real) storage is requested: // Get storage data if not already supplied as argument to this function } elseif (count($recordData) === 0 || $recordData['uid'] !== $uid) { - /** @var $GLOBALS['TYPO3_DB'] t3lib_DB */ - $recordData = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'sys_file_storage', 'uid=' . intval($uid) . ' AND deleted=0'); - if (!is_array($recordData)) { - throw new InvalidArgumentException('No storage found for given UID.', 1314085992); - } + /** @var $storageRepository t3lib_file_Repository_StorageRepository */ + $storageRepository = t3lib_div::makeInstance('t3lib_file_Repository_StorageRepository'); + /** @var $storage t3lib_file_Storage */ + $storageObject = $storageRepository->findByUid($uid); + } + if(!($storageObject instanceof t3lib_file_Storage)) { + $storageObject = $this->createStorageObject($recordData, $storageConfiguration); } - - $storageObject = $this->createStorageObject($recordData, $storageConfiguration); $this->storageInstances[$uid] = $storageObject; } diff --git a/t3lib/file/Storage.php b/t3lib/file/Storage.php index 029af83431f55c34817223b3f0e153b8985563e5..1c14d30643f55bc82df7b6424586d51868d2c134 100644 --- a/t3lib/file/Storage.php +++ b/t3lib/file/Storage.php @@ -1036,7 +1036,7 @@ class t3lib_file_Storage { * @return t3lib_file_FileInterface The file object */ public function createFile($fileName, t3lib_file_Folder $targetFolderObject) { - if (!$this->checkFolderActionPermission('createFile', $targetFolderObject)) { + if (!$this->checkFolderActionPermission('add', $targetFolderObject)) { throw new t3lib_file_exception_InsufficientFolderWritePermissionsException('You are not allowed to create directories on this storage "' . $targetFolderObject->getIdentifier() . '"', 1323059807); } return $this->driver->createFile($fileName, $targetFolderObject); @@ -1050,7 +1050,7 @@ class t3lib_file_Storage { * TODO throw FileInUseException when the file is still used anywhere */ public function deleteFile($fileObject) { - if (!$this->checkFileActionPermission('delete', $fileObject)) { + if (!$this->checkFileActionPermission('remove', $fileObject)) { throw new t3lib_file_exception_InsufficientFileAccessPermissionsException('You are not allowed to delete the file "' . $fileObject->getIdentifier() . "'", 1319550425); } @@ -1457,12 +1457,14 @@ class t3lib_file_Storage { * @param t3lib_file_Folder $targetParentFolder The target parent folder * @param string $newFolderName * @param string $conflictMode How to handle conflicts; one of "overrideExistingFile", "renameNewFolder", "cancel" + * @throws t3lib_exception + * @throws InvalidArgumentException * @return t3lib_file_Folder */ // TODO add tests public function moveFolder(t3lib_file_Folder $folderToMove, t3lib_file_Folder $targetParentFolder, $newFolderName = NULL, $conflictMode = 'renameNewFolder') { $sourceStorage = $folderToMove->getStorage(); - + $returnObject = NULL; if (!$targetParentFolder->getStorage() == $this) { throw new InvalidArgumentException('Cannot move a folder into a folder that does not belong to this storage.', 1325777289); } @@ -1482,18 +1484,19 @@ class t3lib_file_Storage { } else { $fileMappings = $this->moveFolderBetweenStorages($folderToMove, $targetParentFolder, $newFolderName); } - // Update the identifier and storage of all file objects foreach ($fileObjects as $oldIdentifier => $fileObject) { $newIdentifier = $fileMappings[$oldIdentifier]; $fileObject->updateProperties(array('storage' => $this, 'identifier' => $newIdentifier)); } + $returnObject = $this->getFolder($fileMappings[$folderToMove->getIdentifier()]); } catch (t3lib_exception $e) { throw $e; // TODO rollback things that have happened } $this->emitPostFolderMoveSignal($folderToMove, $targetParentFolder, $newFolderName); + return $returnObject; } /** @@ -1523,7 +1526,7 @@ class t3lib_file_Storage { public function copyFolder(t3lib_file_Folder $folderToCopy, t3lib_file_Folder $targetParentFolder, $newFolderName = NULL, $conflictMode = 'renameNewFolder') { // TODO implement the $conflictMode handling // TODO permission checks - + $returnObject = NULL; $newFolderName = $newFolderName ? $newFolderName : $folderToCopy->getName(); $this->emitPreFolderCopySignal($folderToCopy, $targetParentFolder, $newFolderName); @@ -1534,6 +1537,7 @@ class t3lib_file_Storage { try { if ($sourceStorage == $this) { $this->driver->copyFolderWithinStorage($folderToCopy, $targetParentFolder, $newFolderName); + $returnObject = $this->getFolder($targetParentFolder->getSubfolder($newFolderName)->getIdentifier()); } else { $this->copyFolderBetweenStorages($folderToCopy, $targetParentFolder, $newFolderName); } @@ -1543,6 +1547,7 @@ class t3lib_file_Storage { } $this->emitPostFolderCopySignal($folderToCopy, $targetParentFolder, $newFolderName); + return $returnObject; } /** @@ -1568,15 +1573,17 @@ class t3lib_file_Storage { /** * Previously in t3lib_extFileFunc::folder_move() * - * @throws RuntimeException if an error occurs during renaming + * * @param t3lib_file_Folder $folderObject * @param string $newName - * @return bool TRUE if the operation succeeded + * @throws Exception + * @throws InvalidArgumentException + * @return t3lib_file_Folder */ public function renameFolder($folderObject, $newName) { // TODO unit tests // TODO access checks - + $returnObject = NULL; if ($this->driver->folderExistsInFolder($newName, $folderObject)) { throw new InvalidArgumentException("The folder $newName already exists in folder " . $folderObject->getIdentifier(), 1325418870); } @@ -1586,29 +1593,31 @@ class t3lib_file_Storage { $fileObjects = $this->getAllFileObjectsInFolder($folderObject); try { $fileMappings = $this->driver->renameFolder($folderObject, $newName); - // Update the identifier of all file objects foreach ($fileObjects as $oldIdentifier => $fileObject) { $newIdentifier = $fileMappings[$oldIdentifier]; $fileObject->updateProperties(array('identifier' => $newIdentifier)); } + $returnObject = $this->getFolder($fileMappings[$folderObject->getIdentifier()]); } catch (Exception $e) { throw $e; } - $this->emitPostFolderRenameSignal($folderObject, $newName); + return $returnObject; } /** * Previously in t3lib_extFileFunc::folder_delete() * - * @param t3lib_file_Folder $folderObject + * @param t3lib_file_Folder $folderObject * @param bool $deleteRecursively + * @throws RuntimeException + * @throws t3lib_file_exception_InsufficientFileAccessPermissionsException * @return bool */ public function deleteFolder($folderObject, $deleteRecursively = FALSE) { - if (!$this->checkFolderActionPermission('delete', $folderObject)) { + if (!$this->checkFolderActionPermission('remove', $folderObject)) { throw new t3lib_file_exception_InsufficientFileAccessPermissionsException('You are not allowed to access the folder "' . $folderObject->getIdentifier() . "'", 1323423953); } @@ -1618,9 +1627,11 @@ class t3lib_file_Storage { $this->emitPreFolderDeleteSignal($folderObject); - $this->driver->deleteFolder($folderObject, $deleteRecursively); + $result = $this->driver->deleteFolder($folderObject, $deleteRecursively); $this->emitPostFolderDeleteSignal($folderObject); + + return $result; } /** @@ -1701,7 +1712,7 @@ class t3lib_file_Storage { throw new InvalidArgumentException('Parent folder "' . $parentFolder->getIdentifier() . '" does not exist.', 1325689164); } - if (!$this->checkFolderActionPermission('createFolder', $parentFolder)) { + if (!$this->checkFolderActionPermission('add', $parentFolder)) { throw new t3lib_file_exception_InsufficientFolderWritePermissionsException( 'You are not allowed to create directories in the folder "' . $parentFolder->getIdentifier() . '"', 1323059807); } diff --git a/tests/t3lib/class.t3lib_extfilefuncTest.php b/tests/t3lib/class.t3lib_extfilefuncTest.php index e672616c253038fa8cc6f667a5d90cfed356745c..20c9249ae0ceace6dfea1977d20de98f9654e6dd 100644 --- a/tests/t3lib/class.t3lib_extfilefuncTest.php +++ b/tests/t3lib/class.t3lib_extfilefuncTest.php @@ -256,7 +256,7 @@ class t3lib_extFileFunctionsTest extends tx_phpunit_testcase { $this->fileProcessor->start($fileValues); $results = $this->fileProcessor->processData(); - $this->assertEquals(TRUE, empty ($results['delete'][1])); + $this->assertEquals(TRUE, $results['delete'][0]); } /********************************* @@ -430,7 +430,7 @@ class t3lib_extFileFunctionsTest extends tx_phpunit_testcase { $this->objectsToTearDown[] = $results['newfolder'][0]; } - $this->assertEquals(TRUE, $folderObject instanceof t3lib_file_File); + $this->assertEquals(TRUE, $folderObject instanceof t3lib_file_Folder); } /********************************* @@ -492,12 +492,12 @@ class t3lib_extFileFunctionsTest extends tx_phpunit_testcase { */ public function copyFolderInLocalStorage() { - // Computes a $folderIdentifier which looks like 8:/folderName.txt where 8 is the storage Uid + // Computes a $folderIdentifier which looks like 8:/folderName.txt where 8 is the storage Uid $storage = $this->getDefaultStorage(); $folderIdentifier = $storage->getUid() . ':/' . $this->copyFolderNameInput; $targetFolder = $this->getRootFolderIdentifier() . $this->newFolderNameInput; - // Defines values + // Defines values $fileValues = array( 'newfolder' => array( array( @@ -525,7 +525,7 @@ class t3lib_extFileFunctionsTest extends tx_phpunit_testcase { $folderObject = $results['copy'][0]; } - // remove parent folder + // remove parent folder if (!empty ($results['newfolder'][0])) { $this->objectsToTearDown[] = $results['newfolder'][0]; } @@ -533,58 +533,7 @@ class t3lib_extFileFunctionsTest extends tx_phpunit_testcase { $this->objectsToTearDown[] = $results['newfolder'][1]; } - $this->assertEquals(TRUE, $folderObject instanceof t3lib_file_File); - } - - /********************************* - * UPLOAD - ********************************/ - /** - * @test - */ - public function uploadFileInLocalStorage() { - - // Computes a $fileIdentifier which looks like 8:/fileName.txt where 8 is the storage Uid - $storage = $this->getDefaultStorage(); - $fileIdentifier = $storage->getUid() . ':/' . $this->newFileNameInput; - $targetFolder = $this->getRootFolderIdentifier() . $this->newFolderNameInput; - - // creates fake file - $tmpFile = '/tmp/php5Wx0aJ'; - touch ($tmpFile); - - $_FILES['upload_phpunit'] = array( - 'name' => $this->newFileNameInput, - 'type' => 'text/plain', - 'tmp_name' => $tmpFile, - 'error' => 0, - 'size' => 10, - ); - - // Defines values - $fileValues = array( - 'upload' => array( - array( - 'data' => 'phpunit', - 'target' => $this->getRootFolderIdentifier(), - ) - ), - ); - - $this->fileProcessor->start($fileValues); - $results = $this->fileProcessor->processData(); - - $fileObject = NULL; - if (!empty ($results['upload'][0])) { - $fileObject = $results['upload'][0]; - } - - print '<b>Test does not work because of function is_uploaded_file() which is not faked yet @t3lib_file_Storage:820@ </b><br/>'; - - $this->objectsToTearDown[] = $fileObject; - unlink($tmpFile); // delete - - $this->assertEquals(TRUE, $fileObject instanceof t3lib_file_File); + $this->assertEquals(TRUE, $folderObject instanceof t3lib_file_Folder); } } diff --git a/tests/t3lib/file/Driver/LocalDriverTest.php b/tests/t3lib/file/Driver/LocalDriverTest.php index 39e8d93edcbae8075ffc9d8968310e2ca02bc4f4..84135340dda59a4afdffe4b1a94792da4a32e990 100644 --- a/tests/t3lib/file/Driver/LocalDriverTest.php +++ b/tests/t3lib/file/Driver/LocalDriverTest.php @@ -362,9 +362,12 @@ class t3lib_file_Driver_LocalDriverTest extends t3lib_file_BaseTestCase { 'file' => 'asdf' ) )); + $storageObject = $this->getMock('t3lib_file_Storage', array(), array(), '', FALSE); + $storageObject->expects($this->any())->method('getUid')->will($this->returnValue('1')); + $fixture = $this->createDriverFixture(array( 'basePath' => $this->getMountRootUrl() - )); + ), $storageObject); $fixture->addFile($this->getUrlInMount('/targetFolder/file'), $mockedFolder, 'file'); } @@ -674,21 +677,39 @@ class t3lib_file_Driver_LocalDriverTest extends t3lib_file_BaseTestCase { /** * @test */ - public function getFileListDoesNotReturnHiddenFilesByDefault() { + public function getFileListCallsConfiguredCallbackFunctionWithGivenItemName() { $dirStructure = array( - 'aDir' => array(), - '.someHiddenFile' => 'asdf', - 'file1' => 'asdfg', 'file2' => 'fdsa' + ); + // register static callback to self + $callback = array( + array ( + get_class($this), + 'callbackStaticTestFunction' + ) ); $this->addToMount($dirStructure); $fixture = $this->createDriverFixture(array( 'basePath' => $this->getMountRootUrl() )); + // the callback function will throw an exception used to check if it was called with correct $itemName + $this->setExpectedException('InvalidArgumentException', '$itemName', 1336159604); + $fixture->getFileList('/', 0, 0, $callback); + } - $fileList = $fixture->getFileList('/'); - - $this->assertEquals(array('file1', 'file2'), array_keys($fileList)); + /** + * Static callback function used to test if the filter callbacks work + * As it is static we are using an exception to test if it is really called and works + * + * @static + * @throws InvalidArgumentException + * @see getFileListCallsConfiguredCallbackFunction + */ + public static function callbackStaticTestFunction() { + list($itemName) = func_get_args(); + if($itemName === 'file2') { + throw new InvalidArgumentException('$itemName', 1336159604); + } } /**