17 use Psr\Http\Message\ResponseInterface;
185 $this->capabilities =
187 ($this->storageRecord[
'is_public'] ??
null ? self::CAPABILITY_PUBLIC : 0) |
190 self::CAPABILITY_HIERARCHICAL_IDENTIFIERS;
194 $this->driver->mergeConfigurationCapabilities($this->capabilities);
196 $this->driver->processConfiguration();
197 }
catch (
Exception\InvalidConfigurationException $e) {
202 'Failed initializing storage [%d] "%s", error: %s',
209 GeneralUtility::makeInstance(LogManager::class)->getLogger(static::class)->error($message);
211 $this->driver->initialize();
212 $this->capabilities = $this->driver->getCapabilities();
277 return $this->storageRecord[
'name'];
287 return (
int)($this->storageRecord[
'uid'] ?? 0);
322 return ($this->capabilities & $capability) == $capability;
366 return $this->
hasCapability(self::CAPABILITY_HIERARCHICAL_IDENTIFIERS);
381 if (!$folder->checkActionPermission(
'read')) {
390 $useFilters ? $this->getFileAndFolderNameFilters() : []
401 return $this->driver->isCaseSensitiveFileSystem();
416 if ($this->storageRecord[
'is_online'] == 0) {
421 if (TYPO3_MODE ===
'FE') {
425 $registryObject = GeneralUtility::makeInstance(Registry::class);
426 $offlineUntil = $registryObject->get(
'core',
'sys_file_storage-' . $this->
getUid() .
'-offline-until');
427 if ($offlineUntil && $offlineUntil > time()) {
445 return !empty($this->storageRecord[
'auto_extract_metadata']);
459 GeneralUtility::makeInstance(ConnectionPool::class)
460 ->getConnectionForTable(
'sys_file_storage')
464 [
'uid' => (
int)$this->
getUid()]
467 $this->storageRecord[
'is_online'] = 0;
479 $registryObject = GeneralUtility::makeInstance(Registry::class);
480 $registryObject->set(
'core',
'sys_file_storage-' . $this->
getUid() .
'-offline-until', time() + 60 * 5);
481 $this->storageRecord[
'is_online'] = 0;
497 public function addFileMount($folderIdentifier, $additionalData = [])
500 if ($this->driver->folderExists($folderIdentifier) ===
false) {
503 throw new Exception\FolderDoesNotExistException(
'Folder for file mount ' . $folderIdentifier .
' does not exist.', 1334427099);
505 $data = $this->driver->getFolderInfoByIdentifier($folderIdentifier);
510 !empty($this->fileMounts[$folderIdentifier])
511 && empty($this->fileMounts[$folderIdentifier][
'read_only'])
512 && !empty($additionalData[
'read_only'])
517 if (empty($additionalData)) {
519 'path' => $folderIdentifier,
520 'title' => $folderIdentifier,
521 'folder' => $folderObject
524 $additionalData[
'folder'] = $folderObject;
525 if (!isset($additionalData[
'title'])) {
526 $additionalData[
'title'] = $folderIdentifier;
529 $this->fileMounts[$folderIdentifier] = $additionalData;
552 if (!$this->evaluatePermissions) {
555 $isWithinFileMount =
false;
559 $identifier = $subject->getIdentifier();
563 $isWithinFileMount =
true;
567 $writableFileMountAvailable =
false;
568 foreach ($this->fileMounts as $fileMount) {
570 $folder = $fileMount[
'folder'];
571 if ($this->driver->isWithin($folder->getIdentifier(), $identifier)) {
572 $isWithinFileMount =
true;
573 if (!$checkWriteAccess) {
576 if (empty($fileMount[
'read_only'])) {
577 $writableFileMountAvailable =
true;
582 $isWithinFileMount = $checkWriteAccess ? $writableFileMountAvailable : $isWithinFileMount;
584 return $isWithinFileMount;
629 if (!$this->evaluatePermissions) {
634 if (!empty($this->userPermissions[strtolower($action) . ucfirst(strtolower($type))])) {
658 if ($action ===
'editMeta') {
669 $isReadCheck =
false;
670 if (in_array($action, [
'read',
'copy',
'move',
'replace'],
true)) {
673 $isWriteCheck =
false;
674 if (in_array($action, [
'add',
'write',
'move',
'rename',
'replace',
'delete'],
true)) {
675 $isWriteCheck =
true;
684 if (!$isProcessedFile && $file instanceof
File) {
685 $isMissing = $file->isMissing();
688 if ($this->driver->fileExists($file->
getIdentifier()) ===
false) {
689 $file->setMissing(
true);
694 if ($isWriteCheck && ($isMissing || !$this->
isWritable())) {
700 $filePermissions = $this->driver->getPermissions($file->
getIdentifier());
701 if ($isReadCheck && !$filePermissions[
'r']) {
704 if ($isWriteCheck && !$filePermissions[
'w']) {
729 if ($folder ===
null) {
733 $isReadCheck =
false;
734 if (in_array($action, [
'read',
'copy'],
true)) {
737 $isWriteCheck =
false;
738 if (in_array($action, [
'add',
'move',
'write',
'delete',
'rename'],
true)) {
739 $isWriteCheck =
true;
755 $folderPermissions = $this->driver->getPermissions($folder->getIdentifier());
756 if ($isReadCheck && !$folderPermissions[
'r']) {
759 if ($isWriteCheck && !$folderPermissions[
'w']) {
772 trigger_error(__METHOD__ .
' is deprecated. This method will be removed without substitution, use the ResourceStorage API instead', \E_USER_DEPRECATED);
773 foreach ($this->fileAndFolderNameFilters as $filter) {
774 if (is_callable($filter)) {
775 $result = call_user_func($filter, $fileOrFolder->getName(), $fileOrFolder->getIdentifier(), $fileOrFolder->getParentFolder()->getIdentifier(), [], $this->driver);
778 if ($result === -1) {
781 if ($result ===
false) {
782 throw new \RuntimeException(
783 'Could not apply file/folder name filter ' . $filter[0] .
'::' . $filter[1],
802 $fileName = $this->driver->sanitizeFileName($fileName);
803 return GeneralUtility::verifyFilenameAgainstDenyPattern($fileName);
815 if ($folder ===
null) {
816 throw new Exception\InsufficientFolderAccessPermissionsException(
817 'You are not allowed to read folders',
821 throw new Exception\InsufficientFolderAccessPermissionsException(
822 'You are not allowed to access the given folder: "' . $folder->getName() .
'"',
841 throw new Exception\InsufficientUserPermissionsException(
'You are not allowed to delete folders recursively', 1377779423);
845 throw new Exception\InsufficientFolderAccessPermissionsException(
846 'You are not allowed to delete the given folder: "' . $folder->getName() .
'"',
854 throw new Exception\InsufficientFolderWritePermissionsException(
'Writing to folders is not allowed.', 1377779111);
868 throw new Exception\InsufficientFileAccessPermissionsException(
869 'You are not allowed to access that file: "' . $file->getName() .
'"',
874 throw new Exception\IllegalFileExtensionException(
875 'You are not allowed to use that file extension. File: "' . $file->getName() .
'"',
893 throw new Exception\InsufficientFileWritePermissionsException(
'Writing to file "' . $file->getIdentifier() .
'" is not allowed.', 1330121088);
896 throw new Exception\IllegalFileExtensionException(
'You are not allowed to edit a file with extension "' . $file->getExtension() .
'"', 1366711933);
911 throw new Exception\InsufficientFileWritePermissionsException(
'Replacing file "' . $file->getIdentifier() .
'" is not allowed.', 1436899571);
915 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to write to the target folder "' . $file->getIdentifier() .
'"', 1436899572);
931 throw new Exception\IllegalFileExtensionException(
'You are not allowed to delete a file with extension "' . $file->getExtension() .
'"', 1377778916);
934 if (!$file instanceof ProcessedFile) {
937 throw new Exception\InsufficientFileWritePermissionsException(
'You are not allowed to delete the file "' . $file->getIdentifier() .
'"', 1319550425);
943 throw new Exception\InsufficientFolderWritePermissionsException(
'Writing to folders is not allowed.', 1377778702);
963 throw new Exception\IllegalFileExtensionException(
'Extension of file name is not allowed in "' . $targetFileName .
'"!', 1322120271);
967 throw new Exception\InsufficientUserPermissionsException(
'You are not allowed to add files to this storage "' . $this->
getUid() .
'"', 1376992145);
971 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to write to the target folder "' . $targetFolder->getIdentifier() .
'"', 1322120356);
993 if (!is_uploaded_file($localFilePath)) {
994 throw new Exception\UploadException(
'The upload has failed, no uploaded file found!', 1322110455);
997 $maxUploadFileSize = GeneralUtility::getMaxUploadFileSize() * 1024;
998 if ($maxUploadFileSize > 0 && $uploadedFileSize >= $maxUploadFileSize) {
999 unlink($localFilePath);
1000 throw new Exception\UploadSizeException(
'The uploaded file exceeds the size-limit of ' . $maxUploadFileSize .
' bytes', 1322110041);
1020 throw new \RuntimeException(
'The target folder is not in the same storage. Target folder given: "' . $targetFolder->
getIdentifier() .
'"', 1422553107);
1024 throw new Exception\IllegalFileExtensionException(
'Extension of file name is not allowed in "' . $targetFileName .
'"!', 1378243279);
1028 throw new Exception\InsufficientUserPermissionsException(
'You are not allowed to move files to storage "' . $this->
getUid() .
'"', 1319219349);
1032 throw new Exception\InsufficientFolderAccessPermissionsException(
'You are not allowed to write to the target folder "' . $targetFolder->
getIdentifier() .
'"', 1319219350);
1050 throw new Exception\IllegalFileExtensionException(
'You are not allowed to rename a file with this extension. File given: "' . $file->getName() .
'"', 1371466663);
1054 throw new Exception\InsufficientUserPermissionsException(
'You are not allowed to rename files. File given: "' . $file->getName() .
'"', 1319219351);
1061 throw new Exception\InsufficientFileWritePermissionsException(
'You are not allowed to write to folders', 1319219352);
1082 if ($this->
getUid() != $targetFolder->getStorage()->getUid()) {
1083 throw new Exception(
'The operation of the folder cannot be called by this storage "' . $this->
getUid() .
'"', 1319550405);
1086 if (!$file->getStorage()->checkFileActionPermission(
'copy', $file)) {
1087 throw new Exception\InsufficientFileReadPermissionsException(
'You are not allowed to copy the file "' . $file->getIdentifier() .
'"', 1319550426);
1091 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to write to the target folder "' . $targetFolder->getIdentifier() .
'"', 1319550435);
1095 throw new Exception\IllegalFileExtensionException(
'You are not allowed to copy a file of that type.', 1319553317);
1116 if ($this->
getUid() !== $targetParentFolder->getStorage()->getUid()) {
1117 throw new Exception(
'The operation of the folder cannot be called by this storage "' . $this->
getUid() .
'"', 1377777624);
1119 if (!$folderToCopy instanceof Folder) {
1120 throw new \RuntimeException(
'The folder "' . $folderToCopy->getIdentifier() .
'" to copy is not of type folder.', 1384209020);
1123 if (!$folderToCopy->getStorage()->checkFolderActionPermission(
'copy', $folderToCopy)) {
1124 throw new Exception\InsufficientFileReadPermissionsException(
'You are not allowed to copy the folder "' . $folderToCopy->getIdentifier() .
'"', 1377777629);
1126 if (!$targetParentFolder instanceof Folder) {
1127 throw new \RuntimeException(
'The target folder "' . $targetParentFolder->getIdentifier() .
'" is not of type folder.', 1384209021);
1131 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to write to the target folder "' . $targetParentFolder->getIdentifier() .
'"', 1377777635);
1152 if ($this->
getUid() !== $targetParentFolder->getStorage()->getUid()) {
1153 throw new \InvalidArgumentException(
'Cannot move a folder into a folder that does not belong to this storage.', 1325777289);
1155 if (!$folderToMove instanceof Folder) {
1156 throw new \RuntimeException(
'The folder "' . $folderToMove->getIdentifier() .
'" to move is not of type Folder.', 1384209022);
1161 if (!$folderToMove->getStorage()->checkFolderActionPermission(
'move', $folderToMove)) {
1162 throw new Exception\InsufficientFileReadPermissionsException(
'You are not allowed to copy the folder "' . $folderToMove->getIdentifier() .
'"', 1377778045);
1164 if (!$targetParentFolder instanceof Folder) {
1165 throw new \RuntimeException(
'The target folder "' . $targetParentFolder->getIdentifier() .
'" is not of type Folder.', 1384209023);
1169 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to write to the target folder "' . $targetParentFolder->getIdentifier() .
'"', 1377778049);
1186 $fileName = $this->driver->sanitizeFileName($fileName);
1214 if (!is_uploaded_file($localFilePath) && !file_exists($localFilePath)) {
1215 throw new \InvalidArgumentException(
'File "' . $localFilePath .
'" does not exist.', 1319552745);
1225 $replaceExisting =
false;
1227 throw new Exception\ExistingTargetFileNameException(
'File "' . $targetFileName .
'" already exists in folder ' . $targetFolder->
getIdentifier(), 1322121068);
1230 $targetFileName = $this->
getUniqueName($targetFolder, $targetFileName);
1232 $replaceExisting =
true;
1235 $fileIdentifier = $this->driver->addFile($localFilePath, $targetFolder->
getIdentifier(), $targetFileName, $removeOriginal);
1238 if ($replaceExisting && $file instanceof
File) {
1262 if (!file_exists($localFilePath)) {
1263 throw new \InvalidArgumentException(
'File "' . $localFilePath .
'" does not exist.', 1319552746);
1271 return $processedFile;
1297 $hash = $this->driver->hash($fileIdentifier, $hash);
1298 if (!is_string($hash) || $hash ===
'') {
1314 if (is_object($file) && $file instanceof FileInterface) {
1316 $file = $file->getIdentifier();
1318 return $this->driver->hashIdentifier($file);
1331 public function getPublicUrl(ResourceInterface $resourceObject, $relativeToCurrentScript =
false)
1340 && $resourceObject instanceof File
1343 $publicUrl = $helper->getPublicUrl($resourceObject, $relativeToCurrentScript);
1347 if ($publicUrl ===
null) {
1349 $publicUrl = $this->driver->getPublicUrl($resourceObject->getIdentifier());
1352 if ($publicUrl ===
null && $resourceObject instanceof FileInterface) {
1353 $queryParameterArray = [
'eID' =>
'dumpFile',
't' =>
''];
1354 if ($resourceObject instanceof File) {
1355 $queryParameterArray[
'f'] = $resourceObject->getUid();
1356 $queryParameterArray[
't'] =
'f';
1357 } elseif ($resourceObject instanceof ProcessedFile) {
1358 $queryParameterArray[
'p'] = $resourceObject->getUid();
1359 $queryParameterArray[
't'] =
'p';
1362 $queryParameterArray[
'token'] = GeneralUtility::hmac(implode(
'|', $queryParameterArray),
'resourceStorageDumpFile');
1364 $publicUrl .=
'?' . http_build_query($queryParameterArray,
'',
'&', PHP_QUERY_RFC3986);
1369 if ($publicUrl !==
null && $relativeToCurrentScript && !GeneralUtility::isValidUrl($publicUrl)) {
1373 $publicUrl = $pathPart . $filePart;
1392 if ($fileObject->getStorage() !== $this) {
1393 throw new \InvalidArgumentException(
'Cannot process files of foreign storage', 1353401835);
1397 return $processedFile;
1409 $filePath = $this->driver->getFileForLocalProcessing($fileObject->getIdentifier(), $writable);
1419 public function getFile($identifier)
1422 if (!$this->driver->fileExists($identifier)) {
1435 public function getFileInfo(FileInterface $fileObject)
1450 return $this->driver->getFileInfoByIdentifier($identifier, $propertiesToExtract);
1458 $this->fileAndFolderNameFilters = [];
1466 $this->fileAndFolderNameFilters =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'fal'][
'defaultFilterCallbacks'];
1485 $this->fileAndFolderNameFilters = $filters;
1494 $this->fileAndFolderNameFilters[] = $filter;
1504 return $this->driver->getParentFolderIdentifierOfIdentifier($fileIdentifier);
1516 $identifier = $this->driver->getFileInFolder($fileName, $folder->getIdentifier());
1535 public function getFilesInFolder(Folder $folder, $start = 0, $maxNumberOfItems = 0, $useFilters =
true, $recursive =
false, $sort =
'', $sortRev =
false)
1541 $filters = $useFilters ==
true ? $this->fileAndFolderNameFilters : [];
1542 $fileIdentifiers = array_values($this->driver->getFilesInFolder($folder->getIdentifier(), $start, $maxNumberOfItems, $recursive, $filters, $sort, $sortRev));
1545 foreach ($fileIdentifiers as $identifier) {
1546 if (isset($rows[$identifier])) {
1551 if ($fileObject instanceof FileInterface) {
1553 while (isset($items[$key])) {
1556 $items[$key] = $fileObject;
1571 $filters = $useFilters ==
true ? $this->fileAndFolderNameFilters : [];
1572 return $this->driver->getFilesInFolder($folderIdentifier, 0, 0, $recursive, $filters);
1582 public function countFilesInFolder(Folder $folder, $useFilters =
true, $recursive =
false)
1585 $filters = $useFilters ? $this->fileAndFolderNameFilters : [];
1586 return $this->driver->countFilesInFolder($folder->getIdentifier(), $recursive, $filters);
1597 $filters = $useFilters ==
true ? $this->fileAndFolderNameFilters : [];
1598 return $this->driver->getFoldersInFolder($folderIdentifier, 0, 0, $recursive, $filters);
1613 return $this->driver->fileExists($identifier);
1623 if ($this->processingFolders ===
null) {
1624 $this->processingFolders = [];
1627 $storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
1628 $allStorages = $storageRepository->findAll();
1629 foreach ($allStorages as $storage) {
1632 list($storageUid, $processingFolderIdentifier) = array_pad(GeneralUtility::trimExplode(
':', $storage->getStorageRecord()[
'processingfolder']), 2,
null);
1633 if (empty($processingFolderIdentifier) || (
int)$storageUid !== $this->
getUid()) {
1637 if ($potentialProcessingFolder->getStorage() === $this && $potentialProcessingFolder->getIdentifier() !== $this->getProcessingFolder()->getIdentifier()) {
1638 $this->processingFolders[] = $potentialProcessingFolder;
1655 $isProcessingFolder =
false;
1658 $isProcessingFolder =
true;
1662 return $isProcessingFolder;
1675 return $this->driver->fileExistsInFolder($fileName, $folder->
getIdentifier());
1689 return $this->driver->getFileContents($file->getIdentifier());
1704 trigger_error(
'ResourceStorage->dumpFileContents() will be removed in TYPO3 v10.0. Use streamFile() instead.', E_USER_DEPRECATED);
1706 $downloadName = $alternativeFilename ?: $file->
getName();
1707 $contentDisposition = $asDownload ?
'attachment' :
'inline';
1708 header(
'Content-Disposition: ' . $contentDisposition .
'; filename="' . $downloadName .
'"');
1709 header(
'Content-Type: ' . ($overrideMimeType ?: $file->
getMimeType()));
1710 header(
'Content-Length: ' . $file->
getSize());
1714 header(
"Cache-Control: ''");
1717 gmdate(
'D, d M Y H:i:s', array_pop($this->driver->getFileInfoByIdentifier($file->
getIdentifier(), [
'mtime']))) .
' GMT',
1723 while (ob_get_level() > 0) {
1739 FileInterface $file,
1740 bool $asDownload =
false,
1741 string $alternativeFilename =
null,
1742 string $overrideMimeType =
null
1743 ): ResponseInterface {
1744 if (!$this->driver instanceof StreamableDriverInterface) {
1745 return $this->
getPseudoStream($file, $asDownload, $alternativeFilename, $overrideMimeType);
1749 'as_download' => $asDownload,
1750 'filename_overwrite' => $alternativeFilename,
1751 'mimetype_overwrite' => $overrideMimeType,
1753 return $this->driver->streamFile($file->getIdentifier(), $properties);
1767 bool $asDownload =
false,
1768 string $alternativeFilename =
null,
1769 string $overrideMimeType =
null
1771 $downloadName = $alternativeFilename ?: $file->
getName();
1772 $contentDisposition = $asDownload ?
'attachment' :
'inline';
1776 'Content-Disposition' => $contentDisposition .
'; filename="' . $downloadName .
'"',
1777 'Content-Type' => $overrideMimeType ?: $file->
getMimeType(),
1778 'Content-Length' => (string)$file->
getSize(),
1779 'Last-Modified' => gmdate(
'D, d M Y H:i:s', array_pop($this->driver->getFileInfoByIdentifier($file->
getIdentifier(), [
'mtime']))) .
' GMT',
1782 'Cache-Control' =>
'',
1805 $result = $this->driver->setFileContents($file->
getIdentifier(), $contents);
1806 if ($file instanceof
File) {
1829 $newFileIdentifier = $this->driver->createFile($fileName, $targetFolderObject->
getIdentifier());
1849 if ($this->driver->fileExists($fileObject->getIdentifier())) {
1852 $this->evaluatePermissions =
false;
1855 if ($recyclerFolder ===
null) {
1856 $result = $this->driver->deleteFile($fileObject->getIdentifier());
1858 $result = $this->
moveFile($fileObject, $recyclerFolder);
1862 $this->evaluatePermissions = $currentPermissions;
1865 throw new Exception\FileOperationErrorException(
'Deleting the file "' . $fileObject->getIdentifier() .
'\' failed.
', 1329831691);
1868 // Mark the file object as deleted
1869 if ($deleted && $fileObject instanceof AbstractFile) {
1870 $fileObject->setDeleted();
1873 $this->emitPostFileDeleteSignal($fileObject);
1892 public function copyFile(FileInterface $file, Folder $targetFolder, $targetFileName = null, $conflictMode = DuplicationBehavior::RENAME)
1894 $conflictMode = DuplicationBehavior::cast($conflictMode);
1895 if ($targetFileName === null) {
1896 $targetFileName = $file->getName();
1898 $sanitizedTargetFileName = $this->driver->sanitizeFileName($targetFileName);
1899 $this->assureFileCopyPermissions($file, $targetFolder, $sanitizedTargetFileName);
1900 $this->emitPreFileCopySignal($file, $targetFolder);
1901 // File exists and we should abort, let's abort
1903 throw new Exception\ExistingTargetFileNameException(
'The target file already exists.', 1320291064);
1907 $sanitizedTargetFileName = $this->getUniqueName($targetFolder, $sanitizedTargetFileName);
1912 if ($sourceStorage === $this) {
1913 $newFileObjectIdentifier = $this->driver->copyFileWithinStorage($file->
getIdentifier(), $targetFolder->getIdentifier(), $sanitizedTargetFileName);
1916 $newFileObjectIdentifier = $this->driver->addFile($tempPath, $targetFolder->getIdentifier(), $sanitizedTargetFileName);
1920 return $newFileObject;
1941 if ($targetFileName ===
null) {
1942 $targetFileName = $file->
getName();
1945 $sanitizedTargetFileName = $this->driver->sanitizeFileName($targetFileName);
1947 if ($targetFolder->hasFile($sanitizedTargetFileName)) {
1950 $sanitizedTargetFileName = $this->
getUniqueName($targetFolder, $sanitizedTargetFileName);
1952 throw new Exception\ExistingTargetFileNameException(
'The target file already exists', 1329850997);
1959 if ($sourceStorage === $this) {
1960 $newIdentifier = $this->driver->moveFileWithinStorage($file->
getIdentifier(), $targetFolder->getIdentifier(), $sanitizedTargetFileName);
1961 if (!$file instanceof AbstractFile) {
1962 throw new \RuntimeException(
'The given file is not of type AbstractFile.', 1384209025);
1967 $newIdentifier = $this->driver->addFile($tempPath, $targetFolder->getIdentifier(), $sanitizedTargetFileName);
1970 $currentPermissions = $sourceStorage->evaluatePermissions;
1971 $sourceStorage->evaluatePermissions =
false;
1973 $recyclerFolder = $sourceStorage->getNearestRecyclerFolder($file);
1974 if ($recyclerFolder ===
null) {
1977 $sourceStorage->moveFile($file, $recyclerFolder);
1979 $sourceStorage->evaluatePermissions = $currentPermissions;
1980 if ($file instanceof File) {
1985 }
catch (\
TYPO3\CMS\Core\Exception $e) {
1986 echo $e->getMessage();
2004 if ($file->
getName() === $targetFileName) {
2007 $sanitizedTargetFileName = $this->driver->sanitizeFileName($targetFileName);
2015 $newIdentifier = $this->driver->renameFile($file->
getIdentifier(), $sanitizedTargetFileName);
2016 if ($file instanceof File) {
2020 }
catch (ExistingTargetFileNameException $exception) {
2031 }
catch (\RuntimeException $e) {
2053 if (!file_exists($localFilePath)) {
2054 throw new \InvalidArgumentException(
'File "' . $localFilePath .
'" does not exist.', 1325842622);
2057 $this->driver->replaceFile($file->
getIdentifier(), $localFilePath);
2058 if ($file instanceof File) {
2081 $localFilePath = $uploadedFileData[
'tmp_name'];
2082 if ($targetFolder ===
null) {
2085 if ($targetFileName ===
null) {
2086 $targetFileName = $uploadedFileData[
'name'];
2088 $targetFileName = $this->driver->sanitizeFileName($targetFileName);
2093 $resultObject = $this->
replaceFile($file, $localFilePath);
2095 $resultObject = $this->
addFile($localFilePath, $targetFolder, $targetFileName, (
string)$conflictMode);
2097 return $resultObject;
2112 $folderQueue = [$folder];
2113 while (!empty($folderQueue)) {
2114 $folder = array_shift($folderQueue);
2115 foreach ($folder->getSubfolders() as $subfolder) {
2116 $folderQueue[] = $subfolder;
2118 foreach ($folder->getFiles() as $file) {
2120 $files[$file->getIdentifier()] = $file;
2146 $sourceStorage = $folderToMove->getStorage();
2147 $returnObject =
null;
2148 $sanitizedNewFolderName = $this->driver->sanitizeFileName($newFolderName ?: $folderToMove->getName());
2153 if ($sourceStorage === $this) {
2155 throw new InvalidTargetFolderException(
2157 'Cannot move folder "%s" into target folder "%s", because the target folder is already within the folder to be moved!',
2158 $folderToMove->getName(),
2159 $targetParentFolder->getName()
2164 $fileMappings = $this->driver->moveFolderWithinStorage($folderToMove->getIdentifier(), $targetParentFolder->getIdentifier(), $sanitizedNewFolderName);
2169 foreach ($fileObjects as $oldIdentifier => $fileObject) {
2170 $newIdentifier = $fileMappings[$oldIdentifier];
2171 $fileObject->updateProperties([
'storage' => $this->
getUid(),
'identifier' => $newIdentifier]);
2172 $this->
getIndexer()->updateIndexEntry($fileObject);
2174 $returnObject = $this->
getFolder($fileMappings[$folderToMove->getIdentifier()]);
2176 return $returnObject;
2206 $returnObject =
null;
2207 $sanitizedNewFolderName = $this->driver->sanitizeFileName($newFolderName ?: $folderToCopy->
getName());
2208 if ($folderToCopy instanceof
Folder && $targetParentFolder instanceof
Folder) {
2214 if ($sourceStorage === $this) {
2216 throw new InvalidTargetFolderException(
2218 'Cannot copy folder "%s" into target folder "%s", because the target folder is already within the folder to be copied!',
2225 $this->driver->copyFolderWithinStorage($folderToCopy->
getIdentifier(), $targetParentFolder->
getIdentifier(), $sanitizedNewFolderName);
2231 return $returnObject;
2262 throw new Exception\InsufficientUserPermissionsException(
'You are not allowed to rename the folder "' . $folderObject->getIdentifier() .
'\'', 1357811441);
2265 $sanitizedNewName = $this->driver->sanitizeFileName($newName);
2266 $returnObject =
null;
2267 if ($this->driver->folderExistsInFolder($sanitizedNewName, $folderObject->getIdentifier())) {
2268 throw new \InvalidArgumentException(
'The folder ' . $sanitizedNewName .
' already exists in folder ' . $folderObject->getIdentifier(), 1325418870);
2274 $fileMappings = $this->driver->renameFolder($folderObject->getIdentifier(), $sanitizedNewName);
2276 foreach ($fileObjects as $oldIdentifier => $fileObject) {
2277 $newIdentifier = $fileMappings[$oldIdentifier];
2278 $fileObject->updateProperties([
'identifier' => $newIdentifier]);
2279 $this->
getIndexer()->updateIndexEntry($fileObject);
2281 $returnObject = $this->
getFolder($fileMappings[$folderObject->getIdentifier()]);
2285 return $returnObject;
2300 public function deleteFolder($folderObject, $deleteRecursively =
false)
2302 $isEmpty = $this->driver->isFolderEmpty($folderObject->getIdentifier());
2304 if (!$isEmpty && !$deleteRecursively) {
2305 throw new \RuntimeException(
'Could not delete folder "' . $folderObject->getIdentifier() .
'" because it is not empty.', 1325952534);
2310 foreach ($this->
getFilesInFolder($folderObject, 0, 0,
false, $deleteRecursively) as $file) {
2314 $result = $this->driver->deleteFolder($folderObject->getIdentifier(), $deleteRecursively);
2333 $folderIdentifier = $this->driver->getFolderInFolder($folderName, $parentFolder->
getIdentifier());
2334 return $this->
getFolder($folderIdentifier, $returnInaccessibleFolderObject);
2351 public function getFoldersInFolder(Folder $folder, $start = 0, $maxNumberOfItems = 0, $useFilters =
true, $recursive =
false, $sort =
'', $sortRev =
false)
2353 $filters = $useFilters ==
true ? $this->fileAndFolderNameFilters : [];
2355 $folderIdentifiers = $this->driver->getFoldersInFolder($folder->getIdentifier(), $start, $maxNumberOfItems, $recursive, $filters, $sort, $sortRev);
2360 if (isset($folderIdentifiers[$processingIdentifier])) {
2361 unset($folderIdentifiers[$processingIdentifier]);
2365 foreach ($folderIdentifiers as $folderIdentifier) {
2366 $folders[$folderIdentifier] = $this->
getFolder($folderIdentifier,
true);
2381 $filters = $useFilters ? $this->fileAndFolderNameFilters : [];
2382 return $this->driver->countFoldersInFolder($folder->getIdentifier(), $recursive, $filters);
2394 return $this->driver->folderExists($identifier);
2407 return $this->driver->folderExistsInFolder($folderName, $folder->getIdentifier());
2425 if ($parentFolder ===
null) {
2427 } elseif (!$this->driver->folderExists($parentFolder->getIdentifier())) {
2428 throw new \InvalidArgumentException(
'Parent folder "' . $parentFolder->getIdentifier() .
'" does not exist.', 1325689164);
2431 throw new Exception\InsufficientFolderWritePermissionsException(
'You are not allowed to create directories in the folder "' . $parentFolder->getIdentifier() .
'"', 1323059807);
2433 if ($this->driver->folderExistsInFolder($folderName, $parentFolder->getIdentifier())) {
2434 throw new Exception\ExistingTargetFolderException(
'Folder "' . $folderName .
'" already exists.', 1423347324);
2439 $newFolder = $this->
getDriver()->createFolder($folderName, $parentFolder->getIdentifier(),
true);
2455 return $this->driver->getFolderInfoByIdentifier($folder->
getIdentifier());
2465 return $this->
getFolder($this->driver->getDefaultFolder());
2476 public function getFolder($identifier, $returnInaccessibleFolderObject =
false)
2478 $data = $this->driver->getFolderInfoByIdentifier($identifier);
2483 }
catch (Exception\InsufficientFolderAccessPermissionsException $e) {
2485 if ($returnInaccessibleFolderObject) {
2487 $parentPermissions = $this->driver->getPermissions($this->driver->getParentFolderIdentifierOfIdentifier($identifier));
2488 if ($parentPermissions[
'r']) {
2489 $folder = GeneralUtility::makeInstance(
2490 InaccessibleFolder::class,
2492 $data[
'identifier'],
2498 if ($folder ===
null) {
2513 $inProcessingFolder =
false;
2516 $inProcessingFolder =
true;
2520 return $inProcessingFolder;
2531 public function isWithinFolder(Folder $folder, ResourceInterface $resource)
2533 if ($folder->getStorage() !== $this) {
2534 throw new \InvalidArgumentException(
'Given folder "' . $folder->getIdentifier() .
'" is not part of this storage!', 1422709241);
2536 if ($folder->getStorage() !== $resource->getStorage()) {
2539 return $this->driver->isWithin($folder->getIdentifier(), $resource->getIdentifier());
2552 if ($respectFileMounts && !empty($this->fileMounts)) {
2553 $mount = reset($this->fileMounts);
2554 return $mount[
'folder'];
2583 return $targetFileName;
2626 protected function emitPreFileMoveSignal(FileInterface $file, Folder $targetFolder,
string $targetFileName)
2638 protected function emitPostFileMoveSignal(FileInterface $file, Folder $targetFolder, FolderInterface $originalFolder)
2873 $this->
getSignalSlotDispatcher()->
dispatch(self::class, self::SIGNAL_PreGeneratePublicUrl, [$this, $this->driver, $resourceObject, $relativeToCurrentScript, $urlData]);
2891 protected function getUniqueName(FolderInterface $folder, $theFile, $dontCheckForUnique =
false)
2898 $theDestFile = $origFileInfo[
'basename'];
2900 if (!$this->driver->fileExistsInFolder($theDestFile, $folder->getIdentifier()) || $dontCheckForUnique) {
2901 return $theDestFile;
2906 $theTempFileBody = preg_replace(
'/_[0-9][0-9]$/',
'', $origFileInfo[
'filename']);
2907 $theOrigExt = $origFileInfo[
'extension'] ?
'.' . $origFileInfo[
'extension'] :
'';
2908 for ($a = 1; $a <= $maxNumber + 1; $a++) {
2910 if ($a <= $maxNumber) {
2911 $insert =
'_' . sprintf(
'%02d', $a);
2913 $insert =
'_' . substr(md5(uniqid(
'',
true)), 0, 6);
2915 $theTestFile = $theTempFileBody . $insert . $theOrigExt;
2917 $theDestFile = $theTestFile;
2919 if (!$this->driver->fileExistsInFolder($theDestFile, $folder->getIdentifier())) {
2920 return $theDestFile;
2923 throw new \RuntimeException(
'Last possible name "' . $theDestFile .
'" is already taken.', 1325194291);
2933 if (!isset($this->signalSlotDispatcher)) {
2946 return GeneralUtility::makeInstance(ObjectManager::class);
2954 return GeneralUtility::makeInstance(ResourceFactory::class);
2970 if (!$this->fileProcessingService) {
2971 $this->fileProcessingService = GeneralUtility::makeInstance(Service\FileProcessingService::class, $this, $this->driver);
2986 if (method_exists($this->driver,
'getRole')) {
2989 if (isset($this->fileMounts[$identifier])) {
2992 if (!empty($this->fileMounts[$identifier][
'read_only'])) {
2995 if ($this->fileMounts[$identifier][
'user_mount']) {
3016 if ($file !==
null && $file->getStorage()->getUid() !== $this->getUid()) {
3019 if (!isset($this->processingFolder)) {
3021 if (!empty($this->storageRecord[
'processingfolder'])) {
3026 list($storageUid, $processingFolderIdentifier) = explode(
':',
$processingFolder, 2);
3028 if ($storage->hasFolder($processingFolderIdentifier)) {
3029 $this->processingFolder = $storage->
getFolder($processingFolderIdentifier);
3031 $rootFolder = $storage->getRootLevelFolder(
false);
3032 $currentEvaluatePermissions = $storage->getEvaluatePermissions();
3033 $storage->setEvaluatePermissions(
false);
3035 ltrim($processingFolderIdentifier,
'/'),
3038 $storage->setEvaluatePermissions($currentEvaluatePermissions);
3045 $this->evaluatePermissions =
false;
3050 $this->evaluatePermissions = $currentEvaluatePermissions;
3051 }
catch (\InvalidArgumentException $e) {
3052 $this->processingFolder = GeneralUtility::makeInstance(
3053 InaccessibleFolder::class,
3064 }
catch (Exception\InsufficientFolderWritePermissionsException $e) {
3065 $this->processingFolder = GeneralUtility::makeInstance(
3066 InaccessibleFolder::class,
3071 }
catch (Exception\ResourcePermissionsUnavailableException $e) {
3072 $this->processingFolder = GeneralUtility::makeInstance(
3073 InaccessibleFolder::class,
3082 if (!empty($file)) {
3101 $file->getIdentifier(),
3102 self::PROCESSING_FOLDER_LEVELS
3106 foreach ($nestedFolderNames as $folderName) {
3116 }
catch (
Exception\FolderDoesNotExistException $e) {
3132 if ($levels === 0) {
3135 $hash = md5($fileIdentifier);
3136 for ($i = 1; $i <= $levels; $i++) {
3137 $names[] = substr($hash, $i, 1);
3149 return $this->storageRecord[
'driver'];
3159 return GeneralUtility::makeInstance(Index\Indexer::class, $this);
3217 $recyclerFolder =
null;
3227 $recyclerFolder = $subFolder;
3233 $isFolderLoop = $folder->
getIdentifier() === $parentFolder->getIdentifier();
3234 $folder = $parentFolder;
3235 }
while ($recyclerFolder ===
null && !$isFolderLoop);
3237 return $recyclerFolder;