2 namespace TYPO3\CMS\Core\Utility\File
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Backend\Utility\BackendUtility
;
18 use TYPO3\CMS\Core\Messaging\FlashMessage
;
19 use TYPO3\CMS\Core\Messaging\FlashMessageService
;
20 use TYPO3\CMS\Core\Resource\DuplicationBehavior
;
21 use TYPO3\CMS\Core\Resource\Exception
;
22 use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
;
23 use TYPO3\CMS\Core\Resource\File
;
24 use TYPO3\CMS\Core\Resource\Folder
;
25 use TYPO3\CMS\Core\Resource\ResourceFactory
;
26 use TYPO3\CMS\Core\Resource\ResourceStorage
;
27 use TYPO3\CMS\Core\Utility\CommandUtility
;
28 use TYPO3\CMS\Core\Utility\GeneralUtility
;
29 use TYPO3\CMS\Core\Type\Exception\InvalidEnumerationValueException
;
32 * Contains functions for performing file operations like copying, pasting, uploading, moving,
33 * deleting etc. through the TCE
35 * See document "TYPO3 Core API" for syntax
37 * This class contains functions primarily used by tce_file.php (TYPO3 Core Engine for file manipulation)
38 * Functions include copying, moving, deleting, uploading and so on...
40 * Important internal variables:
42 * $filemounts (see basicFileFunctions)
43 * $f_ext (see basicFileFunctions)
45 * All fileoperations must be within the filemount-paths. Further the fileextension
46 * MUST validate TRUE with the f_ext array
48 * The unzip-function allows unzip only if the destination path has it's f_ext[]['allow'] set to '*'!!
49 * You are allowed to copy/move folders within the same 'space' (web/ftp).
50 * You are allowed to copy/move folders between spaces (web/ftp) IF the destination has it's f_ext[]['allow'] set to '*'!
53 * You should always exclude php-files from the webspace. This will keep people from uploading, copy/moving and renaming files to become executable php scripts.
54 * You should never mount a ftp_space 'below' the webspace so that it reaches into the webspace. This is because if somebody unzips a zip-file in the ftp-space so that it reaches out into the webspace this will be a violation of the safety
55 * For example this is a bad idea: you have an ftp-space that is '/www/' and a web-space that is '/www/htdocs/'
57 class ExtendedFileUtility
extends BasicFileUtility
60 * External static variables:
61 * Notice; some of these are overridden in the start() method with values from $GLOBALS['TYPO3_CONF_VARS']['BE']
62 * Path to unzip-program (with trailing '/')
66 public $unzipPath = '';
69 * If set, the uploaded files will overwrite existing files.
72 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
74 public $dontCheckForUnique = 0;
77 * Defines behaviour when uploading files with names that already exist; possible values are
78 * the values of the \TYPO3\CMS\Core\Resource\DuplicationBehavior enumeration
80 * @var \TYPO3\CMS\Core\Resource\DuplicationBehavior
82 protected $existingFilesConflictMode;
85 * This array is self-explaining (look in the class below).
86 * It grants access to the functions. This could be set from outside in order to enabled functions to users.
87 * See also the function setActionPermissions() which takes input directly from the user-record
91 public $actionPerms = array(
98 'renameFile' => false
,
100 'deleteFile' => false
,
101 // Folder permissions
102 'addFolder' => false
,
103 'readFolder' => false
,
104 'writeFolder' => false
,
105 'copyFolder' => false
,
106 'moveFolder' => false
,
107 'renameFolder' => false
,
108 'deleteFolder' => false
,
109 'recursivedeleteFolder' => false
113 * This is regarded to be the recycler folder
117 public $recyclerFN = '_recycler_';
120 * Will contain map between upload ID and the final filename
124 public $internalUploadMap = array();
129 public $lastError = '';
132 * All error messages from the file operations of this script instance
136 protected $errorMessages = array();
141 protected $fileCmdMap;
146 * @var \TYPO3\CMS\Core\Resource\ResourceFactory
148 protected $fileFactory;
151 * Get existingFilesConflictMode
155 public function getExistingFilesConflictMode()
157 return (string)$this->existingFilesConflictMode
;
161 * Set existingFilesConflictMode
163 * @param \TYPO3\CMS\Core\Resource\DuplicationBehavior|string $existingFilesConflictMode Instance or constant of \TYPO3\CMS\Core\Resource\DuplicationBehavior
167 public function setExistingFilesConflictMode($existingFilesConflictMode)
170 $this->existingFilesConflictMode
= DuplicationBehavior
::cast($existingFilesConflictMode);
171 } catch (InvalidEnumerationValueException
$e) {
174 'Invalid argument, received: "%s", expected a value from enumeration \TYPO3\CMS\Core\Resource\DuplicationBehavior (%s)',
175 $existingFilesConflictMode,
176 implode(', ', DuplicationBehavior
::getConstants())
183 * Initialization of the class
185 * @param array $fileCmds Array with the commands to execute. See "TYPO3 Core API" document
188 public function start($fileCmds)
190 $unzipPath = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['unzip_path']);
191 if (substr($unzipPath, -1) !== '/' && is_dir($unzipPath)) {
192 // Make sure the path ends with a slash
195 $this->unzipPath
= $unzipPath;
196 // Initialize Object Factory
197 $this->fileFactory
= ResourceFactory
::getInstance();
198 // Initializing file processing commands:
199 $this->fileCmdMap
= $fileCmds;
203 * Sets the file action permissions.
204 * If no argument is given, permissions of the currently logged in backend user are taken into account.
206 * @param array $permissions File Permissions.
209 public function setActionPermissions(array $permissions = array())
211 if (empty($permissions)) {
212 $permissions = $GLOBALS['BE_USER']->getFilePermissions();
214 $this->actionPerms
= $permissions;
218 * Processing the command array in $this->fileCmdMap
220 * @return mixed FALSE, if the file functions were not initialized
221 * @throws \UnexpectedValueException
223 public function processData()
226 if (!$this->isInit
) {
229 if (is_array($this->fileCmdMap
)) {
230 // Check if there were uploads expected, but no one made
231 if ($this->fileCmdMap
['upload']) {
232 $uploads = $this->fileCmdMap
['upload'];
233 foreach ($uploads as $upload) {
234 if (empty($_FILES['upload_' . $upload['data']]['name'])
235 ||
(is_array($_FILES['upload_' . $upload['data']]['name'])
236 && empty($_FILES['upload_' . $upload['data']]['name'][0])
239 unset($this->fileCmdMap
['upload'][$upload['data']]);
242 if (empty($this->fileCmdMap
['upload'])) {
243 $this->writelog(1, 1, 108, 'No file was uploaded!', '');
247 // Check if there were new folder names expected, but non given
248 if ($this->fileCmdMap
['newfolder']) {
249 foreach ($this->fileCmdMap
['newfolder'] as $key => $cmdArr) {
250 if (empty($cmdArr['data'])) {
251 unset($this->fileCmdMap
['newfolder'][$key]);
254 if (empty($this->fileCmdMap
['newfolder'])) {
255 $this->writeLog(6, 1, 108, 'No name for new folder given!', '');
259 // Traverse each set of actions
260 foreach ($this->fileCmdMap
as $action => $actionData) {
261 // Traverse all action data. More than one file might be affected at the same time.
262 if (is_array($actionData)) {
263 $result[$action] = array();
264 foreach ($actionData as $cmdArr) {
267 // Branch out based on command:
270 $result[$action][] = $this->func_delete($cmdArr);
273 $result[$action][] = $this->func_copy($cmdArr);
276 $result[$action][] = $this->func_move($cmdArr);
279 $result[$action][] = $this->func_rename($cmdArr);
282 $result[$action][] = $this->func_newfolder($cmdArr);
285 $result[$action][] = $this->func_newfile($cmdArr);
288 $result[$action][] = $this->func_edit($cmdArr);
291 $result[$action][] = $this->func_upload($cmdArr);
294 $result[$action][] = $this->replaceFile($cmdArr);
297 $result[$action][] = $this->func_unzip($cmdArr);
300 // Hook for post-processing the action
301 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_extfilefunc.php']['processData'])) {
302 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_extfilefunc.php']['processData'] as $classRef) {
303 $hookObject = GeneralUtility
::getUserObj($classRef);
304 if (!$hookObject instanceof ExtendedFileUtilityProcessDataHookInterface
) {
305 throw new \
UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtilityProcessDataHookInterface', 1279719168);
307 $hookObject->processData_postProcessAction($action, $cmdArr, $result[$action], $this);
318 * Adds all log error messages from the operations of this script instance to the FlashMessageQueue
322 public function pushErrorMessagesToFlashMessageQueue()
324 foreach ($this->getErrorMessages() as $msg) {
325 $flashMessage = GeneralUtility
::makeInstance(
332 $this->addFlashMessage($flashMessage);
337 * Return all error messages from the file operations of this script instance
339 * @return array all errorMessages as a numerical array
341 public function getErrorMessages()
343 return $this->errorMessages
;
347 * @param int $action The action number. See the functions in the class for a hint. Eg. edit is '9', upload is '1' ...
348 * @param int $error The severity: 0 = message, 1 = error, 2 = System Error, 3 = security notice (admin)
349 * @param int $details_nr This number is unique for every combination of $type and $action. This is the error-message number, which can later be used to translate error messages.
350 * @param string $details This is the default, raw error message in english
351 * @param array $data Array with special information that may go into $details by "%s" marks / sprintf() when the log is shown
354 public function writeLog($action, $error, $details_nr, $details, $data)
356 // Type value for tce_file.php
358 if (is_object($this->getBackendUser())) {
359 $this->getBackendUser()->writelog($type, $action, $error, $details_nr, $details, $data);
362 $this->lastError
= vsprintf($details, $data);
363 $this->errorMessages
[] = $this->lastError
;
367 /*************************************
369 * File operation functions
371 **************************************/
373 * Deleting files and folders (action=4)
375 * @param array $cmds $cmds['data'] is the file/folder to delete
376 * @return bool Returns TRUE upon success
378 public function func_delete(array $cmds)
381 if (!$this->isInit
) {
384 // Example indentifier for $cmds['data'] => "4:mypath/tomyfolder/myfile.jpg"
385 // for backwards compatibility: the combined file identifier was the path+filename
387 $fileObject = $this->getFileObject($cmds['data']);
388 } catch (ResourceDoesNotExistException
$e) {
389 $flashMessage = GeneralUtility
::makeInstance(
391 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileNotFound'), $cmds['data']),
392 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileNotFound'),
396 $this->addFlashMessage($flashMessage);
400 // @todo implement the recycler feature which has been removed from the original implementation
401 // checks to delete the file
402 if ($fileObject instanceof File
) {
403 // check if the file still has references
404 // Exclude sys_file_metadata records as these are no use references
405 $databaseConnection = $this->getDatabaseConnection();
406 $table = 'sys_refindex';
407 $refIndexRecords = $databaseConnection->exec_SELECTgetRows(
410 'deleted=0 AND ref_table=' . $databaseConnection->fullQuoteStr('sys_file', $table)
411 . ' AND ref_uid=' . (int)$fileObject->getUid()
412 . ' AND tablename != ' . $databaseConnection->fullQuoteStr('sys_file_metadata', $table)
415 if (!empty($refIndexRecords)) {
416 $shortcutContent = array();
417 $brokenReferences = array();
419 foreach ($refIndexRecords as $fileReferenceRow) {
420 if ($fileReferenceRow['tablename'] === 'sys_file_reference') {
421 $row = $this->transformFileReferenceToRecordReference($fileReferenceRow);
422 $shortcutRecord = BackendUtility
::getRecord($row['tablename'], $row['recuid']);
424 if ($shortcutRecord) {
425 $shortcutContent[] = '[record:' . $row['tablename'] . ':' . $row['recuid'] . ']';
427 $brokenReferences[] = $fileReferenceRow['ref_uid'];
431 if (!empty($brokenReferences)) {
432 // render a message that the file has broken references
433 $flashMessage = GeneralUtility
::makeInstance(
435 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileHasBrokenReferences'), count($brokenReferences)),
436 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileHasBrokenReferences'),
440 $this->addFlashMessage($flashMessage);
442 if (!empty($shortcutContent)) {
443 // render a message that the file could not be deleted
444 $flashMessage = GeneralUtility
::makeInstance(
446 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileNotDeletedHasReferences'), $fileObject->getName()) . ' ' . implode(', ', $shortcutContent),
447 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileNotDeletedHasReferences'),
448 FlashMessage
::WARNING
,
451 $this->addFlashMessage($flashMessage);
458 $result = $fileObject->delete();
460 // show the user that the file was deleted
461 $flashMessage = GeneralUtility
::makeInstance(
463 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileDeleted'), $fileObject->getName()),
464 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileDeleted'),
468 $this->addFlashMessage($flashMessage);
470 $this->writelog(4, 0, 1, 'File "%s" deleted', array($fileObject->getIdentifier()));
471 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException
$e) {
472 $this->writelog(4, 1, 112, 'You are not allowed to access the file', array($fileObject->getIdentifier()));
473 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException
$e) {
474 $this->writelog(4, 1, 111, 'Target was not within your mountpoints! T="%s"', array($fileObject->getIdentifier()));
475 } catch (\RuntimeException
$e) {
476 $this->writelog(4, 1, 110, 'Could not delete file "%s". Write-permission problem?', array($fileObject->getIdentifier()));
480 /** @var Folder $fileObject */
481 if (!$this->folderHasFilesInUse($fileObject)) {
483 $result = $fileObject->delete(true
);
485 // notify the user that the folder was deleted
486 /** @var FlashMessage $flashMessage */
487 $flashMessage = GeneralUtility
::makeInstance(
489 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderDeleted'), $fileObject->getName()),
490 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.folderDeleted'),
494 $this->addFlashMessage($flashMessage);
496 $this->writelog(4, 0, 3, 'Directory "%s" deleted', array($fileObject->getIdentifier()));
498 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException
$e) {
499 $this->writelog(4, 1, 120, 'Could not delete directory! Is directory "%s" empty? (You are not allowed to delete directories recursively).', array($fileObject->getIdentifier()));
500 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException
$e) {
501 $this->writelog(4, 1, 123, 'You are not allowed to access the directory', array($fileObject->getIdentifier()));
502 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException
$e) {
503 $this->writelog(4, 1, 121, 'Target was not within your mountpoints! T="%s"', array($fileObject->getIdentifier()));
504 } catch (\TYPO3\CMS\Core\Resource\Exception\FileOperationErrorException
$e) {
505 $this->writelog(4, 1, 120, 'Could not delete directory "%s"! Write-permission problem?', array($fileObject->getIdentifier()));
514 * Checks files in given folder recursively for for existing references.
516 * Creates a flash message if there are references.
518 * @param Folder $folder
519 * @return bool TRUE if folder has files in use, FALSE otherwise
521 public function folderHasFilesInUse(Folder
$folder)
523 $files = $folder->getFiles(0, 0, Folder
::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS
, true
);
528 /** @var int[] $fileUids */
530 foreach ($files as $file) {
531 $fileUids[] = $file->getUid();
533 $numberOfReferences = $this->getDatabaseConnection()->exec_SELECTcountRows(
536 'deleted=0 AND ref_table="sys_file" AND ref_uid IN (' . implode(',', $fileUids) . ') AND tablename<>"sys_file_metadata"'
539 $hasReferences = $numberOfReferences > 0;
540 if ($hasReferences) {
541 /** @var FlashMessage $flashMessage */
542 $flashMessage = GeneralUtility
::makeInstance(
544 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderNotDeletedHasFilesWithReferences'),
545 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.folderNotDeletedHasFilesWithReferences'),
546 FlashMessage
::WARNING
,
549 $this->addFlashMessage($flashMessage);
552 return $hasReferences;
556 * Maps results from the fal file reference table on the
557 * structure of the normal reference index table.
559 * @param array $referenceRecord
562 protected function transformFileReferenceToRecordReference(array $referenceRecord)
564 $fileReference = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
566 'sys_file_reference',
567 'uid=' . (int)$referenceRecord['recuid']
570 'recuid' => $fileReference['uid_foreign'],
571 'tablename' => $fileReference['tablenames'],
572 'field' => $fileReference['fieldname'],
575 'sorting' => $fileReference['sorting_foreign']
580 * Gets a File or a Folder object from an identifier [storage]:[fileId]
582 * @param string $identifier
583 * @return \TYPO3\CMS\Core\Resource\Folder|\TYPO3\CMS\Core\Resource\File
584 * @throws \TYPO3\CMS\Core\Resource\Exception\InvalidFileException
586 protected function getFileObject($identifier)
588 $object = $this->fileFactory
->retrieveFileOrFolderObject($identifier);
589 if (!is_object($object)) {
590 throw new \TYPO3\CMS\Core\Resource\Exception\
InvalidFileException('The item ' . $identifier . ' was not a file or directory!!', 1320122453);
592 if ($object->getStorage()->getUid() === 0) {
593 throw new \TYPO3\CMS\Core\Resource\Exception\
InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1375889830);
599 * Copying files and folders (action=2)
601 * $cmds['data'] (string): The file/folder to copy
602 * + example "4:mypath/tomyfolder/myfile.jpg")
603 * + for backwards compatibility: the identifier was the path+filename
604 * $cmds['target'] (string): The path where to copy to.
605 * + example "2:targetpath/targetfolder/"
606 * $cmds['altName'] (string): Use an alternative name if the target already exists
608 * @param array $cmds Command details as described above
609 * @return \TYPO3\CMS\Core\Resource\File
611 protected function func_copy($cmds)
613 if (!$this->isInit
) {
616 $sourceFileObject = $this->getFileObject($cmds['data']);
617 /** @var $targetFolderObject \TYPO3\CMS\Core\Resource\Folder */
618 $targetFolderObject = $this->getFileObject($cmds['target']);
620 if (!$targetFolderObject instanceof Folder
) {
621 $this->writelog(2, 2, 100, 'Destination "%s" was not a directory', array($cmds['target']));
624 // If this is TRUE, we append _XX to the file name if
625 $appendSuffixOnConflict = (string)$cmds['altName'];
626 $resultObject = null
;
627 $conflictMode = $appendSuffixOnConflict !== '' ? DuplicationBehavior
::RENAME
: DuplicationBehavior
::CANCEL
;
629 if ($sourceFileObject instanceof File
) {
631 $resultObject = $sourceFileObject->copyTo($targetFolderObject, null
, $conflictMode);
632 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException
$e) {
633 $this->writelog(2, 1, 114, 'You are not allowed to copy files', '');
634 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException
$e) {
635 $this->writelog(2, 1, 110, 'Could not access all necessary resources. Source file or destination maybe was not within your mountpoints? T="%s", D="%s"', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
636 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException
$e) {
637 $this->writelog(2, 1, 111, 'Extension of file name "%s" is not allowed in "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
638 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException
$e) {
639 $this->writelog(2, 1, 112, 'File "%s" already exists in folder "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
640 } catch (\BadMethodCallException
$e) {
641 $this->writelog(3, 1, 128, 'The function to copy a file between storages is not yet implemented', array());
642 } catch (\RuntimeException
$e) {
643 $this->writelog(2, 2, 109, 'File "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
646 $this->writelog(2, 0, 1, 'File "%s" copied to "%s"', array($sourceFileObject->getIdentifier(), $resultObject->getIdentifier()));
649 // Else means this is a Folder
650 $sourceFolderObject = $sourceFileObject;
652 $resultObject = $sourceFolderObject->copyTo($targetFolderObject, null
, $conflictMode);
653 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException
$e) {
654 $this->writelog(2, 1, 125, 'You are not allowed to copy directories', '');
655 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException
$e) {
656 $this->writelog(2, 1, 110, 'Could not access all necessary resources. Source file or destination maybe was not within your mountpoints? T="%s", D="%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
657 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException
$e) {
658 $this->writelog(2, 1, 121, 'You don\'t have full access to the destination directory "%s"!', array($targetFolderObject->getIdentifier()));
659 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidTargetFolderException
$e) {
660 $this->writelog(2, 1, 122, 'Cannot copy folder "%s" into target folder "%s", because the target folder is already within the folder to be copied!', array($sourceFolderObject->getName(), $targetFolderObject->getName()));
661 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException
$e) {
662 $this->writelog(2, 1, 123, 'Target "%s" already exists!', array($targetFolderObject->getIdentifier()));
663 } catch (\BadMethodCallException
$e) {
664 $this->writelog(3, 1, 129, 'The function to copy a folder between storages is not yet implemented', array());
665 } catch (\RuntimeException
$e) {
666 $this->writelog(2, 2, 119, 'Directory "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
669 $this->writelog(2, 0, 2, 'Directory "%s" copied to "%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
672 return $resultObject;
676 * Moving files and folders (action=3)
678 * $cmds['data'] (string): The file/folder to move
679 * + example "4:mypath/tomyfolder/myfile.jpg")
680 * + for backwards compatibility: the identifier was the path+filename
681 * $cmds['target'] (string): The path where to move to.
682 * + example "2:targetpath/targetfolder/"
683 * $cmds['altName'] (string): Use an alternative name if the target already exists
685 * @param array $cmds Command details as described above
686 * @return \TYPO3\CMS\Core\Resource\File
688 protected function func_move($cmds)
690 if (!$this->isInit
) {
693 $sourceFileObject = $this->getFileObject($cmds['data']);
694 $targetFolderObject = $this->getFileObject($cmds['target']);
696 if (!$targetFolderObject instanceof Folder
) {
697 $this->writelog(3, 2, 100, 'Destination "%s" was not a directory', array($cmds['target']));
700 $alternativeName = (string)$cmds['altName'];
701 $resultObject = null
;
703 if ($sourceFileObject instanceof File
) {
705 if ($alternativeName !== '') {
706 // Don't allow overwriting existing files, but find a new name
707 $resultObject = $sourceFileObject->moveTo($targetFolderObject, $alternativeName, DuplicationBehavior
::RENAME
);
709 // Don't allow overwriting existing files
710 $resultObject = $sourceFileObject->moveTo($targetFolderObject, null
, DuplicationBehavior
::CANCEL
);
712 $this->writelog(3, 0, 1, 'File "%s" moved to "%s"', array($sourceFileObject->getIdentifier(), $resultObject->getIdentifier()));
713 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException
$e) {
714 $this->writelog(3, 1, 114, 'You are not allowed to move files', '');
715 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException
$e) {
716 $this->writelog(3, 1, 110, 'Could not access all necessary resources. Source file or destination maybe was not within your mountpoints? T="%s", D="%s"', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
717 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException
$e) {
718 $this->writelog(3, 1, 111, 'Extension of file name "%s" is not allowed in "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
719 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException
$e) {
720 $this->writelog(3, 1, 112, 'File "%s" already exists in folder "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
721 } catch (\BadMethodCallException
$e) {
722 $this->writelog(3, 1, 126, 'The function to move a file between storages is not yet implemented', array());
723 } catch (\RuntimeException
$e) {
724 $this->writelog(3, 2, 109, 'File "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
727 // Else means this is a Folder
728 $sourceFolderObject = $sourceFileObject;
730 if ($alternativeName !== '') {
731 // Don't allow overwriting existing files, but find a new name
732 $resultObject = $sourceFolderObject->moveTo($targetFolderObject, $alternativeName, DuplicationBehavior
::RENAME
);
734 // Don't allow overwriting existing files
735 $resultObject = $sourceFolderObject->moveTo($targetFolderObject, null
, DuplicationBehavior
::RENAME
);
737 $this->writelog(3, 0, 2, 'Directory "%s" moved to "%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
738 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException
$e) {
739 $this->writelog(3, 1, 125, 'You are not allowed to move directories', '');
740 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException
$e) {
741 $this->writelog(3, 1, 110, 'Could not access all necessary resources. Source file or destination maybe was not within your mountpoints? T="%s", D="%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
742 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException
$e) {
743 $this->writelog(3, 1, 121, 'You don\'t have full access to the destination directory "%s"!', array($targetFolderObject->getIdentifier()));
744 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidTargetFolderException
$e) {
745 $this->writelog(3, 1, 122, 'Cannot move folder "%s" into target folder "%s", because the target folder is already within the folder to be moved!', array($sourceFolderObject->getName(), $targetFolderObject->getName()));
746 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException
$e) {
747 $this->writelog(3, 1, 123, 'Target "%s" already exists!', array($targetFolderObject->getIdentifier()));
748 } catch (\BadMethodCallException
$e) {
749 $this->writelog(3, 1, 127, 'The function to move a folder between storages is not yet implemented', array());
750 } catch (\RuntimeException
$e) {
751 $this->writelog(3, 2, 119, 'Directory "%s" WAS NOT moved to "%s"! Write-permission problem?', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
754 return $resultObject;
758 * Renaming files or foldes (action=5)
760 * $cmds['data'] (string): The file/folder to copy
761 * + example "4:mypath/tomyfolder/myfile.jpg")
762 * + for backwards compatibility: the identifier was the path+filename
763 * $cmds['target'] (string): New name of the file/folder
765 * @param array $cmds Command details as described above
766 * @return \TYPO3\CMS\Core\Resource\File Returns the new file upon success
768 public function func_rename($cmds)
770 if (!$this->isInit
) {
773 $sourceFileObject = $this->getFileObject($cmds['data']);
774 $sourceFile = $sourceFileObject->getName();
775 $targetFile = $cmds['target'];
776 $resultObject = null
;
777 if ($sourceFileObject instanceof File
) {
779 // Try to rename the File
780 $resultObject = $sourceFileObject->rename($targetFile);
781 $this->writelog(5, 0, 1, 'File renamed from "%s" to "%s"', array($sourceFile, $targetFile));
782 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException
$e) {
783 $this->writelog(5, 1, 102, 'You are not allowed to rename files!', '');
784 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException
$e) {
785 $this->writelog(5, 1, 101, 'Extension of file name "%s" or "%s" was not allowed!', array($sourceFileObject->getName(), $targetFile));
786 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException
$e) {
787 $this->writelog(5, 1, 120, 'Destination "%s" existed already!', array($targetFile));
788 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException
$e) {
789 $this->writelog(5, 1, 121, 'Destination path "%s" was not within your mountpoints!', array($targetFile));
790 } catch (\RuntimeException
$e) {
791 $this->writelog(5, 1, 100, 'File "%s" was not renamed! Write-permission problem in "%s"?', array($sourceFileObject->getName(), $targetFile));
794 // Else means this is a Folder
796 // Try to rename the Folder
797 $resultObject = $sourceFileObject->rename($targetFile);
798 $this->writelog(5, 0, 2, 'Directory renamed from "%s" to "%s"', array($sourceFile, $targetFile));
799 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException
$e) {
800 $this->writelog(5, 1, 111, 'You are not allowed to rename directories!', '');
801 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException
$e) {
802 $this->writelog(5, 1, 120, 'Destination "%s" existed already!', array($targetFile));
803 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException
$e) {
804 $this->writelog(5, 1, 121, 'Destination path "%s" was not within your mountpoints!', array($targetFile));
805 } catch (\RuntimeException
$e) {
806 $this->writelog(5, 1, 110, 'Directory "%s" was not renamed! Write-permission problem in "%s"?', array($sourceFileObject->getName(), $targetFile));
809 return $resultObject;
813 * This creates a new folder. (action=6)
815 * $cmds['data'] (string): The new folder name
816 * $cmds['target'] (string): The path where to copy to.
817 * + example "2:targetpath/targetfolder/"
819 * @param array $cmds Command details as described above
820 * @return \TYPO3\CMS\Core\Resource\Folder Returns the new foldername upon success
822 public function func_newfolder($cmds)
824 if (!$this->isInit
) {
827 $targetFolderObject = $this->getFileObject($cmds['target']);
828 if (!$targetFolderObject instanceof Folder
) {
829 $this->writelog(6, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
832 $resultObject = null
;
834 $folderName = $cmds['data'];
835 $resultObject = $targetFolderObject->createFolder($folderName);
836 $this->writelog(6, 0, 1, 'Directory "%s" created in "%s"', array($folderName, $targetFolderObject->getIdentifier() . '/'));
837 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException
$e) {
838 $this->writelog(6, 1, 104, 'Invalid folder name "%s"!', [$folderName]);
839 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException
$e) {
840 $this->writelog(6, 1, 103, 'You are not allowed to create directories!', '');
841 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException
$e) {
842 $this->writelog(6, 1, 102, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier() . '/'));
843 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException
$e) {
844 $this->writelog(6, 1, 101, 'File or directory "%s" existed already!', array($folderName));
845 } catch (\RuntimeException
$e) {
846 $this->writelog(6, 1, 100, 'Directory "%s" not created. Write-permission problem in "%s"?', array($folderName, $targetFolderObject->getIdentifier() . '/'));
848 return $resultObject;
852 * This creates a new file. (action=8)
853 * $cmds['data'] (string): The new file name
854 * $cmds['target'] (string): The path where to create it.
855 * + example "2:targetpath/targetfolder/"
857 * @param array $cmds Command details as described above
858 * @return string Returns the new filename upon success
860 public function func_newfile($cmds)
862 if (!$this->isInit
) {
865 $targetFolderObject = $this->getFileObject($cmds['target']);
866 if (!$targetFolderObject instanceof Folder
) {
867 $this->writelog(8, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
870 $resultObject = null
;
872 $fileName = $cmds['data'];
873 $resultObject = $targetFolderObject->createFile($fileName);
874 $this->writelog(8, 0, 1, 'File created: "%s"', array($fileName));
875 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException
$e) {
876 $this->writeLog(8, 1, 106, 'Extension of file "%s" was not allowed!', array($fileName));
877 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException
$e) {
878 $this->writelog(8, 1, 103, 'You are not allowed to create files!', '');
879 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException
$e) {
880 $this->writelog(8, 1, 102, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier()));
881 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException
$e) {
882 $this->writelog(8, 1, 101, 'File existed already in "%s"!', array($targetFolderObject->getIdentifier()));
883 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException
$e) {
884 $this->writelog(8, 1, 106, 'File name "%s" was not allowed!', $fileName);
885 } catch (\RuntimeException
$e) {
886 $this->writelog(8, 1, 100, 'File "%s" was not created! Write-permission problem in "%s"?', array($fileName, $targetFolderObject->getIdentifier()));
888 return $resultObject;
892 * Editing textfiles or folders (action=9)
894 * @param array $cmds $cmds['data'] is the new content. $cmds['target'] is the target (file or dir)
895 * @return bool Returns TRUE on success
897 public function func_edit($cmds)
899 if (!$this->isInit
) {
902 // Example indentifier for $cmds['target'] => "4:mypath/tomyfolder/myfile.jpg"
903 // for backwards compatibility: the combined file identifier was the path+filename
904 $fileIdentifier = $cmds['target'];
905 $fileObject = $this->getFileObject($fileIdentifier);
906 // Example indentifier for $cmds['target'] => "2:targetpath/targetfolder/"
907 $content = $cmds['data'];
908 if (!$fileObject instanceof File
) {
909 $this->writelog(9, 2, 123, 'Target "%s" was not a file!', array($fileIdentifier));
912 $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
913 if (!GeneralUtility
::inList($extList, $fileObject->getExtension())) {
914 $this->writelog(9, 1, 102, 'File extension "%s" is not a textfile format! (%s)', array($fileObject->getExtension(), $extList));
918 $fileObject->setContents($content);
920 $this->writelog(9, 0, 1, 'File saved to "%s", bytes: %s, MD5: %s ', array($fileObject->getIdentifier(), $fileObject->getSize(), md5($content)));
922 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException
$e) {
923 $this->writelog(9, 1, 104, 'You are not allowed to edit files!', '');
925 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileWritePermissionsException
$e) {
926 $this->writelog(9, 1, 100, 'File "%s" was not saved! Write-permission problem?', array($fileObject->getIdentifier()));
928 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException
$e) {
929 $this->writelog(9, 1, 100, 'File "%s" was not saved! File extension rejected!', array($fileObject->getIdentifier()));
935 * Upload of files (action=1)
936 * when having multiple uploads (HTML5-style), the array $_FILES looks like this:
938 * [upload_1] => Array(
940 * [0] => GData - Content-Elements and Media-Gallery.pdf
941 * [1] => CMS Expo 2011.txt
944 * [0] => application/pdf
947 * [tmp_name] => Array(
948 * [0] => /Applications/MAMP/tmp/php/phpNrOB43
949 * [1] => /Applications/MAMP/tmp/php/phpD2HQAK
957 * in HTML you'd need sth like this: <input type="file" name="upload_1[]" multiple="true" />
959 * @param array $cmds $cmds['data'] is the ID-number (points to the global var that holds the filename-ref ($_FILES['upload_' . $id]['name']) . $cmds['target'] is the target directory, $cmds['charset'] is the the character set of the file name (utf-8 is needed for JS-interaction)
960 * @return File[] | FALSE Returns an array of new file objects upon success. False otherwise
962 public function func_upload($cmds)
964 if (!$this->isInit
) {
967 $uploadPosition = $cmds['data'];
968 $uploadedFileData = $_FILES['upload_' . $uploadPosition];
969 if (empty($uploadedFileData['name']) ||
is_array($uploadedFileData['name']) && empty($uploadedFileData['name'][0])) {
970 $this->writelog(1, 2, 108, 'No file was uploaded!', '');
973 // Example indentifier for $cmds['target'] => "2:targetpath/targetfolder/"
974 $targetFolderObject = $this->getFileObject($cmds['target']);
975 // Uploading with non HTML-5-style, thus, make an array out of it, so we can loop over it
976 if (!is_array($uploadedFileData['name'])) {
977 $uploadedFileData = array(
978 'name' => array($uploadedFileData['name']),
979 'type' => array($uploadedFileData['type']),
980 'tmp_name' => array($uploadedFileData['tmp_name']),
981 'size' => array($uploadedFileData['size'])
984 $resultObjects = array();
985 $numberOfUploadedFilesForPosition = count($uploadedFileData['name']);
986 // Loop through all uploaded files
987 for ($i = 0; $i < $numberOfUploadedFilesForPosition; $i++
) {
989 'name' => $uploadedFileData['name'][$i],
990 'type' => $uploadedFileData['type'][$i],
991 'tmp_name' => $uploadedFileData['tmp_name'][$i],
992 'size' => $uploadedFileData['size'][$i]
995 if ((int)$this->dontCheckForUnique
=== 1) {
996 GeneralUtility
::deprecationLog('dontCheckForUnique = 1 is deprecated. Use setExistingFilesConflictMode(DuplicationBehavior::REPLACE);. Support for dontCheckForUnique will be removed in TYPO3 CMS 8.');
997 $this->existingFilesConflictMode
= DuplicationBehavior
::cast(DuplicationBehavior
::REPLACE
);
1000 /** @var $fileObject File */
1001 $fileObject = $targetFolderObject->addUploadedFile($fileInfo, (string)$this->existingFilesConflictMode
);
1002 $fileObject = ResourceFactory
::getInstance()->getFileObjectByStorageAndIdentifier($targetFolderObject->getStorage()->getUid(), $fileObject->getIdentifier());
1003 if ($this->existingFilesConflictMode
->equals(DuplicationBehavior
::REPLACE
)) {
1004 $this->getIndexer($fileObject->getStorage())->updateIndexEntry($fileObject);
1006 $resultObjects[] = $fileObject;
1007 $this->internalUploadMap
[$uploadPosition] = $fileObject->getCombinedIdentifier();
1008 $this->writelog(1, 0, 1, 'Uploading file "%s" to "%s"', array($fileInfo['name'], $targetFolderObject->getIdentifier()));
1009 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileWritePermissionsException
$e) {
1010 $this->writelog(1, 1, 107, 'You are not allowed to override "%s"!', array($fileInfo['name']));
1011 } catch (\TYPO3\CMS\Core\Resource\Exception\UploadException
$e) {
1012 $this->writelog(1, 2, 106, 'The upload has failed, no uploaded file found!', '');
1013 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException
$e) {
1014 $this->writelog(1, 1, 105, 'You are not allowed to upload files!', '');
1015 } catch (\TYPO3\CMS\Core\Resource\Exception\UploadSizeException
$e) {
1016 $this->writelog(1, 1, 104, 'The uploaded file "%s" exceeds the size-limit', array($fileInfo['name']));
1017 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException
$e) {
1018 $this->writelog(1, 1, 103, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier()));
1019 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException
$e) {
1020 $this->writelog(1, 1, 102, 'Extension of file name "%s" is not allowed in "%s"!', array($fileInfo['name'], $targetFolderObject->getIdentifier()));
1021 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException
$e) {
1022 $this->writelog(1, 1, 101, 'No unique filename available in "%s"!', array($targetFolderObject->getIdentifier()));
1023 } catch (\RuntimeException
$e) {
1024 $this->writelog(1, 1, 100, 'Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolderObject->getIdentifier()));
1028 return $resultObjects;
1032 * Unzipping file (action=7)
1033 * This is permitted only if the user has fullAccess or if the file resides
1035 * @param array $cmds $cmds['data'] is the zip-file. $cmds['target'] is the target directory. If not set we'll default to the same directory as the file is in.
1036 * @return bool Returns TRUE on success
1038 public function func_unzip($cmds)
1040 if (!$this->isInit ||
$this->dont_use_exec_commands
) {
1043 $theFile = $cmds['data'];
1044 if (!@is_file
($theFile)) {
1045 $this->writelog(7, 2, 105, 'The file "%s" did not exist!', array($theFile));
1048 $fI = GeneralUtility
::split_fileref($theFile);
1049 if (!isset($cmds['target'])) {
1050 $cmds['target'] = $fI['path'];
1052 // Clean up destination directory
1053 // !!! Method has been put in the local driver, can be saftely removed
1054 $theDest = $this->is_directory($cmds['target']);
1056 $this->writelog(7, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
1059 if (!$this->actionPerms
['unzipFile']) {
1060 $this->writelog(7, 1, 103, 'You are not allowed to unzip files', '');
1063 if ($fI['fileext'] != 'zip') {
1064 $this->writelog(7, 1, 102, 'File extension is not "zip"', '');
1067 if (!$this->checkIfFullAccess($theDest)) {
1068 $this->writelog(7, 1, 101, 'You don\'t have full access to the destination directory "%s"!', array($theDest));
1071 // !!! Method has been put in the sotrage driver, can be saftely removed
1072 if ($this->checkPathAgainstMounts($theFile) && $this->checkPathAgainstMounts($theDest . '/')) {
1073 // No way to do this under windows.
1074 $cmd = $this->unzipPath
. 'unzip -qq ' . escapeshellarg($theFile) . ' -d ' . escapeshellarg($theDest);
1075 CommandUtility
::exec($cmd);
1076 $this->writelog(7, 0, 1, 'Unzipping file "%s" in "%s"', array($theFile, $theDest));
1079 $this->writelog(7, 1, 100, 'File "%s" or destination "%s" was not within your mountpoints!', array($theFile, $theDest));
1085 * Replaces a file on the filesystem and changes the identifier of the persisted file object in sys_file if keepFilename
1086 * is not checked. If keepFilename is checked, only the file content will be replaced.
1088 * @param array $cmdArr
1089 * @return array|bool
1090 * @throws \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException
1091 * @throws \TYPO3\CMS\Core\Resource\Exception\InvalidFileException
1093 protected function replaceFile(array $cmdArr)
1095 if (!$this->isInit
) {
1099 $uploadPosition = $cmdArr['data'];
1100 $fileInfo = $_FILES['replace_' . $uploadPosition];
1101 if (empty($fileInfo['name'])) {
1102 $this->writelog(1, 2, 108, 'No file was uploaded for replacing!', '');
1106 $keepFileName = ($cmdArr['keepFilename'] == 1) ? true
: false
;
1107 $resultObjects = array();
1110 $fileObjectToReplace = $this->getFileObject($cmdArr['uid']);
1111 $folder = $fileObjectToReplace->getParentFolder();
1112 $resourceStorage = $fileObjectToReplace->getStorage();
1114 $fileObject = $resourceStorage->addUploadedFile($fileInfo, $folder, $fileObjectToReplace->getName(), DuplicationBehavior
::REPLACE
);
1116 // Check if there is a file that is going to be uploaded that has a different name as the replacing one
1117 // but exists in that folder as well.
1118 // rename to another name, but check if the name is already given
1119 if ($keepFileName === false
) {
1120 // if a file with the same name already exists, we need to change it to _01 etc.
1121 // if the file does not exist, we can do a simple rename
1122 $resourceStorage->moveFile($fileObject, $folder, $fileInfo['name'], DuplicationBehavior
::RENAME
);
1125 $resultObjects[] = $fileObject;
1126 $this->internalUploadMap
[$uploadPosition] = $fileObject->getCombinedIdentifier();
1128 $this->writelog(1, 0, 1, 'Replacing file "%s" to "%s"', array($fileInfo['name'], $fileObjectToReplace->getIdentifier()));
1129 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileWritePermissionsException
$e) {
1130 $this->writelog(1, 1, 107, 'You are not allowed to override "%s"!', array($fileInfo['name']));
1131 } catch (\TYPO3\CMS\Core\Resource\Exception\UploadException
$e) {
1132 $this->writelog(1, 2, 106, 'The upload has failed, no uploaded file found!', '');
1133 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException
$e) {
1134 $this->writelog(1, 1, 105, 'You are not allowed to upload files!', '');
1135 } catch (\TYPO3\CMS\Core\Resource\Exception\UploadSizeException
$e) {
1136 $this->writelog(1, 1, 104, 'The uploaded file "%s" exceeds the size-limit', array($fileInfo['name']));
1137 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException
$e) {
1138 $this->writelog(1, 1, 103, 'Destination path "%s" was not within your mountpoints!', array($fileObjectToReplace->getIdentifier()));
1139 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException
$e) {
1140 $this->writelog(1, 1, 102, 'Extension of file name "%s" is not allowed in "%s"!', array($fileInfo['name'], $fileObjectToReplace->getIdentifier()));
1141 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException
$e) {
1142 $this->writelog(1, 1, 101, 'No unique filename available in "%s"!', array($fileObjectToReplace->getIdentifier()));
1143 } catch (\RuntimeException
$e) {
1146 return $resultObjects;
1150 * Add flash message to message queue
1152 * @param FlashMessage $flashMessage
1155 protected function addFlashMessage(FlashMessage
$flashMessage)
1157 /** @var $flashMessageService FlashMessageService */
1158 $flashMessageService = GeneralUtility
::makeInstance(FlashMessageService
::class);
1160 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
1161 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
1162 $defaultFlashMessageQueue->enqueue($flashMessage);
1168 * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
1169 * @return \TYPO3\CMS\Core\Resource\Index\Indexer
1171 protected function getIndexer(ResourceStorage
$storage)
1173 return GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Resource\Index\Indexer
::class, $storage);
1177 * Get database connection
1179 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
1181 protected function getDatabaseConnection()
1183 return $GLOBALS['TYPO3_DB'];
1187 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1189 protected function getBackendUser()
1191 return $GLOBALS['BE_USER'];