2 namespace TYPO3\CMS\Core\Resource;
18 use TYPO3\CMS\Core\Resource\Exception\InvalidTargetFolderException;
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);
244 return $this->storageRecord[
'name'];
254 return (
int)$this->storageRecord[
'uid'];
289 return ($this->capabilities & $capability) == $capability;
333 return $this->driver->isCaseSensitiveFileSystem();
344 if ($this->
getUid() === 0) {
348 if ($this->storageRecord[
'is_online'] == 0) {
353 if (TYPO3_MODE ===
'FE') {
358 $offlineUntil = $registryObject->get(
'core',
'sys_file_storage-' . $this->
getUid() .
'-offline-until');
359 if ($offlineUntil && $offlineUntil > time()) {
377 return !empty($this->storageRecord[
'auto_extract_metadata']);
391 if ($this->
getUid() > 0) {
393 $GLOBALS[
'TYPO3_DB']->exec_UPDATEquery(
'sys_file_storage',
'uid=' . (
int)$this->
getUid(), array(
'is_online' => 0));
395 $this->storageRecord[
'is_online'] = 0;
410 $registryObject->set(
'core',
'sys_file_storage-' . $this->
getUid() .
'-offline-until', time() + 60 * 5);
411 $this->storageRecord[
'is_online'] = 0;
428 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;
483 if (!$this->evaluatePermissions) {
486 $isWithinFileMount =
false;
490 $identifier = $subject->getIdentifier();
494 $isWithinFileMount =
true;
498 $writableFileMountAvailable =
false;
499 foreach ($this->fileMounts as $fileMount) {
500 if ($this->driver->isWithin($fileMount[
'folder']->getIdentifier(), $identifier)) {
501 $isWithinFileMount =
true;
502 if (!$checkWriteAccess) {
504 }
elseif (empty($fileMount[
'read_only'])) {
505 $writableFileMountAvailable =
true;
510 $isWithinFileMount = $checkWriteAccess ? $writableFileMountAvailable : $isWithinFileMount;
512 return $isWithinFileMount;
558 if (!$this->evaluatePermissions) {
563 if (!empty($this->userPermissions[strtolower($action) . ucfirst(strtolower($type))])) {
594 $isReadCheck =
false;
595 if (in_array($action, array(
'read',
'copy',
'move',
'replace'),
true)) {
598 $isWriteCheck =
false;
599 if (in_array($action, array(
'add',
'write',
'move',
'rename',
'replace',
'unzip',
'delete'),
true)) {
600 $isWriteCheck =
true;
609 if (!$isProcessedFile && $file instanceof
File) {
610 $isMissing = $file->isMissing();
613 if ($this->driver->fileExists($file->
getIdentifier()) ===
false) {
614 $file->setMissing(
true);
619 if ($isWriteCheck && ($isMissing || !$this->
isWritable())) {
625 $filePermissions = $this->driver->getPermissions($file->
getIdentifier());
626 if ($isReadCheck && !$filePermissions[
'r']) {
629 if ($isWriteCheck && !$filePermissions[
'w']) {
654 if ($folder === null) {
658 $isReadCheck =
false;
659 if (in_array($action, array(
'read',
'copy'),
true)) {
662 $isWriteCheck =
false;
663 if (in_array($action, array(
'add',
'move',
'write',
'delete',
'rename'),
true)) {
664 $isWriteCheck =
true;
680 $folderPermissions = $this->driver->getPermissions($folder->getIdentifier());
681 if ($isReadCheck && !$folderPermissions[
'r']) {
684 if ($isWriteCheck && !$folderPermissions[
'w']) {
699 if (!$this->evaluatePermissions) {
702 $fileName = $this->driver->sanitizeFileName($fileName);
707 $fileExtensionPermissions =
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'fileExtensions'][
'webspace'];
710 if ($fileExtension !==
'') {
712 if ($fileExtensionPermissions[
'allow'] ===
'*' ||
GeneralUtility::inList($fileExtensionPermissions[
'allow'], $fileExtension)) {
716 if ($fileExtensionPermissions[
'deny'] ===
'*' ||
GeneralUtility::inList($fileExtensionPermissions[
'deny'], $fileExtension)) {
722 if ($fileExtensionPermissions[
'allow'] ===
'*') {
725 if ($fileExtensionPermissions[
'deny'] ===
'*') {
744 if ($folder === null) {
745 throw new Exception\InsufficientFolderAccessPermissionsException(
746 'You are not allowed to read folders',
750 throw new Exception\InsufficientFolderAccessPermissionsException(
751 'You are not allowed to access the given folder: "' . $folder->getName() .
'"',
772 throw new Exception\InsufficientUserPermissionsException(
'You are not allowed to delete folders recursively', 1377779423);
776 throw new Exception\InsufficientFolderAccessPermissionsException(
777 'You are not allowed to delete the given folder: "' . $folder->
getName() .
'"',
785 throw new Exception\InsufficientFolderWritePermissionsException(
'Writing to folders is not allowed.', 1377779111);
800 throw new Exception\InsufficientFileAccessPermissionsException(
801 'You are not allowed to access that file: "' . $file->
getName() .
'"',
806 throw new Exception\IllegalFileExtensionException(
807 'You are not allowed to use that file extension. File: "' . $file->
getName() .
'"',
826 throw new Exception\InsufficientFileWritePermissionsException(
'Writing to file "' . $file->
getIdentifier() .
'" is not allowed.', 1330121088);
829 throw new Exception\IllegalFileExtensionException(
'You are not allowed to edit a file with extension "' . $file->
getExtension() .
'"', 1366711933);
845 throw new Exception\InsufficientFileWritePermissionsException(
'Replacing file "' . $file->
getIdentifier() .
'" is not allowed.', 1436899571);
849 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to write to the target folder "' . $file->
getIdentifier() .
'"', 1436899572);
866 throw new Exception\IllegalFileExtensionException(
'You are not allowed to delete a file with extension "' . $file->
getExtension() .
'"', 1377778916);
872 throw new Exception\InsufficientFileWritePermissionsException(
'You are not allowed to delete the file "' . $file->
getIdentifier() .
'"', 1319550425);
878 throw new Exception\InsufficientFolderWritePermissionsException(
'Writing to folders is not allowed.', 1377778702);
899 throw new Exception\IllegalFileExtensionException(
'Extension of file name is not allowed in "' . $targetFileName .
'"!', 1322120271);
903 throw new Exception\InsufficientUserPermissionsException(
'You are not allowed to add files to this storage "' . $this->
getUid() .
'"', 1376992145);
907 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to write to the target folder "' . $targetFolder->getIdentifier() .
'"', 1322120356);
930 if (!is_uploaded_file($localFilePath)) {
931 throw new Exception\UploadException(
'The upload has failed, no uploaded file found!', 1322110455);
935 if ($uploadedFileSize >= $maxUploadFileSize) {
936 unlink($localFilePath);
937 throw new Exception\UploadSizeException(
'The uploaded file exceeds the size-limit of ' . $maxUploadFileSize .
' bytes', 1322110041);
958 throw new \RuntimeException(
'The target folder is not in the same storage. Target folder given: "' . $targetFolder .
'"', 1422553107);
962 throw new Exception\IllegalFileExtensionException(
'Extension of file name is not allowed in "' . $targetFileName .
'"!', 1378243279);
965 if (!$file->
getStorage()->checkFileActionPermission(
'move', $file)) {
966 throw new Exception\InsufficientUserPermissionsException(
'You are not allowed to move files to storage "' . $this->
getUid() .
'"', 1319219349);
970 throw new Exception\InsufficientFolderAccessPermissionsException(
'You are not allowed to write to the target folder "' . $targetFolder->
getIdentifier() .
'"', 1319219350);
989 throw new Exception\IllegalFileExtensionException(
'You are not allowed to rename a file with this extension. File given: "' . $file->
getName() .
'"', 1371466663);
993 throw new Exception\InsufficientUserPermissionsException(
'You are not allowed to rename files. File given: "' . $file->
getName() .
'"', 1319219351);
1000 throw new Exception\InsufficientFileWritePermissionsException(
'You are not allowed to write to folders', 1319219352);
1023 throw new Exception(
'The operation of the folder cannot be called by this storage "' . $this->
getUid() .
'"', 1319550405);
1026 if (!$file->
getStorage()->checkFileActionPermission(
'copy', $file)) {
1027 throw new Exception\InsufficientFileReadPermissionsException(
'You are not allowed to copy the file "' . $file->
getIdentifier() .
'"', 1319550426);
1031 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to write to the target folder "' . $targetFolder->
getIdentifier() .
'"', 1319550435);
1035 throw new Exception\IllegalFileExtensionException(
'You are not allowed to copy a file of that type.', 1319553317);
1058 throw new Exception(
'The operation of the folder cannot be called by this storage "' . $this->
getUid() .
'"', 1377777624);
1060 if (!$folderToCopy instanceof
Folder) {
1061 throw new \RuntimeException(
'The folder "' . $folderToCopy->
getIdentifier() .
'" to copy is not of type folder.', 1384209020);
1064 if (!$folderToCopy->
getStorage()->checkFolderActionPermission(
'copy', $folderToCopy)) {
1065 throw new Exception\InsufficientFileReadPermissionsException(
'You are not allowed to copy the folder "' . $folderToCopy->
getIdentifier() .
'"', 1377777629);
1067 if (!$targetParentFolder instanceof Folder) {
1068 throw new \RuntimeException(
'The target folder "' . $targetParentFolder->
getIdentifier() .
'" is not of type folder.', 1384209021);
1072 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to write to the target folder "' . $targetParentFolder->
getIdentifier() .
'"', 1377777635);
1095 throw new \InvalidArgumentException(
'Cannot move a folder into a folder that does not belong to this storage.', 1325777289);
1097 if (!$folderToMove instanceof
Folder) {
1098 throw new \RuntimeException(
'The folder "' . $folderToMove->
getIdentifier() .
'" to move is not of type Folder.', 1384209022);
1103 if (!$folderToMove->
getStorage()->checkFolderActionPermission(
'move', $folderToMove)) {
1104 throw new Exception\InsufficientFileReadPermissionsException(
'You are not allowed to copy the folder "' . $folderToMove->
getIdentifier() .
'"', 1377778045);
1106 if (!$targetParentFolder instanceof Folder) {
1107 throw new \RuntimeException(
'The target folder "' . $targetParentFolder->
getIdentifier() .
'" is not of type Folder.', 1384209023);
1111 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to write to the target folder "' . $targetParentFolder->
getIdentifier() .
'"', 1377778049);
1128 $fileName = $this->driver->sanitizeFileName($fileName);
1155 if (!file_exists($localFilePath)) {
1156 throw new \InvalidArgumentException(
'File "' . $localFilePath .
'" does not exist.', 1319552745);
1166 throw new Exception\ExistingTargetFileNameException(
'File "' . $targetFileName .
'" already exists in folder ' . $targetFolder->
getIdentifier(), 1322121068);
1168 $targetFileName = $this->
getUniqueName($targetFolder, $targetFileName);
1171 $fileIdentifier = $this->driver->addFile($localFilePath, $targetFolder->
getIdentifier(), $targetFileName);
1176 $indexer->extractMetaData($file);
1196 if (!file_exists($localFilePath)) {
1197 throw new \InvalidArgumentException(
'File "' . $localFilePath .
'" does not exist.', 1319552746);
1202 $fileIdentifier = $this->driver->addFile($localFilePath,
$processingFolder->getIdentifier(), $processedFile->
getName());
1206 return $processedFile;
1231 return $this->driver->hash($fileIdentifier, $hash);
1242 public function hashFileIdentifier($file)
1246 $file = $file->getIdentifier();
1248 return $this->driver->hashIdentifier($file);
1270 && $resourceObject instanceof
File
1273 $publicUrl = $helper->getPublicUrl($resourceObject, $relativeToCurrentScript);
1277 if ($publicUrl === null) {
1279 $publicUrl = $this->driver->getPublicUrl($resourceObject->
getIdentifier());
1282 if ($publicUrl === null && $resourceObject instanceof FileInterface) {
1283 $queryParameterArray = array(
'eID' =>
'dumpFile',
't' =>
'');
1284 if ($resourceObject instanceof
File) {
1285 $queryParameterArray[
'f'] = $resourceObject->getUid();
1286 $queryParameterArray[
't'] =
'f';
1288 $queryParameterArray[
'p'] = $resourceObject->getUid();
1289 $queryParameterArray[
't'] =
'p';
1292 $queryParameterArray[
'token'] =
GeneralUtility::hmac(implode(
'|', $queryParameterArray),
'resourceStorageDumpFile');
1293 $publicUrl =
'index.php?' . str_replace(
'+',
'%20', http_build_query($queryParameterArray));
1301 $filePart = substr(PATH_site . $publicUrl, strlen($absolutePathToContainingFolder) + 1);
1302 $publicUrl = $pathPart . $filePart;
1322 throw new \InvalidArgumentException(
'Cannot process files of foreign storage', 1353401835);
1326 return $processedFile;
1338 $filePath = $this->driver->getFileForLocalProcessing($fileObject->
getIdentifier(), $writable);
1350 $file = $this->
getFileFactory()->getFileObjectByStorageAndIdentifier($this->
getUid(), $identifier);
1351 if (!$this->driver->fileExists($identifier)) {
1352 $file->setMissing(
true);
1379 return $this->driver->getFileInfoByIdentifier($identifier, $propertiesToExtract);
1389 $this->fileAndFolderNameFilters = array();
1399 $this->fileAndFolderNameFilters =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'fal'][
'defaultFilterCallbacks'];
1418 $this->fileAndFolderNameFilters = $filters;
1427 $this->fileAndFolderNameFilters[] = $filter;
1437 return $this->driver->getParentFolderIdentifierOfIdentifier($fileIdentifier);
1449 $identifier = $this->driver->getFileInFolder($fileName, $folder->
getIdentifier());
1450 return $this->
getFileFactory()->getFileObjectByStorageAndIdentifier($this->
getUid(), $identifier);
1468 public function getFilesInFolder(
Folder $folder, $start = 0, $maxNumberOfItems = 0, $useFilters =
true, $recursive =
false, $sort =
'', $sortRev =
false)
1474 $filters = $useFilters ==
true ? $this->fileAndFolderNameFilters : array();
1475 $fileIdentifiers = array_values($this->driver->getFilesInFolder($folder->
getIdentifier(), $start, $maxNumberOfItems, $recursive, $filters, $sort, $sortRev));
1478 foreach ($fileIdentifiers as $identifier) {
1479 if (isset($rows[$identifier])) {
1480 $fileObject = $this->
getFileFactory()->getFileObject($rows[$identifier][
'uid'], $rows[$identifier]);
1482 $fileObject = $this->
getFileFactory()->getFileObjectByStorageAndIdentifier($this->
getUid(), $identifier);
1484 if ($fileObject instanceof FileInterface) {
1485 $key = $fileObject->getName();
1486 while (isset($items[$key])) {
1489 $items[$key] = $fileObject;
1504 $filters = $useFilters ==
true ? $this->fileAndFolderNameFilters : array();
1505 return $this->driver->getFilesInFolder($folderIdentifier, 0, 0, $recursive, $filters);
1518 $filters = $useFilters ? $this->fileAndFolderNameFilters : array();
1519 return $this->driver->countFilesInFolder($folder->
getIdentifier(), $recursive, $filters);
1530 $filters = $useFilters ==
true ? $this->fileAndFolderNameFilters : array();
1531 return $this->driver->getFoldersInFolder($folderIdentifier, 0, 0, $recursive, $filters);
1546 return $this->driver->fileExists($identifier);
1554 public function getProcessingFolders()
1556 if ($this->processingFolders === null) {
1557 $this->processingFolders = array();
1561 $allStorages = $storageRepository->findAll();
1562 foreach ($allStorages as $storage) {
1565 list($storageUid, $processingFolderIdentifier) =
GeneralUtility::trimExplode(
':', $storage->getStorageRecord()[
'processingfolder']);
1566 if (empty($processingFolderIdentifier) || (int)$storageUid !== $this->
getUid()) {
1569 $potentialProcessingFolder =
ResourceFactory::getInstance()->getInstance()->createFolderObject($this, $processingFolderIdentifier, $processingFolderIdentifier);
1570 if ($potentialProcessingFolder->getStorage() === $this && $potentialProcessingFolder->getIdentifier() !== $this->
getProcessingFolder()->getIdentifier()) {
1571 $this->processingFolders[] = $potentialProcessingFolder;
1588 $isProcessingFolder =
false;
1591 $isProcessingFolder =
true;
1595 return $isProcessingFolder;
1608 return $this->driver->fileExistsInFolder($fileName, $folder->
getIdentifier());
1622 return $this->driver->getFileContents($file->getIdentifier());
1635 public function dumpFileContents(FileInterface $file, $asDownload =
false, $alternativeFilename = null, $overrideMimeType = null)
1637 $downloadName = $alternativeFilename ?: $file->
getName();
1638 $contentDisposition = $asDownload ?
'attachment' :
'inline';
1639 header(
'Content-Disposition: ' . $contentDisposition .
'; filename="' . $downloadName .
'"');
1640 header(
'Content-Type: ' . ($overrideMimeType ?: $file->
getMimeType()));
1641 header(
'Content-Length: ' . $file->
getSize());
1645 header(
"Cache-Control: ''");
1646 header(
'Last-Modified: ' .
1647 gmdate(
'D, d M Y H:i:s', array_pop($this->driver->getFileInfoByIdentifier($file->
getIdentifier(), array(
'mtime')))) .
' GMT',
1653 while (ob_get_level() > 0) {
1675 $result = $this->driver->setFileContents($file->
getIdentifier(), $contents);
1676 $this->
getIndexer()->updateIndexEntry($file);
1696 $newFileIdentifier = $this->driver->createFile($fileName, $targetFolderObject->
getIdentifier());
1715 if ($this->driver->fileExists($fileObject->getIdentifier())) {
1716 $result = $this->driver->deleteFile($fileObject->getIdentifier());
1718 throw new Exception\FileOperationErrorException(
'Deleting the file "' . $fileObject->getIdentifier() .
'\' failed.
', 1329831691);
1721 // Mark the file object as deleted
1722 if ($fileObject instanceof File) {
1723 $fileObject->setDeleted();
1726 $this->emitPostFileDeleteSignal($fileObject);
1745 public function copyFile(FileInterface $file, Folder $targetFolder, $targetFileName = null, $conflictMode = DuplicationBehavior::RENAME)
1747 $conflictMode = DuplicationBehavior::cast($conflictMode);
1748 if ($targetFileName === null) {
1749 $targetFileName = $file->getName();
1751 $sanitizedTargetFileName = $this->driver->sanitizeFileName($targetFileName);
1752 $this->assureFileCopyPermissions($file, $targetFolder, $sanitizedTargetFileName);
1753 $this->emitPreFileCopySignal($file, $targetFolder);
1754 // File exists and we should abort, let's abort
1756 throw new Exception\ExistingTargetFileNameException(
'The target file already exists.', 1320291064);
1760 $sanitizedTargetFileName = $this->
getUniqueName($targetFolder, $sanitizedTargetFileName);
1762 $sourceStorage = $file->getStorage();
1765 if ($sourceStorage === $this) {
1766 $newFileObjectIdentifier = $this->driver->copyFileWithinStorage($file->getIdentifier(), $targetFolder->getIdentifier(), $sanitizedTargetFileName);
1768 $tempPath = $file->getForLocalProcessing();
1769 $newFileObjectIdentifier = $this->driver->addFile($tempPath, $targetFolder->getIdentifier(), $sanitizedTargetFileName);
1773 return $newFileObject;
1794 if ($targetFileName === null) {
1795 $targetFileName = $file->getName();
1797 $originalFolder = $file->getParentFolder();
1798 $sanitizedTargetFileName = $this->driver->sanitizeFileName($targetFileName);
1800 if ($targetFolder->hasFile($sanitizedTargetFileName)) {
1803 $sanitizedTargetFileName = $this->
getUniqueName($targetFolder, $sanitizedTargetFileName);
1805 throw new Exception\ExistingTargetFileNameException(
'The target file already exists', 1329850997);
1809 $sourceStorage = $file->getStorage();
1812 if ($sourceStorage === $this) {
1813 $newIdentifier = $this->driver->moveFileWithinStorage($file->getIdentifier(), $targetFolder->getIdentifier(), $sanitizedTargetFileName);
1815 throw new \RuntimeException(
'The given file is not of type AbstractFile.', 1384209025);
1817 $file->updateProperties(array(
'identifier' => $newIdentifier));
1819 $tempPath = $file->getForLocalProcessing();
1820 $newIdentifier = $this->driver->addFile($tempPath, $targetFolder->getIdentifier(), $sanitizedTargetFileName);
1821 $sourceStorage->driver->deleteFile($file->getIdentifier());
1822 if ($file instanceof
File) {
1823 $file->updateProperties(array(
'storage' => $this->
getUid(),
'identifier' => $newIdentifier));
1826 $this->
getIndexer()->updateIndexEntry($file);
1827 }
catch (\TYPO3\CMS\Core\
Exception $e) {
1828 echo $e->getMessage();
1850 if ($file->getName() === $targetFileName) {
1853 $sanitizedTargetFileName = $this->driver->sanitizeFileName($targetFileName);
1859 $newIdentifier = $this->driver->renameFile($file->getIdentifier(), $sanitizedTargetFileName);
1860 if ($file instanceof
File) {
1861 $file->updateProperties(array(
'identifier' => $newIdentifier));
1863 $this->
getIndexer()->updateIndexEntry($file);
1864 }
catch (\RuntimeException $e) {
1887 throw new Exception\IllegalFileExtensionException(
'Source file extension not allowed.', 1378132239);
1889 if (!file_exists($localFilePath)) {
1890 throw new \InvalidArgumentException(
'File "' . $localFilePath .
'" does not exist.', 1325842622);
1893 $this->driver->replaceFile($file->
getIdentifier(), $localFilePath);
1894 if ($file instanceof
File) {
1895 $this->
getIndexer()->updateIndexEntry($file);
1899 $indexer->extractMetaData($file);
1918 $localFilePath = $uploadedFileData[
'tmp_name'];
1919 if ($targetFolder === null) {
1922 if ($targetFileName === null) {
1923 $targetFileName = $uploadedFileData[
'name'];
1925 $targetFileName = $this->driver->sanitizeFileName($targetFileName);
1930 $resultObject = $this->
replaceFile($file, $localFilePath);
1932 $resultObject = $this->
addFile($localFilePath, $targetFolder, $targetFileName, (
string)$conflictMode);
1934 return $resultObject;
1946 protected function getAllFileObjectsInFolder(
Folder $folder)
1949 $folderQueue = array($folder);
1950 while (!empty($folderQueue)) {
1951 $folder = array_shift($folderQueue);
1953 $folderQueue[] = $subfolder;
1955 foreach ($folder->
getFiles() as $file) {
1957 $files[$file->getIdentifier()] = $file;
1983 $sourceStorage = $folderToMove->
getStorage();
1984 $returnObject = null;
1985 $sanitizedNewFolderName = $this->driver->sanitizeFileName($newFolderName ?: $folderToMove->
getName());
1989 $fileObjects = $this->getAllFileObjectsInFolder($folderToMove);
1990 if ($sourceStorage === $this) {
1994 'Cannot move folder "%s" into target folder "%s", because the target folder is already within the folder to be moved!',
1996 $targetParentFolder->
getName()
2001 $fileMappings = $this->driver->moveFolderWithinStorage($folderToMove->
getIdentifier(), $targetParentFolder->
getIdentifier(), $sanitizedNewFolderName);
2006 foreach ($fileObjects as $oldIdentifier => $fileObject) {
2007 $newIdentifier = $fileMappings[$oldIdentifier];
2008 $fileObject->updateProperties(array(
'storage' => $this->
getUid(),
'identifier' => $newIdentifier));
2009 $this->
getIndexer()->updateIndexEntry($fileObject);
2013 return $returnObject;
2028 throw new \RuntimeException(
'Not yet implemented');
2045 $returnObject = null;
2046 $sanitizedNewFolderName = $this->driver->sanitizeFileName($newFolderName ?: $folderToCopy->
getName());
2047 if ($folderToCopy instanceof
Folder && $targetParentFolder instanceof
Folder) {
2050 $sourceStorage = $folderToCopy->
getStorage();
2053 if ($sourceStorage === $this) {
2057 'Cannot copy folder "%s" into target folder "%s", because the target folder is already within the folder to be copied!',
2059 $targetParentFolder->
getName()
2064 $this->driver->copyFolderWithinStorage($folderToCopy->
getIdentifier(), $targetParentFolder->
getIdentifier(), $sanitizedNewFolderName);
2065 $returnObject = $this->
getFolder($targetParentFolder->
getSubfolder($sanitizedNewFolderName)->getIdentifier());
2070 return $returnObject;
2085 throw new \RuntimeException(
'Not yet implemented.');
2103 throw new Exception\InsufficientUserPermissionsException(
'You are not allowed to rename the folder "' . $folderObject->getIdentifier() .
'\'', 1357811441);
2106 $sanitizedNewName = $this->driver->sanitizeFileName($newName);
2107 $returnObject = null;
2108 if ($this->driver->folderExistsInFolder($sanitizedNewName, $folderObject->getIdentifier())) {
2109 throw new \InvalidArgumentException(
'The folder ' . $sanitizedNewName .
' already exists in folder ' . $folderObject->getIdentifier(), 1325418870);
2114 $fileObjects = $this->getAllFileObjectsInFolder($folderObject);
2115 $fileMappings = $this->driver->renameFolder($folderObject->getIdentifier(), $sanitizedNewName);
2117 foreach ($fileObjects as $oldIdentifier => $fileObject) {
2118 $newIdentifier = $fileMappings[$oldIdentifier];
2119 $fileObject->updateProperties(array(
'identifier' => $newIdentifier));
2120 $this->
getIndexer()->updateIndexEntry($fileObject);
2122 $returnObject = $this->
getFolder($fileMappings[$folderObject->getIdentifier()]);
2126 return $returnObject;
2143 $isEmpty = $this->driver->isFolderEmpty($folderObject->getIdentifier());
2145 if (!$isEmpty && !$deleteRecursively) {
2146 throw new \RuntimeException(
'Could not delete folder "' . $folderObject->getIdentifier() .
'" because it is not empty.', 1325952534);
2151 foreach ($this->
getFilesInFolder($folderObject, 0, 0,
false, $deleteRecursively) as $file) {
2155 $result = $this->driver->deleteFolder($folderObject->getIdentifier(), $deleteRecursively);
2174 $folderIdentifier = $this->driver->getFolderInFolder($folderName, $parentFolder->
getIdentifier());
2175 return $this->
getFolder($folderIdentifier, $returnInaccessibleFolderObject);
2192 public function getFoldersInFolder(
Folder $folder, $start = 0, $maxNumberOfItems = 0, $useFilters =
true, $recursive =
false, $sort =
'', $sortRev =
false)
2194 $filters = $useFilters ==
true ? $this->fileAndFolderNameFilters : array();
2196 $folderIdentifiers = $this->driver->getFoldersInFolder($folder->
getIdentifier(), $start, $maxNumberOfItems, $recursive, $filters, $sort, $sortRev);
2201 if (isset($folderIdentifiers[$processingIdentifier])) {
2202 unset($folderIdentifiers[$processingIdentifier]);
2206 foreach ($folderIdentifiers as $folderIdentifier) {
2207 $folders[$folderIdentifier] = $this->
getFolder($folderIdentifier,
true);
2222 $filters = $useFilters ? $this->fileAndFolderNameFilters : array();
2223 return $this->driver->countFoldersInFolder($folder->
getIdentifier(), $recursive, $filters);
2235 return $this->driver->folderExists($identifier);
2248 return $this->driver->folderExistsInFolder($folderName, $folder->
getIdentifier());
2266 if ($parentFolder === null) {
2268 }
elseif (!$this->driver->folderExists($parentFolder->getIdentifier())) {
2269 throw new \InvalidArgumentException(
'Parent folder "' . $parentFolder->getIdentifier() .
'" does not exist.', 1325689164);
2272 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to create directories in the folder "' . $parentFolder->getIdentifier() .
'"', 1323059807);
2274 if ($this->driver->folderExistsInFolder($folderName, $parentFolder->getIdentifier())) {
2275 throw new Exception\ExistingTargetFolderException(
'Folder "' . $folderName .
'" already exists.', 1423347324);
2280 $newFolder = $this->
getDriver()->createFolder($folderName, $parentFolder->getIdentifier(),
true);
2281 $newFolder = $this->
getFolder($newFolder);
2295 return $this->
getFolder($this->driver->getDefaultFolder());
2306 public function getFolder($identifier, $returnInaccessibleFolderObject =
false)
2308 $data = $this->driver->getFolderInfoByIdentifier($identifier);
2313 }
catch (
Exception\InsufficientFolderAccessPermissionsException $e) {
2315 if ($returnInaccessibleFolderObject) {
2317 $parentPermissions = $this->driver->getPermissions($this->driver->getParentFolderIdentifierOfIdentifier($identifier));
2318 if ($parentPermissions[
'r']) {
2320 \TYPO3\CMS\Core\Resource\InaccessibleFolder::class, $this, $data[
'identifier'], $data[
'name']
2325 if ($folder === null) {
2340 $inProcessingFolder =
false;
2342 if ($this->driver->isWithin($processingFolder->getIdentifier(), $identifier)) {
2343 $inProcessingFolder =
true;
2347 return $inProcessingFolder;
2361 throw new \InvalidArgumentException(
'Given folder "' . $folder->
getIdentifier() .
'" is not part of this storage!', 1422709241);
2379 if ($respectFileMounts && !empty($this->fileMounts)) {
2380 $mount = reset($this->fileMounts);
2381 return $mount[
'folder'];
2396 list($fileName) = $this->
getSignalSlotDispatcher()->dispatch(ResourceStorage::class, self::SIGNAL_SanitizeFileName, array($fileName, $targetFolder, $this, $this->driver));
2410 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PreFileAdd, array(&$targetFileName, $targetFolder, $sourceFilePath, $this, $this->driver));
2411 return $targetFileName;
2423 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PostFileAdd, array($file, $targetFolder));
2435 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PreFileCopy, array($file, $targetFolder));
2447 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PostFileCopy, array($file, $targetFolder));
2459 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PreFileMove, array($file, $targetFolder));
2472 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PostFileMove, array($file, $targetFolder, $originalFolder));
2484 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PreFileRename, array($file, $targetFolder));
2496 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PostFileRename, array($file, $targetFolder));
2508 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PreFileReplace, array($file, $localFilePath));
2520 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PostFileReplace, array($file, $localFilePath));
2531 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PostFileCreate, array($newFileIdentifier, $targetFolder));
2542 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PreFileDelete, array($file));
2553 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PostFileDelete, array($file));
2565 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PostFileSetContents, array($file, $content));
2577 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PreFolderAdd, array($targetFolder, $name));
2588 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PostFolderAdd, array($folder));
2601 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PreFolderCopy, array($folder, $targetFolder, $newName));
2614 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PostFolderCopy, array($folder, $targetFolder, $newName));
2627 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PreFolderMove, array($folder, $targetFolder, $newName));
2641 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PostFolderMove, array($folder, $targetFolder, $newName, $originalFolder));
2653 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PreFolderRename, array($folder, $newName));
2665 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PostFolderRename, array($folder, $newName));
2676 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PreFolderDelete, array($folder));
2687 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PostFolderDelete, array($folder));
2699 $this->
getSignalSlotDispatcher()->dispatch(\TYPO3\CMS\Core\Resource\ResourceStorage::class, self::SIGNAL_PreGeneratePublicUrl, array($this, $this->driver, $resourceObject, $relativeToCurrentScript, $urlData));
2717 static $maxNumber = 99, $uniqueNamePrefix =
'';
2721 if ($uniqueNamePrefix) {
2722 $origFileInfo[
'basename'] = $uniqueNamePrefix . $origFileInfo[
'basename'];
2723 $origFileInfo[
'filename'] = $uniqueNamePrefix . $origFileInfo[
'filename'];
2727 $theDestFile = $origFileInfo[
'basename'];
2729 if (!$this->driver->fileExistsInFolder($theDestFile, $folder->
getIdentifier()) || $dontCheckForUnique) {
2730 return $theDestFile;
2735 $theTempFileBody = preg_replace(
'/_[0-9][0-9]$/',
'', $origFileInfo[
'filename']);
2736 $theOrigExt = $origFileInfo[
'extension'] ?
'.' . $origFileInfo[
'extension'] :
'';
2737 for ($a = 1; $a <= $maxNumber + 1; $a++) {
2739 if ($a <= $maxNumber) {
2740 $insert =
'_' . sprintf(
'%02d', $a);
2742 $insert =
'_' . substr(md5(uniqid(
'',
true)), 0, 6);
2744 $theTestFile = $theTempFileBody . $insert . $theOrigExt;
2746 $theDestFile = $theTestFile;
2748 if (!$this->driver->fileExistsInFolder($theDestFile, $folder->
getIdentifier())) {
2749 return $theDestFile;
2752 throw new \RuntimeException(
'Last possible name "' . $theDestFile .
'" is already taken.', 1325194291);
2762 if (!isset($this->signalSlotDispatcher)) {
2763 $this->signalSlotDispatcher = $this->
getObjectManager()->get(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
2799 if (!$this->fileProcessingService) {
2800 $this->fileProcessingService =
GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Service\FileProcessingService::class, $this, $this->driver);
2815 if (method_exists($this->driver,
'getRole')) {
2816 $folderRole = $this->driver->getRole($folder->
getIdentifier());
2818 if (isset($this->fileMounts[$identifier])) {
2821 if (!empty($this->fileMounts[$identifier][
'read_only'])) {
2824 if ($this->fileMounts[$identifier][
'user_mount']) {
2843 if (!isset($this->processingFolder)) {
2845 if (!empty($this->storageRecord[
'processingfolder'])) {
2859 }
catch (
Exception\InsufficientFolderWritePermissionsException $e) {
2863 }
catch (
Exception\ResourcePermissionsUnavailableException $e) {
2879 return $this->storageRecord[
'driver'];