163 $this->capabilities =
164 ($this->storageRecord[
'is_browsable'] ? self::CAPABILITY_BROWSABLE : 0) |
165 ($this->storageRecord[
'is_public'] ? self::CAPABILITY_PUBLIC : 0) |
166 ($this->storageRecord[
'is_writable'] ? self::CAPABILITY_WRITABLE : 0);
169 $this->driver->setStorageUid($storageRecord[
'uid']);
170 $this->driver->mergeConfigurationCapabilities($this->capabilities);
172 $this->driver->processConfiguration();
173 }
catch (
Exception\InvalidConfigurationException $e) {
178 $this->driver->initialize();
179 $this->capabilities = $this->driver->getCapabilities();
181 $this->
isDefault = (isset($storageRecord[
'is_default']) && $storageRecord[
'is_default'] == 1);
240 throw new \BadMethodCallException(
241 'Function TYPO3\\CMS\\Core\\Resource\\ResourceStorage::getFolderByIdentifier() has been renamed to just getFolder(). Please fix the method call.',
254 throw new \BadMethodCallException(
255 'Function TYPO3\\CMS\\Core\\Resource\\ResourceStorage::getFileByIdentifier() has been renamed to just getFileInfoByIdentifier(). ' .
'Please fix the method call.',
266 return $this->storageRecord[
'name'];
275 return (
int)$this->storageRecord[
'uid'];
307 return ($this->capabilities & $capability) == $capability;
347 return $this->driver->isCaseSensitiveFileSystem();
357 if ($this->
getUid() === 0) {
361 if ($this->storageRecord[
'is_online'] == 0) {
371 $offlineUntil = $registryObject->get(
'core',
'sys_file_storage-' . $this->
getUid() .
'-offline-until');
372 if ($offlineUntil && $offlineUntil > time()) {
393 if ($this->
getUid() > 0) {
395 $GLOBALS[
'TYPO3_DB']->exec_UPDATEquery(
'sys_file_storage',
'uid=' . (
int)$this->
getUid(), array(
'is_online' => 0));
397 $this->storageRecord[
'is_online'] = 0;
411 $registryObject->set(
'core',
'sys_file_storage-' . $this->
getUid() .
'-offline-until', time() + 60 * 5);
412 $this->storageRecord[
'is_online'] = 0;
429 public function addFileMount($folderIdentifier, $additionalData = array()) {
431 if ($this->driver->folderExists($folderIdentifier) === FALSE) {
434 throw new Exception\FolderDoesNotExistException(
'Folder for file mount ' . $folderIdentifier .
' does not exist.', 1334427099);
436 $data = $this->driver->getFolderInfoByIdentifier($folderIdentifier);
439 $folderIdentifier = $folderObject->getIdentifier();
441 !empty($this->fileMounts[$folderIdentifier])
442 && empty($this->fileMounts[$folderIdentifier][
'read_only'])
443 && !empty($additionalData[
'read_only'])
448 if (empty($additionalData)) {
449 $additionalData = array(
450 'path' => $folderIdentifier,
451 'title' => $folderIdentifier,
452 'folder' => $folderObject
455 $additionalData[
'folder'] = $folderObject;
456 if (!isset($additionalData[
'title'])) {
457 $additionalData[
'title'] = $folderIdentifier;
460 $this->fileMounts[$folderIdentifier] = $additionalData;
481 if (!$this->evaluatePermissions) {
484 $isWithinFileMount = FALSE;
488 $identifier = $subject->getIdentifier();
492 $isWithinFileMount = TRUE;
496 $writableFileMountAvailable = FALSE;
497 foreach ($this->fileMounts as $fileMount) {
498 if ($this->driver->isWithin($fileMount[
'folder']->getIdentifier(), $identifier)) {
499 $isWithinFileMount = TRUE;
500 if (!$checkWriteAccess) {
502 } elseif (empty($fileMount[
'read_only'])) {
503 $writableFileMountAvailable = TRUE;
508 $isWithinFileMount = $checkWriteAccess ? $writableFileMountAvailable : $isWithinFileMount;
510 return $isWithinFileMount;
552 if (!$this->evaluatePermissions) {
557 if (!empty($this->userPermissions[strtolower($action) . ucfirst(strtolower($type))])) {
587 $isReadCheck = FALSE;
588 if (in_array($action, array(
'read',
'copy',
'move'), TRUE)) {
591 $isWriteCheck = FALSE;
592 if (in_array($action, array(
'add',
'write',
'move',
'rename',
'unzip',
'delete'), TRUE)) {
593 $isWriteCheck = TRUE;
602 if (!$isProcessedFile && $file instanceof
File) {
603 $isMissing = $file->isMissing();
606 if ($this->driver->fileExists($file->
getIdentifier()) === FALSE) {
607 $file->setMissing(TRUE);
612 if ($isWriteCheck && ($isMissing || !$this->
isWritable())) {
618 $filePermissions = $this->driver->getPermissions($file->
getIdentifier());
619 if ($isReadCheck && !$filePermissions[
'r']) {
622 if ($isWriteCheck && !$filePermissions[
'w']) {
646 if ($folder === NULL) {
650 $isReadCheck = FALSE;
651 if (in_array($action, array(
'read',
'copy'), TRUE)) {
654 $isWriteCheck = FALSE;
655 if (in_array($action, array(
'add',
'move',
'write',
'delete',
'rename'), TRUE)) {
656 $isWriteCheck = TRUE;
672 $folderPermissions = $this->driver->getPermissions($folder->getIdentifier());
673 if ($isReadCheck && !$folderPermissions[
'r']) {
676 if ($isWriteCheck && !$folderPermissions[
'w']) {
690 $fileName = $this->driver->sanitizeFileName($fileName);
692 if ($isAllowed && $this->evaluatePermissions) {
695 $fileExtensionPermissions =
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'fileExtensions'][
'webspace'];
698 if ($fileExtension !==
'') {
700 if ($fileExtensionPermissions[
'allow'] ===
'*' ||
GeneralUtility::inList($fileExtensionPermissions[
'allow'], $fileExtension)) {
704 if ($fileExtensionPermissions[
'deny'] ===
'*' ||
GeneralUtility::inList($fileExtensionPermissions[
'deny'], $fileExtension)) {
710 if ($fileExtensionPermissions[
'allow'] ===
'*') {
713 if ($fileExtensionPermissions[
'deny'] ===
'*') {
731 if ($folder === NULL) {
732 throw new Exception\InsufficientFolderAccessPermissionsException(
733 'You are not allowed to read folders',
737 throw new Exception\InsufficientFolderAccessPermissionsException(
738 'You are not allowed to access the given folder: "' . $folder->getName() .
'"',
758 throw new Exception\InsufficientUserPermissionsException(
'You are not allowed to delete folders recursively', 1377779423);
762 throw new Exception\InsufficientFolderAccessPermissionsException(
'You are not allowed to delete the given folder', 1377779039);
768 throw new Exception\InsufficientFolderWritePermissionsException(
'Writing to folders is not allowed.', 1377779111);
782 throw new Exception\InsufficientFileAccessPermissionsException(
'You are not allowed to access that file.', 1375955429);
785 throw new Exception\IllegalFileExtensionException(
'You are not allowed to use that file extension', 1375955430);
801 throw new Exception\InsufficientFileWritePermissionsException(
'Writing to file "' . $file->
getIdentifier() .
'" is not allowed.', 1330121088);
804 throw new Exception\IllegalFileExtensionException(
'You are not allowed to edit a file with extension "' . $file->
getExtension() .
'"', 1366711933);
820 throw new Exception\IllegalFileExtensionException(
'You are not allowed to delete a file with extension "' . $file->
getExtension() .
'"', 1377778916);
826 throw new Exception\InsufficientFileWritePermissionsException(
'You are not allowed to delete the file "' . $file->
getIdentifier() .
'"', 1319550425);
832 throw new Exception\InsufficientFolderWritePermissionsException(
'Writing to folders is not allowed.', 1377778702);
855 throw new Exception\IllegalFileExtensionException(
'Extension of file name is not allowed in "' . $targetFileName .
'"!', 1322120271);
859 throw new Exception\InsufficientUserPermissionsException(
'You are not allowed to add files to this storage "' . $this->
getUid() .
'"', 1376992145);
863 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to write to the target folder "' . $targetFolder->getIdentifier() .
'"', 1322120356);
885 if (!is_uploaded_file($localFilePath)) {
886 throw new Exception\UploadException(
'The upload has failed, no uploaded file found!', 1322110455);
890 if ($uploadedFileSize >= $maxUploadFileSize) {
891 unlink($localFilePath);
892 throw new Exception\UploadSizeException(
'The uploaded file exceeds the size-limit of ' . $maxUploadFileSize .
' bytes', 1322110041);
912 throw new \RuntimeException();
916 throw new Exception\IllegalFileExtensionException(
'Extension of file name is not allowed in "' . $targetFileName .
'"!', 1378243279);
919 if (!$file->
getStorage()->checkFileActionPermission(
'move', $file)) {
920 throw new Exception\InsufficientUserPermissionsException(
'You are not allowed to move files to storage "' . $this->
getUid() .
'"', 1319219349);
924 throw new Exception\InsufficientFolderAccessPermissionsException(
'You are not allowed to write to the target folder "' . $targetFolder->
getIdentifier() .
'"', 1319219350);
942 throw new Exception\IllegalFileExtensionException(
'You are not allowed to rename a file with to this extension', 1371466663);
946 throw new Exception\InsufficientUserPermissionsException(
'You are not allowed to rename files."', 1319219351);
953 throw new Exception\InsufficientFileWritePermissionsException(
'You are not allowed to write to folders', 1319219352);
975 throw new Exception(
'The operation of the folder cannot be called by this storage "' . $this->
getUid() .
'"', 1319550405);
978 if (!$file->
getStorage()->checkFileActionPermission(
'copy', $file)) {
979 throw new Exception\InsufficientFileReadPermissionsException(
'You are not allowed to copy the file "' . $file->
getIdentifier() .
'"', 1319550426);
983 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to write to the target folder "' . $targetFolder->
getIdentifier() .
'"', 1319550435);
987 throw new Exception\IllegalFileExtensionException(
'You are not allowed to copy a file of that type.', 1319553317);
1009 throw new Exception(
'The operation of the folder cannot be called by this storage "' . $this->
getUid() .
'"', 1377777624);
1011 if (!$folderToCopy instanceof
Folder) {
1012 throw new \RuntimeException(
'The folder "' . $folderToCopy->
getIdentifier() .
'" to copy is not of type Folder.', 1384209020);
1015 if (!$folderToCopy->
getStorage()->checkFolderActionPermission(
'copy', $folderToCopy)) {
1016 throw new Exception\InsufficientFileReadPermissionsException(
'You are not allowed to copy the folder "' . $folderToCopy->
getIdentifier() .
'"', 1377777629);
1018 if (!$targetParentFolder instanceof Folder) {
1019 throw new \RuntimeException(
'The target folder "' . $targetParentFolder->
getIdentifier() .
'" is not of type Folder.', 1384209021);
1023 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to write to the target folder "' . $targetParentFolder->
getIdentifier() .
'"', 1377777635);
1045 throw new \InvalidArgumentException(
'Cannot move a folder into a folder that does not belong to this storage.', 1325777289);
1047 if (!$folderToMove instanceof
Folder) {
1048 throw new \RuntimeException(
'The folder "' . $folderToMove->
getIdentifier() .
'" to move is not of type Folder.', 1384209022);
1053 if (!$folderToMove->
getStorage()->checkFolderActionPermission(
'move', $folderToMove)) {
1054 throw new Exception\InsufficientFileReadPermissionsException(
'You are not allowed to copy the folder "' . $folderToMove->
getIdentifier() .
'"', 1377778045);
1056 if (!$targetParentFolder instanceof Folder) {
1057 throw new \RuntimeException(
'The target folder "' . $targetParentFolder->
getIdentifier() .
'" is not of type Folder.', 1384209023);
1061 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to write to the target folder "' . $targetParentFolder->
getIdentifier() .
'"', 1377778049);
1080 public function addFile($localFilePath,
Folder $targetFolder, $targetFileName =
'', $conflictMode =
'changeName') {
1083 if (!is_uploaded_file($localFilePath) && !file_exists($localFilePath)) {
1084 throw new \InvalidArgumentException(
'File "' . $localFilePath .
'" does not exist.', 1319552745);
1087 $targetFileName = $this->driver->sanitizeFileName($targetFileName ?:
PathUtility::basename($localFilePath));
1094 if ($conflictMode ===
'cancel' && $this->driver->fileExistsInFolder($targetFileName, $targetFolder->
getIdentifier())) {
1095 throw new Exception\ExistingTargetFileNameException(
'File "' . $targetFileName .
'" already exists in folder ' . $targetFolder->
getIdentifier(), 1322121068);
1096 } elseif ($conflictMode ===
'changeName') {
1097 $targetFileName = $this->
getUniqueName($targetFolder, $targetFileName);
1100 $fileIdentifier = $this->driver->addFile($localFilePath, $targetFolder->
getIdentifier(), $targetFileName);
1119 if (!file_exists($localFilePath)) {
1120 throw new \InvalidArgumentException(
'File "' . $localFilePath .
'" does not exist.', 1319552746);
1125 $fileIdentifier = $this->driver->addFile($localFilePath,
$processingFolder->getIdentifier(), $processedFile->
getName());
1129 return $processedFile;
1152 return $this->driver->hash($fileIdentifier, $hash);
1163 public function hashFileIdentifier($file) {
1166 $file = $file->getIdentifier();
1168 return $this->driver->hashIdentifier($file);
1187 if ($publicUrl === NULL) {
1190 $publicUrl = $this->driver->getPublicUrl($resourceObject->
getIdentifier());
1193 if ($publicUrl === NULL && $resourceObject instanceof
FileInterface) {
1194 $queryParameterArray = array(
'eID' =>
'dumpFile',
't' =>
'');
1195 if ($resourceObject instanceof
File) {
1196 $queryParameterArray[
'f'] = $resourceObject->getUid();
1197 $queryParameterArray[
't'] =
'f';
1199 $queryParameterArray[
'p'] = $resourceObject->getUid();
1200 $queryParameterArray[
't'] =
'p';
1203 $queryParameterArray[
'token'] =
GeneralUtility::hmac(implode(
'|', $queryParameterArray),
'resourceStorageDumpFile');
1204 $publicUrl =
'index.php?' . str_replace(
'+',
'%20', http_build_query($queryParameterArray));
1212 $filePart = substr(PATH_site . $publicUrl, strlen($absolutePathToContainingFolder) + 1);
1213 $publicUrl = $pathPart . $filePart;
1232 throw new \InvalidArgumentException(
'Cannot process files of foreign storage', 1353401835);
1236 return $processedFile;
1247 $filePath = $this->driver->getFileForLocalProcessing($fileObject->
getIdentifier(), $writable);
1258 $file = $this->
getFileFactory()->getFileObjectByStorageAndIdentifier($this->
getUid(), $identifier);
1259 if (!$this->driver->fileExists($identifier)) {
1260 $file->setMissing(TRUE);
1285 return $this->driver->getFileInfoByIdentifier($identifier, $propertiesToExtract);
1294 $this->fileAndFolderNameFilters = array();
1303 $this->fileAndFolderNameFilters =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'fal'][
'defaultFilterCallbacks'];
1320 $this->fileAndFolderNameFilters = $filters;
1328 $this->fileAndFolderNameFilters[] = $filter;
1337 return $this->driver->getParentFolderIdentifierOfIdentifier($fileIdentifier);
1353 public function getFileList($path, $start = 0, $numberOfItems = 0, $useFilters = TRUE, $loadIndexRecords = TRUE, $recursive = FALSE) {
1366 public function getFilesInFolder(
Folder $folder, $start = 0, $maxNumberOfItems = 0, $useFilters = TRUE, $recursive = FALSE) {
1371 $filters = $useFilters == TRUE ? $this->fileAndFolderNameFilters : array();
1372 $fileIdentifiers = array_values($this->driver->getFilesInFolder($folder->
getIdentifier(), $start, $maxNumberOfItems, $recursive, $filters));
1373 $fileIdentifiersCount = count($fileIdentifiers);
1375 if ($maxNumberOfItems === 0) {
1376 $maxNumberOfItems = $fileIdentifiersCount;
1378 $end = min($fileIdentifiersCount, $start + $maxNumberOfItems);
1379 for ($i = $start; $i < $end; $i++) {
1380 $identifier = $fileIdentifiers[$i];
1381 if (isset($rows[$identifier])) {
1382 $fileObject = $this->
getFileFactory()->getFileObject($rows[$identifier][
'uid'], $rows[$identifier]);
1384 $fileObject = $this->
getFileFactory()->getFileObjectByStorageAndIdentifier($this->
getUid(), $identifier);
1387 $key = $fileObject->getName();
1388 while (isset($items[$key])) {
1391 $items[$key] = $fileObject;
1394 uksort($items,
'strnatcasecmp');
1407 $filters = $useFilters == TRUE ? $this->fileAndFolderNameFilters : array();
1408 return $this->driver->getFilesInFolder($folderIdentifier, 0, 0, $recursive, $filters);
1419 $filters = $useFilters == TRUE ? $this->fileAndFolderNameFilters : array();
1420 return $this->driver->getFoldersInFolder($folderIdentifier, 0, 0, $recursive, $filters);
1434 return $this->driver->fileExists($identifier);
1442 public function getProcessingFolders() {
1443 if ($this->processingFolders === NULL) {
1444 $this->processingFolders = array();
1448 $allStorages = $storageRepository->findAll();
1449 foreach ($allStorages as $storage) {
1454 if (empty($processingFolderIdentifier) || (
int)$storageUid !== $this->
getUid()) {
1457 $potentialProcessingFolder =
ResourceFactory::getInstance()->getInstance()->createFolderObject($this, $processingFolderIdentifier, $processingFolderIdentifier);
1458 if ($potentialProcessingFolder->getStorage() === $this && $potentialProcessingFolder->getIdentifier() !== $this->
getProcessingFolder()->getIdentifier()) {
1459 $this->processingFolders[] = $potentialProcessingFolder;
1475 $isProcessingFolder = FALSE;
1478 $isProcessingFolder = TRUE;
1482 return $isProcessingFolder;
1494 return $this->driver->fileExistsInFolder($fileName, $folder->
getIdentifier());
1507 return $this->driver->getFileContents($file->getIdentifier());
1520 $downloadName = $alternativeFilename ?: $file->
getName();
1521 $contentDisposition = $asDownload ?
'attachment' :
'inline';
1522 header(
'Content-Disposition: ' . $contentDisposition .
'; filename="' . $downloadName .
'"');
1524 header(
'Content-Length: ' . $file->
getSize());
1528 header(
"Cache-Control: ''");
1529 header(
'Last-Modified: ' .
1530 gmdate(
'D, d M Y H:i:s', array_pop($this->driver->getFileInfoByIdentifier($file->
getIdentifier(), array(
'mtime')))) .
' GMT',
1536 while (ob_get_level() > 0) {
1558 $this->
getIndexer()->updateIndexEntry($file);
1577 $newFileIdentifier = $this->driver->createFile($fileName, $targetFolderObject->
getIdentifier());
1595 if ($this->driver->fileExists($fileObject->getIdentifier())) {
1596 $result = $this->driver->deleteFile($fileObject->getIdentifier());
1598 throw new Exception\FileOperationErrorException(
'Deleting the file "' . $fileObject->getIdentifier() .
'\' failed.
', 1329831691); 1601 // Mark the file object as deleted 1602 if ($fileObject instanceof File) { 1603 $fileObject->setDeleted(); 1606 $this->emitPostFileDeleteSignal($fileObject); 1625 public function copyFile(FileInterface $file, Folder $targetFolder, $targetFileName = NULL, $conflictMode = 'renameNewFile
') { 1626 if ($targetFileName === NULL) { 1627 $targetFileName = $file->getName(); 1629 $sanitizedTargetFileName = $this->driver->sanitizeFileName($targetFileName); 1630 $this->assureFileCopyPermissions($file, $targetFolder, $sanitizedTargetFileName); 1631 $this->emitPreFileCopySignal($file, $targetFolder); 1632 // File exists and we should abort, let's abort
1633 if ($conflictMode ===
'cancel' && $targetFolder->hasFile($sanitizedTargetFileName)) {
1634 throw new Exception\ExistingTargetFileNameException(
'The target file already exists.', 1320291064);
1637 if ($conflictMode ===
'renameNewFile' && $targetFolder->hasFile($sanitizedTargetFileName)) {
1638 $sanitizedTargetFileName = $this->
getUniqueName($targetFolder, $sanitizedTargetFileName);
1640 $sourceStorage = $file->getStorage();
1643 if ($sourceStorage === $this) {
1644 $newFileObjectIdentifier = $this->driver->copyFileWithinStorage($file->getIdentifier(), $targetFolder->getIdentifier(), $sanitizedTargetFileName);
1646 $tempPath = $file->getForLocalProcessing();
1647 $newFileObjectIdentifier = $this->driver->addFile($tempPath, $targetFolder->getIdentifier(), $sanitizedTargetFileName);
1651 return $newFileObject;
1669 public function moveFile($file, $targetFolder, $targetFileName = NULL, $conflictMode =
'renameNewFile') {
1670 if ($targetFileName === NULL) {
1671 $targetFileName = $file->getName();
1673 $originalFolder = $file->getParentFolder();
1674 $sanitizedTargetFileName = $this->driver->sanitizeFileName($targetFileName);
1676 if ($targetFolder->hasFile($sanitizedTargetFileName)) {
1678 if ($conflictMode ===
'renameNewFile') {
1679 $sanitizedTargetFileName = $this->
getUniqueName($targetFolder, $sanitizedTargetFileName);
1680 } elseif ($conflictMode ===
'cancel') {
1681 throw new Exception\ExistingTargetFileNameException(
'The target file already exists', 1329850997);
1685 $sourceStorage = $file->getStorage();
1688 if ($sourceStorage === $this) {
1689 $newIdentifier = $this->driver->moveFileWithinStorage($file->getIdentifier(), $targetFolder->getIdentifier(), $sanitizedTargetFileName);
1691 throw new \RuntimeException(
'The given file is not of type AbstractFile.', 1384209025);
1693 $file->updateProperties(array(
'identifier' => $newIdentifier));
1695 $tempPath = $file->getForLocalProcessing();
1696 $newIdentifier = $this->driver->addFile($tempPath, $targetFolder->getIdentifier(), $sanitizedTargetFileName);
1697 $sourceStorage->driver->deleteFile($file->getIdentifier());
1698 if ($file instanceof
File) {
1699 $file->updateProperties(array(
'storage' => $this->
getUid(),
'identifier' => $newIdentifier));
1702 $this->
getIndexer()->updateIndexEntry($file);
1704 echo $e->getMessage();
1725 if ($file->getName() === $targetFileName) {
1728 $sanitizedTargetFileName = $this->driver->sanitizeFileName($targetFileName);
1734 $newIdentifier = $this->driver->renameFile($file->getIdentifier(), $sanitizedTargetFileName);
1735 if ($file instanceof
File) {
1736 $file->updateProperties(array(
'identifier' => $newIdentifier));
1738 $this->
getIndexer()->updateIndexEntry($file);
1739 }
catch (\RuntimeException $e) {
1761 if (!file_exists($localFilePath)) {
1762 throw new \InvalidArgumentException(
'File "' . $localFilePath .
'" does not exist.', 1325842622);
1766 if ($file instanceof
File) {
1767 $this->
getIndexer()->updateIndexEntry($file);
1782 public function addUploadedFile(array $uploadedFileData,
Folder $targetFolder = NULL, $targetFileName = NULL, $conflictMode =
'cancel') {
1783 $localFilePath = $uploadedFileData[
'tmp_name'];
1784 if ($targetFolder === NULL) {
1787 if ($targetFileName === NULL) {
1788 $targetFileName = $uploadedFileData[
'name'];
1792 $resultObject = $this->
addFile($localFilePath, $targetFolder, $targetFileName, $conflictMode);
1793 return $resultObject;
1805 protected function getAllFileObjectsInFolder(
Folder $folder) {
1807 $folderQueue = array($folder);
1808 while (!empty($folderQueue)) {
1809 $folder = array_shift($folderQueue);
1811 $folderQueue[] = $subfolder;
1813 foreach ($folder->
getFiles() as $file) {
1815 $files[$file->getIdentifier()] = $file;
1836 public function moveFolder(
Folder $folderToMove,
Folder $targetParentFolder, $newFolderName = NULL, $conflictMode =
'renameNewFolder') {
1840 $sourceStorage = $folderToMove->
getStorage();
1841 $returnObject = NULL;
1842 $sanitizedNewFolderName = $this->driver->sanitizeFileName($newFolderName ?: $folderToMove->
getName());
1846 $fileObjects = $this->getAllFileObjectsInFolder($folderToMove);
1847 if ($sourceStorage === $this) {
1851 'Cannot move folder "%s" into target folder "%s", because the target folder is already within the folder to be moved!',
1853 $targetParentFolder->
getName()
1858 $fileMappings = $this->driver->moveFolderWithinStorage($folderToMove->
getIdentifier(), $targetParentFolder->
getIdentifier(), $sanitizedNewFolderName);
1863 foreach ($fileObjects as $oldIdentifier => $fileObject) {
1864 $newIdentifier = $fileMappings[$oldIdentifier];
1865 $fileObject->updateProperties(array(
'storage' => $this->
getUid(),
'identifier' => $newIdentifier));
1866 $this->
getIndexer()->updateIndexEntry($fileObject);
1870 return $returnObject;
1884 throw new \RuntimeException(
'Not yet implemented');
1900 $returnObject = NULL;
1901 $sanitizedNewFolderName = $this->driver->sanitizeFileName($newFolderName ?: $folderToCopy->
getName());
1902 if ($folderToCopy instanceof
Folder && $targetParentFolder instanceof
Folder) {
1905 $sourceStorage = $folderToCopy->
getStorage();
1908 if ($sourceStorage === $this) {
1912 'Cannot copy folder "%s" into target folder "%s", because the target folder is already within the folder to be copied!',
1914 $targetParentFolder->
getName()
1919 $this->driver->copyFolderWithinStorage($folderToCopy->
getIdentifier(), $targetParentFolder->
getIdentifier(), $sanitizedNewFolderName);
1920 $returnObject = $this->
getFolder($targetParentFolder->
getSubfolder($sanitizedNewFolderName)->getIdentifier());
1925 return $returnObject;
1939 throw new \RuntimeException(
'Not yet implemented.');
1956 throw new Exception\InsufficientUserPermissionsException(
'You are not allowed to rename the folder "' . $folderObject->getIdentifier() .
'\'', 1357811441);
1959 $sanitizedNewName = $this->driver->sanitizeFileName($newName);
1960 $returnObject = NULL;
1961 if ($this->driver->folderExistsInFolder($sanitizedNewName, $folderObject->getIdentifier())) {
1962 throw new \InvalidArgumentException(
'The folder ' . $sanitizedNewName .
' already exists in folder ' . $folderObject->getIdentifier(), 1325418870);
1967 $fileObjects = $this->getAllFileObjectsInFolder($folderObject);
1968 $fileMappings = $this->driver->renameFolder($folderObject->getIdentifier(), $sanitizedNewName);
1970 foreach ($fileObjects as $oldIdentifier => $fileObject) {
1971 $newIdentifier = $fileMappings[$oldIdentifier];
1972 $fileObject->updateProperties(array(
'identifier' => $newIdentifier));
1973 $this->
getIndexer()->updateIndexEntry($fileObject);
1975 $returnObject = $this->
getFolder($fileMappings[$folderObject->getIdentifier()]);
1979 return $returnObject;
1995 $isEmpty = $this->driver->isFolderEmpty($folderObject->getIdentifier());
1997 if (!$isEmpty && !$deleteRecursively) {
1998 throw new \RuntimeException(
'Could not delete folder "' . $folderObject->getIdentifier() .
'" because it is not empty.', 1325952534);
2003 foreach ($this->
getFilesInFolder($folderObject, 0, 0, FALSE, $deleteRecursively) as $file) {
2007 $result = $this->driver->deleteFolder($folderObject->getIdentifier(), $deleteRecursively);
2024 public function getFolderList($path, $start = 0, $numberOfItems = 0, $useFilters = TRUE) {
2027 $filters = $useFilters === TRUE ? $this->fileAndFolderNameFilters : array();
2041 $filters = $useFilters == TRUE ? $this->fileAndFolderNameFilters : array();
2042 $folderIdentifiers = $this->driver->getFoldersInFolder($folder->
getIdentifier(), $start, $maxNumberOfItems, $recursive, $filters);
2047 if (isset($folderIdentifiers[$processingIdentifier])) {
2048 unset($folderIdentifiers[$processingIdentifier]);
2052 foreach ($folderIdentifiers as $folderIdentifier) {
2053 $folders[$folderIdentifier] = $this->
getFolder($folderIdentifier, TRUE);
2067 public function fetchFolderListFromDriver($path, $start = 0, $numberOfItems = 0, array $folderFilterCallbacks = array(), $recursive = FALSE) {
2070 $parentFolder = $this->
getFolder($path);
2071 if ($parentFolder === NULL) {
2074 $folders = $this->
getFoldersInFolder($parentFolder, $start, $numberOfItems, count($folderFilterCallbacks) > 0, $recursive);
2075 $folderInfo = array();
2076 foreach ($folders as $folder) {
2077 $folderInfo[$folder->getIdentifier()] = array(
2078 'name' => $folder->getName(),
2079 'identifier' => $folder->getIdentifier()
2093 return $this->driver->folderExists($identifier);
2105 return $this->driver->folderExistsInFolder($folderName, $folder->
getIdentifier());
2121 if ($parentFolder === NULL) {
2123 } elseif (!$this->driver->folderExists($parentFolder->getIdentifier())) {
2124 throw new \InvalidArgumentException(
'Parent folder "' . $parentFolder->getIdentifier() .
'" does not exist.', 1325689164);
2127 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to create directories in the folder "' . $parentFolder->getIdentifier() .
'"', 1323059807);
2132 $newFolder = $this->
getDriver()->createFolder($folderName, $parentFolder->getIdentifier(), TRUE);
2133 $newFolder = $this->
getFolder($newFolder);
2146 return $this->
getFolder($this->driver->getDefaultFolder());
2157 public function getFolder($identifier, $returnInaccessibleFolderObject = FALSE) {
2159 $data = $this->driver->getFolderInfoByIdentifier($identifier);
2164 }
catch (
Exception\InsufficientFolderAccessPermissionsException $e) {
2166 if ($returnInaccessibleFolderObject) {
2168 $parentPermissions = $this->driver->getPermissions($this->driver->getParentFolderIdentifierOfIdentifier($identifier));
2169 if ($parentPermissions[
'r']) {
2171 'TYPO3\\CMS\\Core\\Resource\\InaccessibleFolder', $this, $data[
'identifier'], $data[
'name']
2176 if ($folder === NULL) {
2190 $inProcessingFolder = FALSE;
2192 if ($this->driver->isWithin($processingFolder->getIdentifier(), $identifier)) {
2193 $inProcessingFolder = TRUE;
2197 return $inProcessingFolder;
2210 throw new \InvalidArgumentException(
'Given folder "' . $folder->
getIdentifier() .
'" is not part of this storage!', 1422709241);
2227 if ($respectFileMounts && count($this->fileMounts)) {
2228 $mount = reset($this->fileMounts);
2229 return $mount[
'folder'];
2244 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PreFileAdd, array(&$targetFileName, $targetFolder, $sourceFilePath, $this, $this->driver));
2245 return $targetFileName;
2256 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PostFileAdd, array($file, $targetFolder));
2267 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PreFileCopy, array($file, $targetFolder));
2278 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PostFileCopy, array($file, $targetFolder));
2289 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PreFileMove, array($file, $targetFolder));
2301 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PostFileMove, array($file, $targetFolder, $originalFolder));
2312 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PreFileRename, array($file, $targetFolder));
2323 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PostFileRename, array($file, $targetFolder));
2334 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PreFileReplace, array($file, $localFilePath));
2345 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PostFileReplace, array($file, $localFilePath));
2355 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PostFileCreate, array($newFileIdentifier, $targetFolder));
2365 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PreFileDelete, array($file));
2375 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PostFileDelete, array($file));
2386 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PostFileSetContents, array($file, $content));
2397 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PreFolderAdd, array($targetFolder, $name));
2407 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PostFolderAdd, array($folder));
2419 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PreFolderCopy, array($folder, $targetFolder, $newName));
2431 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PostFolderCopy, array($folder, $targetFolder, $newName));
2443 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PreFolderMove, array($folder, $targetFolder, $newName));
2456 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PostFolderMove, array($folder, $targetFolder, $newName, $originalFolder));
2467 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PreFolderRename, array($folder, $newName));
2478 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PostFolderRename, array($folder, $newName));
2488 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PreFolderDelete, array($folder));
2498 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PostFolderDelete, array($folder));
2509 $this->
getSignalSlotDispatcher()->dispatch(
'TYPO3\\CMS\\Core\\Resource\\ResourceStorage', self::SIGNAL_PreGeneratePublicUrl, array($this, $this->driver, $resourceObject, $relativeToCurrentScript, $urlData));
2526 static $maxNumber = 99, $uniqueNamePrefix =
'';
2530 if ($uniqueNamePrefix) {
2531 $origFileInfo[
'basename'] = $uniqueNamePrefix . $origFileInfo[
'basename'];
2532 $origFileInfo[
'filename'] = $uniqueNamePrefix . $origFileInfo[
'filename'];
2536 $theDestFile = $origFileInfo[
'basename'];
2538 if (!$this->driver->fileExistsInFolder($theDestFile, $folder->
getIdentifier()) || $dontCheckForUnique) {
2539 return $theDestFile;
2544 $theTempFileBody = preg_replace(
'/_[0-9][0-9]$/',
'', $origFileInfo[
'filename']);
2545 $theOrigExt = $origFileInfo[
'extension'] ?
'.' . $origFileInfo[
'extension'] :
'';
2546 for ($a = 1; $a <= $maxNumber + 1; $a++) {
2548 if ($a <= $maxNumber) {
2549 $insert =
'_' . sprintf(
'%02d', $a);
2551 $insert =
'_' . substr(md5(uniqid(
'', TRUE)), 0, 6);
2553 $theTestFile = $theTempFileBody . $insert . $theOrigExt;
2555 $theDestFile = $theTestFile;
2557 if (!$this->driver->fileExistsInFolder($theDestFile, $folder->
getIdentifier())) {
2558 return $theDestFile;
2561 throw new \RuntimeException(
'Last possible name "' . $theDestFile .
'" is already taken.', 1325194291);
2570 if (!isset($this->signalSlotDispatcher)) {
2571 $this->signalSlotDispatcher = $this->
getObjectManager()->get(
'TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
2603 if (!$this->fileProcessingService) {
2604 $this->fileProcessingService =
GeneralUtility::makeInstance(
'TYPO3\\CMS\\Core\\Resource\\Service\\FileProcessingService', $this, $this->driver);
2618 if (method_exists($this->driver,
'getRole')) {
2619 $folderRole = $this->driver->getRole($folder->
getIdentifier());
2621 if (isset($this->fileMounts[$identifier])) {
2624 if (!empty($this->fileMounts[$identifier][
'read_only'])) {
2627 if ($this->fileMounts[$identifier][
'user_mount']) {
2645 if (!isset($this->processingFolder)) {
2647 if (!empty($this->storageRecord[
'processingfolder'])) {
2652 list ($storageUid, $processingFolderIdentifier) = explode(
':',
$processingFolder, 2);
2654 if ($storage->hasFolder($processingFolderIdentifier)) {
2655 $this->processingFolder = $storage->getFolder($processingFolderIdentifier);
2657 $this->processingFolder = $storage->createFolder(ltrim($processingFolderIdentifier,
'/'));
2667 }
catch(
Exception\InsufficientFolderWritePermissionsException $e) {
2671 }
catch(
Exception\ResourcePermissionsUnavailableException $e) {
2686 return $this->storageRecord[
'driver'];
getFolderList($path, $start=0, $numberOfItems=0, $useFilters=TRUE)
assureFolderCopyPermissions(FolderInterface $folderToCopy, FolderInterface $targetParentFolder)
emitPreFileMoveSignal(FileInterface $file, Folder $targetFolder)
addFileMount($folderIdentifier, $additionalData=array())
resetFileAndFolderNameFiltersToDefault()
emitPreFileDeleteSignal(FileInterface $file)
replaceFile(FileInterface $file, $localFilePath)
emitPostFolderAddSignal(Folder $folder)
checkFolderActionPermission($action, Folder $folder=NULL)
emitPreFileReplaceSignal(FileInterface $file, $localFilePath)
isWithinProcessingFolder($identifier)
getFileList($path, $start=0, $numberOfItems=0, $useFilters=TRUE, $loadIndexRecords=TRUE, $recursive=FALSE)
isWithinFolder(Folder $folder, ResourceInterface $resource)
static uniqueList($in_list, $secondParameter=NULL)
getFolderByIdentifier($identifier)
getFolderIdentifierFromFileIdentifier($fileIdentifier)
moveFolder(Folder $folderToMove, Folder $targetParentFolder, $newFolderName=NULL, $conflictMode='renameNewFolder')
checkFileActionPermission($action, FileInterface $file)
setFileContents(AbstractFile $file, $contents)
hasFileInFolder($fileName, Folder $folder)
assureFileAddPermissions($localFilePath, $targetFolder, $targetFileName)
emitPreFolderMoveSignal(Folder $folder, Folder $targetFolder, $newName)
processFile(FileInterface $fileObject, $context, array $configuration)
static getCanonicalPath($path)
static getRelativePathTo($targetPath)
emitPostFileRenameSignal(FileInterface $file, $targetFolder)
assureFileWritePermissions(FileInterface $file)
getSubfolders($start=0, $numberOfItems=0, $filterMode=self::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS)
__construct(Driver\DriverInterface $driver, array $storageRecord)
emitPostFileCreateSignal($newFileIdentifier, Folder $targetFolder)
getFileAndFolderNameFilters()
getSignalSlotDispatcher()
addFileAndFolderNameFilter($filter)
emitPreFileCopySignal(FileInterface $file, Folder $targetFolder)
hashFileByIdentifier($fileIdentifier, $hash)
markAsPermanentlyOffline()
getFilesInFolder(Folder $folder, $start=0, $maxNumberOfItems=0, $useFilters=TRUE, $recursive=FALSE)
getFolderIdentifiersInFolder($folderIdentifier, $useFilters=TRUE, $recursive=FALSE)
usesCaseSensitiveIdentifiers()
getFolder($identifier, $returnInaccessibleFolderObject=FALSE)
emitPreFolderRenameSignal(Folder $folder, $newName)
emitPreFileRenameSignal(FileInterface $file, $targetFolder)
static getMaxUploadFileSize($localLimit=0)
getRootLevelFolder($respectFileMounts=TRUE)
static hmac($input, $additionalSecret='')
emitPostFolderDeleteSignal(Folder $folder)
getPublicUrl(ResourceInterface $resourceObject, $relativeToCurrentScript=FALSE)
emitPostFolderRenameSignal(Folder $folder, $newName)
static logDeprecatedFunction()
assureFolderMovePermissions(FolderInterface $folderToMove, FolderInterface $targetParentFolder)
setUserPermissions(array $userPermissions)
setIdentifier($identifier)
isWithinFileMountBoundaries($subject, $checkWriteAccess=FALSE)
addFile($localFilePath, Folder $targetFolder, $targetFileName='', $conflictMode='changeName')
static makeInstance($className)
emitPostFileReplaceSignal(FileInterface $file, $localFilePath)
const ROLE_READONLY_MOUNT
static pathinfo($path, $options=NULL)
copyFolderBetweenStorages(Folder $folderToCopy, Folder $targetParentFolder, $newFolderName)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
copyFolder(FolderInterface $folderToCopy, FolderInterface $targetParentFolder, $newFolderName=NULL, $conflictMode='renameNewFolder')
static verifyFilenameAgainstDenyPattern($filename)
assureFolderReadPermission(Folder $folder=NULL)
unsetFileAndFolderNameFilters()
renameFile($file, $targetFileName)
hashFile(FileInterface $fileObject, $hash)
setEvaluatePermissions($evaluatePermissions)
emitPostFileSetContentsSignal(FileInterface $file, $content)
emitPostFileCopySignal(FileInterface $file, Folder $targetFolder)
emitPreGeneratePublicUrlSignal(ResourceInterface $resourceObject, $relativeToCurrentScript, array $urlData)
$fileAndFolderNameFilters
getFileForLocalProcessing(FileInterface $fileObject, $writable=TRUE)
setConfiguration(array $configuration)
assureFileCopyPermissions(FileInterface $file, Folder $targetFolder, $targetFileName)
checkFileExtensionPermission($fileName)
moveFolderBetweenStorages(Folder $folderToMove, Folder $targetParentFolder, $newFolderName)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren't numeric.
assureFolderDeletePermission(Folder $folder, $checkDeleteRecursively)
emitPostFileAddSignal(FileInterface $file, Folder $targetFolder)
checkUserActionPermission($action, $type)
dumpFileContents(FileInterface $file, $asDownload=FALSE, $alternativeFilename=NULL)
createFolder($folderName, Folder $parentFolder=NULL)
getFileByIdentifier($identifier)
emitPostFileDeleteSignal(FileInterface $file)
deleteFolder($folderObject, $deleteRecursively=FALSE)
hasCapability($capability)
moveFile($file, $targetFolder, $targetFileName=NULL, $conflictMode='renameNewFile')
addUploadedFile(array $uploadedFileData, Folder $targetFolder=NULL, $targetFileName=NULL, $conflictMode='cancel')
fetchFolderListFromDriver($path, $start=0, $numberOfItems=0, array $folderFilterCallbacks=array(), $recursive=FALSE)
assureFileDeletePermissions(FileInterface $file)
emitPreFolderDeleteSignal(Folder $folder)
setDriver(Driver\DriverInterface $driver)
emitPreFolderAddSignal(Folder $targetFolder, $name)
createFile($fileName, Folder $targetFolderObject)
emitPostFolderMoveSignal(Folder $folder, Folder $targetFolder, $newName, Folder $originalFolder)
assureFileUploadPermissions($localFilePath, $targetFolder, $targetFileName, $uploadedFileSize)
getUniqueName(Folder $folder, $theFile, $dontCheckForUnique=FALSE)
getFoldersInFolder(Folder $folder, $start=0, $maxNumberOfItems=0, $useFilters=TRUE, $recursive=FALSE)
isProcessingFolder(Folder $folder)
emitPreFileAddSignal($targetFileName, Folder $targetFolder, $sourceFilePath)
getRole(FolderInterface $folder)
emitPostFolderCopySignal(Folder $folder, Folder $targetFolder, $newName)
emitPreFolderCopySignal(Folder $folder, Folder $targetFolder, $newName)
setFileAndFolderNameFilters(array $filters)
hasFolderInFolder($folderName, Folder $folder)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
assureFileReadPermission(FileInterface $file)
getFileProcessingService()
static inList($list, $item)
assureFileRenamePermissions(FileInterface $file, $targetFileName)
updateProcessedFile($localFilePath, ProcessedFile $processedFile, Folder $processingFolder=NULL)
getFileIdentifiersInFolder($folderIdentifier, $useFilters=TRUE, $recursive=FALSE)
renameFolder($folderObject, $newName)
assureFileMovePermissions(FileInterface $file, Folder $targetFolder, $targetFileName)
getFiles($start=0, $numberOfItems=0, $filterMode=self::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, $recursive=FALSE)
emitPostFileMoveSignal(FileInterface $file, Folder $targetFolder, Folder $originalFolder)
getFileInfo(FileInterface $fileObject)
getFileInfoByIdentifier($identifier, array $propertiesToExtract=array())