[CLEANUP] Make use of possible imports and remove unused ones
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Utility / File / ExtendedFileUtility.php
1 <?php
2 namespace TYPO3\CMS\Core\Utility\File;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
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.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Backend\Utility\IconUtility;
19 use TYPO3\CMS\Core\Messaging\FlashMessage;
20 use TYPO3\CMS\Core\Messaging\FlashMessageService;
21 use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
22 use TYPO3\CMS\Core\Resource\File;
23 use TYPO3\CMS\Core\Resource\Folder;
24 use TYPO3\CMS\Core\Resource\ResourceFactory;
25 use TYPO3\CMS\Core\Resource\ResourceStorage;
26 use TYPO3\CMS\Core\Utility\CommandUtility;
27 use TYPO3\CMS\Core\Utility\GeneralUtility;
28
29 /**
30 * Contains functions for performing file operations like copying, pasting, uploading, moving,
31 * deleting etc. through the TCE
32 *
33 * See document "TYPO3 Core API" for syntax
34 *
35 * This class contains functions primarily used by tce_file.php (TYPO3 Core Engine for file manipulation)
36 * Functions include copying, moving, deleting, uploading and so on...
37 *
38 * Important internal variables:
39 *
40 * $filemounts (see basicFileFunctions)
41 * $f_ext (see basicFileFunctions)
42 *
43 * All fileoperations must be within the filemount-paths. Further the fileextension
44 * MUST validate TRUE with the f_ext array
45 *
46 * The unzip-function allows unzip only if the destination path has it's f_ext[]['allow'] set to '*'!!
47 * You are allowed to copy/move folders within the same 'space' (web/ftp).
48 * You are allowed to copy/move folders between spaces (web/ftp) IF the destination has it's f_ext[]['allow'] set to '*'!
49 *
50 * Advice:
51 * 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.
52 * 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
53 * For example this is a bad idea: you have an ftp-space that is '/www/' and a web-space that is '/www/htdocs/'
54 *
55 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
56 */
57 class ExtendedFileUtility extends BasicFileUtility {
58
59 /**
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 '/')
63 *
64 * @var string
65 */
66 public $unzipPath = '';
67
68 /**
69 * If set, the uploaded files will overwrite existing files.
70 *
71 * @var bool
72 */
73 public $dontCheckForUnique = 0;
74
75 /**
76 * This array is self-explaining (look in the class below).
77 * It grants access to the functions. This could be set from outside in order to enabled functions to users.
78 * See also the function setActionPermissions() which takes input directly from the user-record
79 *
80 * @var array
81 */
82 public $actionPerms = array(
83 // File permissions
84 'addFile' => FALSE,
85 'readFile' => FALSE,
86 'writeFile' => FALSE,
87 'copyFile' => FALSE,
88 'moveFile' => FALSE,
89 'renameFile' => FALSE,
90 'unzipFile' => FALSE,
91 'deleteFile' => FALSE,
92 // Folder permissions
93 'addFolder' => FALSE,
94 'readFolder' => FALSE,
95 'writeFolder' => FALSE,
96 'copyFolder' => FALSE,
97 'moveFolder' => FALSE,
98 'renameFolder' => FALSE,
99 'deleteFolder' => FALSE,
100 'recursivedeleteFolder' => FALSE
101 );
102
103 /**
104 * This is regarded to be the recycler folder
105 *
106 * @var string
107 */
108 public $recyclerFN = '_recycler_';
109
110 /**
111 * Will contain map between upload ID and the final filename
112 *
113 * @var array
114 */
115 public $internalUploadMap = array();
116
117 /**
118 * @var string
119 */
120 public $lastError = '';
121
122 /**
123 * All error messages from the file operations of this script instance
124 *
125 * @var array
126 */
127 protected $errorMessages = array();
128
129 /**
130 * @var array
131 */
132 protected $fileCmdMap;
133
134 /**
135 * The File Factory
136 *
137 * @var \TYPO3\CMS\Core\Resource\ResourceFactory
138 */
139 protected $fileFactory;
140
141 /**
142 * Initialization of the class
143 *
144 * @param array $fileCmds Array with the commands to execute. See "TYPO3 Core API" document
145 * @return void
146 */
147 public function start($fileCmds) {
148 $unzipPath = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['unzip_path']);
149 if (substr($unzipPath, -1) !== '/' && is_dir($unzipPath)) {
150 // Make sure the path ends with a slash
151 $unzipPath .= '/';
152 }
153 $this->unzipPath = $unzipPath;
154 // Initialize Object Factory
155 $this->fileFactory = ResourceFactory::getInstance();
156 // Initializing file processing commands:
157 $this->fileCmdMap = $fileCmds;
158 }
159
160 /**
161 * Sets the file action permissions.
162 * If no argument is given, permissions of the currently logged in backend user are taken into account.
163 *
164 * @param array $permissions File Permissions.
165 */
166 public function setActionPermissions(array $permissions = array()) {
167 if (empty($permissions)) {
168 $permissions = $GLOBALS['BE_USER']->getFilePermissions();
169 }
170 $this->actionPerms = $permissions;
171 }
172
173 /**
174 * Processing the command array in $this->fileCmdMap
175 *
176 * @return mixed FALSE, if the file functions were not initialized
177 * @throws \UnexpectedValueException
178 */
179 public function processData() {
180 $result = array();
181 if (!$this->isInit) {
182 return FALSE;
183 }
184 if (is_array($this->fileCmdMap)) {
185 // Check if there were uploads expected, but no one made
186 if ($this->fileCmdMap['upload']) {
187 $uploads = $this->fileCmdMap['upload'];
188 foreach ($uploads as $upload) {
189 if (empty($_FILES[('upload_' . $upload['data'])]['name'])
190 || (is_array($_FILES[('upload_' . $upload['data'])]['name'])
191 && empty($_FILES[('upload_' . $upload['data'])]['name'][0])
192 )
193 ) {
194 unset($this->fileCmdMap['upload'][$upload['data']]);
195 }
196 }
197 if (count($this->fileCmdMap['upload']) == 0) {
198 $this->writelog(1, 1, 108, 'No file was uploaded!', '');
199 }
200 }
201
202 // Check if there were new folder names expected, but non given
203 if ($this->fileCmdMap['newfolder']) {
204 foreach ($this->fileCmdMap['newfolder'] as $key => $cmdArr) {
205 if (empty($cmdArr['data'])) {
206 unset($this->fileCmdMap['newfolder'][$key]);
207 }
208 }
209 if (count($this->fileCmdMap['newfolder']) === 0) {
210 $this->writeLog(6, 1, 108, 'No name for new folder given!', '');
211 }
212 }
213
214 // Traverse each set of actions
215 foreach ($this->fileCmdMap as $action => $actionData) {
216 // Traverse all action data. More than one file might be affected at the same time.
217 if (is_array($actionData)) {
218 $result[$action] = array();
219 foreach ($actionData as $cmdArr) {
220 // Clear file stats
221 clearstatcache();
222 // Branch out based on command:
223 switch ($action) {
224 case 'delete':
225 $result[$action][] = $this->func_delete($cmdArr);
226 break;
227 case 'copy':
228 $result[$action][] = $this->func_copy($cmdArr);
229 break;
230 case 'move':
231 $result[$action][] = $this->func_move($cmdArr);
232 break;
233 case 'rename':
234 $result[$action][] = $this->func_rename($cmdArr);
235 break;
236 case 'newfolder':
237 $result[$action][] = $this->func_newfolder($cmdArr);
238 break;
239 case 'newfile':
240 $result[$action][] = $this->func_newfile($cmdArr);
241 break;
242 case 'editfile':
243 $result[$action][] = $this->func_edit($cmdArr);
244 break;
245 case 'upload':
246 $result[$action][] = $this->func_upload($cmdArr);
247 break;
248 case 'unzip':
249 $result[$action][] = $this->func_unzip($cmdArr);
250 break;
251 }
252 // Hook for post-processing the action
253 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_extfilefunc.php']['processData'])) {
254 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_extfilefunc.php']['processData'] as $classRef) {
255 $hookObject = GeneralUtility::getUserObj($classRef);
256 if (!$hookObject instanceof ExtendedFileUtilityProcessDataHookInterface) {
257 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtilityProcessDataHookInterface', 1279719168);
258 }
259 $hookObject->processData_postProcessAction($action, $cmdArr, $result[$action], $this);
260 }
261 }
262 }
263 }
264 }
265 }
266 return $result;
267 }
268
269 /**
270 * Adds all log error messages from the operations of this script instance to the FlashMessageQueue
271 *
272 * @return void
273 */
274 public function pushErrorMessagesToFlashMessageQueue() {
275 foreach ($this->getErrorMessages() as $msg) {
276 $flashMessage = GeneralUtility::makeInstance(
277 FlashMessage::class,
278 $msg,
279 '',
280 FlashMessage::ERROR,
281 TRUE
282 );
283 $this->addFlashMessage($flashMessage);
284 }
285 }
286
287 /**
288 * Return all error messages from the file operations of this script instance
289 *
290 * @return array all errorMessages as a numerical array
291 */
292 public function getErrorMessages() {
293 return $this->errorMessages;
294 }
295
296 /**
297 * @param int $action The action number. See the functions in the class for a hint. Eg. edit is '9', upload is '1' ...
298 * @param int $error The severity: 0 = message, 1 = error, 2 = System Error, 3 = security notice (admin)
299 * @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.
300 * @param string $details This is the default, raw error message in english
301 * @param array $data Array with special information that may go into $details by "%s" marks / sprintf() when the log is shown
302 * @return void
303 */
304 public function writeLog($action, $error, $details_nr, $details, $data) {
305 // Type value for tce_file.php
306 $type = 2;
307 if (is_object($this->getBackendUser())) {
308 $this->getBackendUser()->writelog($type, $action, $error, $details_nr, $details, $data);
309 }
310 if ($error > 0) {
311 $this->lastError = vsprintf($details, $data);
312 $this->errorMessages[] = $this->lastError;
313 }
314 }
315
316 /*************************************
317 *
318 * File operation functions
319 *
320 **************************************/
321 /**
322 * Deleting files and folders (action=4)
323 *
324 * @param array $cmds $cmds['data'] is the file/folder to delete
325 * @return bool Returns TRUE upon success
326 */
327 public function func_delete($cmds) {
328 $result = FALSE;
329 if (!$this->isInit) {
330 return $result;
331 }
332 // Example indentifier for $cmds['data'] => "4:mypath/tomyfolder/myfile.jpg"
333 // for backwards compatibility: the combined file identifier was the path+filename
334 try {
335 $fileObject = $this->getFileObject($cmds['data']);
336 } catch (ResourceDoesNotExistException $ex) {
337 $flashMessage = GeneralUtility::makeInstance(
338 FlashMessage::class,
339 sprintf( $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileNotFound'), $cmds['data']),
340 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileNotFound'),
341 FlashMessage::ERROR,
342 TRUE
343 );
344 $this->addFlashMessage($flashMessage);
345
346 return FALSE;
347 }
348 // @todo implement the recycler feature which has been removed from the original implementation
349 // checks to delete the file
350 if ($fileObject instanceof File) {
351 // check if the file still has references
352 // Exclude sys_file_metadata records as these are no use references
353 $refIndexRecords = $this->getDatabaseConnection()->exec_SELECTgetRows(
354 '*',
355 'sys_refindex',
356 'deleted=0 AND ref_table="sys_file" AND ref_uid=' . (int)$fileObject->getUid()
357 . ' AND tablename != "sys_file_metadata"'
358 );
359 $deleteFile = TRUE;
360 if (count($refIndexRecords) > 0) {
361 $shortcutContent = array();
362 $brokenReferences = array();
363
364 foreach ($refIndexRecords as $fileReferenceRow) {
365 if ($fileReferenceRow['tablename'] === 'sys_file_reference') {
366 $row = $this->transformFileReferenceToRecordReference($fileReferenceRow);
367 $shortcutRecord = BackendUtility::getRecord($row['tablename'], $row['recuid']);
368
369 if ($shortcutRecord) {
370 $icon = IconUtility::getSpriteIconForRecord($row['tablename'], $shortcutRecord);
371 $tagParameters = array(
372 'class' => 't3-js-clickmenutrigger',
373 'data-table' => $row['tablename'],
374 'data-uid' => $row['recuid'],
375 'data-listframe' => 1,
376 'data-iteminfo' => '%2Binfo,history,edit'
377 );
378 $icon = '<a href="#" ' . GeneralUtility::implodeAttributes($tagParameters, TRUE) . '>' . $icon . '</a>';
379 $shortcutContent[] = $icon . htmlspecialchars((BackendUtility::getRecordTitle($row['tablename'], $shortcutRecord) . ' [' . BackendUtility::getRecordPath($shortcutRecord['pid'], '', 80) . ']'));
380 } else {
381 $brokenReferences[] = $fileReferenceRow['ref_uid'];
382 }
383 }
384 }
385 if (!empty($brokenReferences)) {
386 // render a message that the file has broken references
387 $flashMessage = GeneralUtility::makeInstance(
388 FlashMessage::class,
389 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileHasBrokenReferences'), count($brokenReferences)),
390 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileHasBrokenReferences'),
391 FlashMessage::INFO,
392 TRUE
393 );
394 $this->addFlashMessage($flashMessage);
395 }
396 if (!empty($shortcutContent)) {
397 // render a message that the file could not be deleted
398 $flashMessage = GeneralUtility::makeInstance(
399 FlashMessage::class,
400 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileNotDeletedHasReferences'), $fileObject->getName()) . '<br />' . implode('<br />', $shortcutContent),
401 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileNotDeletedHasReferences'),
402 FlashMessage::WARNING,
403 TRUE
404 );
405 $this->addFlashMessage($flashMessage);
406 $deleteFile = FALSE;
407 }
408 }
409
410 if ($deleteFile) {
411 try {
412 $result = $fileObject->delete();
413
414 // show the user that the file was deleted
415 $flashMessage = GeneralUtility::makeInstance(
416 FlashMessage::class,
417 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.fileDeleted'), $fileObject->getName()),
418 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.fileDeleted'),
419 FlashMessage::OK,
420 TRUE
421 );
422 $this->addFlashMessage($flashMessage);
423 // Log success
424 $this->writelog(4, 0, 1, 'File "%s" deleted', array($fileObject->getIdentifier()));
425 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
426 $this->writelog(4, 1, 112, 'You are not allowed to access the file', array($fileObject->getIdentifier()));
427 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
428 $this->writelog(4, 1, 111, 'Target was not within your mountpoints! T="%s"', array($fileObject->getIdentifier()));
429 } catch (\RuntimeException $e) {
430 $this->writelog(4, 1, 110, 'Could not delete file "%s". Write-permission problem?', array($fileObject->getIdentifier()));
431 }
432 }
433 } else {
434 try {
435 /** @var \TYPO3\CMS\Core\Resource\Folder $fileObject */
436 $result = $fileObject->delete(TRUE);
437 if ($result) {
438 // notify the user that the folder was deleted
439 /** @var FlashMessage $flashMessage */
440 $flashMessage = GeneralUtility::makeInstance(
441 FlashMessage::class,
442 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderDeleted'), $fileObject->getName()),
443 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.folderDeleted'),
444 FlashMessage::OK,
445 TRUE
446 );
447 $this->addFlashMessage($flashMessage);
448 // Log success
449 $this->writelog(4, 0, 3, 'Directory "%s" deleted', array($fileObject->getIdentifier()));
450 }
451 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
452 $this->writelog(4, 1, 120, 'Could not delete directory! Is directory "%s" empty? (You are not allowed to delete directories recursively).', array($fileObject->getIdentifier()));
453 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException $e) {
454 $this->writelog(4, 1, 123, 'You are not allowed to access the directory', array($fileObject->getIdentifier()));
455 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
456 $this->writelog(4, 1, 121, 'Target was not within your mountpoints! T="%s"', array($fileObject->getIdentifier()));
457 } catch (\TYPO3\CMS\Core\Resource\Exception\FileOperationErrorException $e) {
458 $this->writelog(4, 1, 120, 'Could not delete directory "%s"! Write-permission problem?', array($fileObject->getIdentifier()));
459 }
460 }
461 return $result;
462 }
463
464 /**
465 * Maps results from the fal file reference table on the
466 * structure of the normal reference index table.
467 *
468 * @param array $referenceRecord
469 * @return array
470 */
471 protected function transformFileReferenceToRecordReference(array $referenceRecord) {
472 $fileReference = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
473 '*',
474 'sys_file_reference',
475 'uid=' . (int)$referenceRecord['recuid']
476 );
477 return array(
478 'recuid' => $fileReference['uid_foreign'],
479 'tablename' => $fileReference['tablenames'],
480 'field' => $fileReference['fieldname'],
481 'flexpointer' => '',
482 'softref_key' => '',
483 'sorting' => $fileReference['sorting_foreign']
484 );
485 }
486
487 /**
488 * Gets a File or a Folder object from an identifier [storage]:[fileId]
489 *
490 * @param string $identifier
491 * @return \TYPO3\CMS\Core\Resource\Folder|\TYPO3\CMS\Core\Resource\File
492 * @throws \TYPO3\CMS\Core\Resource\Exception\InvalidFileException
493 */
494 protected function getFileObject($identifier) {
495 $object = $this->fileFactory->retrieveFileOrFolderObject($identifier);
496 if (!is_object($object)) {
497 throw new \TYPO3\CMS\Core\Resource\Exception\InvalidFileException('The item ' . $identifier . ' was not a file or directory!!', 1320122453);
498 }
499 if ($object->getStorage()->getUid() === 0) {
500 throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1375889830);
501 }
502 return $object;
503 }
504
505 /**
506 * Copying files and folders (action=2)
507 *
508 * $cmds['data'] (string): The file/folder to copy
509 * + example "4:mypath/tomyfolder/myfile.jpg")
510 * + for backwards compatibility: the identifier was the path+filename
511 * $cmds['target'] (string): The path where to copy to.
512 * + example "2:targetpath/targetfolder/"
513 * $cmds['altName'] (string): Use an alternative name if the target already exists
514 *
515 * @param array $cmds Command details as described above
516 * @return \TYPO3\CMS\Core\Resource\File
517 */
518 protected function func_copy($cmds) {
519 if (!$this->isInit) {
520 return FALSE;
521 }
522 $sourceFileObject = $this->getFileObject($cmds['data']);
523 /** @var $targetFolderObject \TYPO3\CMS\Core\Resource\Folder */
524 $targetFolderObject = $this->getFileObject($cmds['target']);
525 // Basic check
526 if (!$targetFolderObject instanceof Folder) {
527 $this->writelog(2, 2, 100, 'Destination "%s" was not a directory', array($cmds['target']));
528 return FALSE;
529 }
530 // If this is TRUE, we append _XX to the file name if
531 $appendSuffixOnConflict = (string)$cmds['altName'];
532 $resultObject = NULL;
533 // Copying the file
534 if ($sourceFileObject instanceof File) {
535 try {
536 $conflictMode = $appendSuffixOnConflict !== '' ? 'renameNewFile' : 'cancel';
537 $resultObject = $sourceFileObject->copyTo($targetFolderObject, NULL, $conflictMode);
538 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
539 $this->writelog(2, 1, 114, 'You are not allowed to copy files', '');
540 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
541 $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()));
542 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
543 $this->writelog(2, 1, 111, 'Extension of file name "%s" is not allowed in "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
544 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
545 $this->writelog(2, 1, 112, 'File "%s" already exists in folder "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
546 } catch (\BadMethodCallException $e) {
547 $this->writelog(3, 1, 128, 'The function to copy a file between storages is not yet implemented', array());
548 } catch (\RuntimeException $e) {
549 $this->writelog(2, 2, 109, 'File "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
550 }
551 if ($resultObject) {
552 $this->writelog(2, 0, 1, 'File "%s" copied to "%s"', array($sourceFileObject->getIdentifier(), $resultObject->getIdentifier()));
553 }
554 } else {
555 // Else means this is a Folder
556 $sourceFolderObject = $sourceFileObject;
557 try {
558 $conflictMode = $appendSuffixOnConflict !== '' ? 'renameNewFile' : 'cancel';
559 $resultObject = $sourceFolderObject->copyTo($targetFolderObject, NULL, $conflictMode);
560 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
561 $this->writelog(2, 1, 125, 'You are not allowed to copy directories', '');
562 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
563 $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()));
564 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException $e) {
565 $this->writelog(2, 1, 121, 'You don\'t have full access to the destination directory "%s"!', array($targetFolderObject->getIdentifier()));
566 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidTargetFolderException $e) {
567 $this->writelog(2, 1, 122, 'Destination cannot be inside the target! D="%s", T="%s"', array($targetFolderObject->getIdentifier(), $sourceFolderObject->getIdentifier()));
568 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException $e) {
569 $this->writelog(2, 1, 123, 'Target "%s" already exists!', array($targetFolderObject->getIdentifier()));
570 } catch (\BadMethodCallException $e) {
571 $this->writelog(3, 1, 129, 'The function to copy a folder between storages is not yet implemented', array());
572 } catch (\RuntimeException $e) {
573 $this->writelog(2, 2, 119, 'Directory "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
574 }
575 if ($resultObject) {
576 $this->writelog(2, 0, 2, 'Directory "%s" copied to "%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
577 }
578 }
579 return $resultObject;
580 }
581
582 /**
583 * Moving files and folders (action=3)
584 *
585 * $cmds['data'] (string): The file/folder to move
586 * + example "4:mypath/tomyfolder/myfile.jpg")
587 * + for backwards compatibility: the identifier was the path+filename
588 * $cmds['target'] (string): The path where to move to.
589 * + example "2:targetpath/targetfolder/"
590 * $cmds['altName'] (string): Use an alternative name if the target already exists
591 *
592 * @param array $cmds Command details as described above
593 * @return \TYPO3\CMS\Core\Resource\File
594 */
595 protected function func_move($cmds) {
596 if (!$this->isInit) {
597 return FALSE;
598 }
599 $sourceFileObject = $this->getFileObject($cmds['data']);
600 $targetFolderObject = $this->getFileObject($cmds['target']);
601 // Basic check
602 if (!$targetFolderObject instanceof Folder) {
603 $this->writelog(3, 2, 100, 'Destination "%s" was not a directory', array($cmds['target']));
604 return FALSE;
605 }
606 $alternativeName = (string)$cmds['altName'];
607 $resultObject = NULL;
608 // Moving the file
609 if ($sourceFileObject instanceof File) {
610 try {
611 if ($alternativeName !== '') {
612 // Don't allow overwriting existing files, but find a new name
613 $resultObject = $sourceFileObject->moveTo($targetFolderObject, $alternativeName, 'renameNewFile');
614 } else {
615 // Don't allow overwriting existing files
616 $resultObject = $sourceFileObject->moveTo($targetFolderObject, NULL, 'cancel');
617 }
618 $this->writelog(3, 0, 1, 'File "%s" moved to "%s"', array($sourceFileObject->getIdentifier(), $resultObject->getIdentifier()));
619 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
620 $this->writelog(3, 1, 114, 'You are not allowed to move files', '');
621 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
622 $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()));
623 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
624 $this->writelog(3, 1, 111, 'Extension of file name "%s" is not allowed in "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
625 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
626 $this->writelog(3, 1, 112, 'File "%s" already exists in folder "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
627 } catch (\BadMethodCallException $e) {
628 $this->writelog(3, 1, 126, 'The function to move a file between storages is not yet implemented', array());
629 } catch (\RuntimeException $e) {
630 $this->writelog(3, 2, 109, 'File "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
631 }
632 } else {
633 // Else means this is a Folder
634 $sourceFolderObject = $sourceFileObject;
635 try {
636 if ($alternativeName !== '') {
637 // Don't allow overwriting existing files, but find a new name
638 $resultObject = $sourceFolderObject->moveTo($targetFolderObject, $alternativeName, 'renameNewFile');
639 } else {
640 // Don't allow overwriting existing files
641 $resultObject = $sourceFolderObject->moveTo($targetFolderObject, NULL, 'renameNewFile');
642 }
643 $this->writelog(3, 0, 2, 'Directory "%s" moved to "%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
644 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
645 $this->writelog(3, 1, 125, 'You are not allowed to move directories', '');
646 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
647 $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()));
648 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException $e) {
649 $this->writelog(3, 1, 121, 'You don\'t have full access to the destination directory "%s"!', array($targetFolderObject->getIdentifier()));
650 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidTargetFolderException $e) {
651 $this->writelog(3, 1, 122, 'Destination cannot be inside the target! D="%s", T="%s"', array($targetFolderObject->getIdentifier(), $sourceFolderObject->getIdentifier()));
652 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException $e) {
653 $this->writelog(3, 1, 123, 'Target "%s" already exists!', array($targetFolderObject->getIdentifier()));
654 } catch (\BadMethodCallException $e) {
655 $this->writelog(3, 1, 127, 'The function to move a folder between storages is not yet implemented', array());
656 } catch (\RuntimeException $e) {
657 $this->writelog(3, 2, 119, 'Directory "%s" WAS NOT moved to "%s"! Write-permission problem?', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
658 }
659 }
660 return $resultObject;
661 }
662
663 /**
664 * Renaming files or foldes (action=5)
665 *
666 * $cmds['data'] (string): The file/folder to copy
667 * + example "4:mypath/tomyfolder/myfile.jpg")
668 * + for backwards compatibility: the identifier was the path+filename
669 * $cmds['target'] (string): New name of the file/folder
670 *
671 * @param array $cmds Command details as described above
672 * @return \TYPO3\CMS\Core\Resource\File Returns the new file upon success
673 */
674 public function func_rename($cmds) {
675 if (!$this->isInit) {
676 return FALSE;
677 }
678 $sourceFileObject = $this->getFileObject($cmds['data']);
679 $targetFile = $cmds['target'];
680 $resultObject = NULL;
681 if ($sourceFileObject instanceof File) {
682 try {
683 // Try to rename the File
684 $resultObject = $sourceFileObject->rename($targetFile);
685 $this->writelog(5, 0, 1, 'File renamed from "%s" to "%s"', array($sourceFileObject->getName(), $targetFile));
686 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
687 $this->writelog(5, 1, 102, 'You are not allowed to rename files!', '');
688 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
689 $this->writelog(5, 1, 101, 'Extension of file name "%s" or "%s" was not allowed!', array($sourceFileObject->getName(), $targetFile));
690 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
691 $this->writelog(5, 1, 120, 'Destination "%s" existed already!', array($targetFile));
692 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
693 $this->writelog(5, 1, 121, 'Destination path "%s" was not within your mountpoints!', array($targetFile));
694 } catch (\RuntimeException $e) {
695 $this->writelog(5, 1, 100, 'File "%s" was not renamed! Write-permission problem in "%s"?', array($sourceFileObject->getName(), $targetFile));
696 }
697 } else {
698 // Else means this is a Folder
699 try {
700 // Try to rename the Folder
701 $resultObject = $sourceFileObject->rename($targetFile);
702 $this->writelog(5, 0, 2, 'Directory renamed from "%s" to "%s"', array($sourceFileObject->getName(), $targetFile));
703 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
704 $this->writelog(5, 1, 111, 'You are not allowed to rename directories!', '');
705 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
706 $this->writelog(5, 1, 120, 'Destination "%s" existed already!', array($targetFile));
707 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
708 $this->writelog(5, 1, 121, 'Destination path "%s" was not within your mountpoints!', array($targetFile));
709 } catch (\RuntimeException $e) {
710 $this->writelog(5, 1, 110, 'Directory "%s" was not renamed! Write-permission problem in "%s"?', array($sourceFileObject->getName(), $targetFile));
711 }
712 }
713 return $resultObject;
714 }
715
716 /**
717 * This creates a new folder. (action=6)
718 *
719 * $cmds['data'] (string): The new folder name
720 * $cmds['target'] (string): The path where to copy to.
721 * + example "2:targetpath/targetfolder/"
722 *
723 * @param array $cmds Command details as described above
724 * @return \TYPO3\CMS\Core\Resource\Folder Returns the new foldername upon success
725 */
726 public function func_newfolder($cmds) {
727 if (!$this->isInit) {
728 return FALSE;
729 }
730 $targetFolderObject = $this->getFileObject($cmds['target']);
731 if (!$targetFolderObject instanceof Folder) {
732 $this->writelog(6, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
733 return FALSE;
734 }
735 $resultObject = NULL;
736 try {
737 $folderName = $cmds['data'];
738 $resultObject = $targetFolderObject->createFolder($folderName);
739 $this->writelog(6, 0, 1, 'Directory "%s" created in "%s"', array($folderName, $targetFolderObject->getIdentifier() . '/'));
740 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException $e) {
741 $this->writelog(6, 1, 103, 'You are not allowed to create directories!', '');
742 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
743 $this->writelog(6, 1, 102, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier() . '/'));
744 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException $e) {
745 $this->writelog(6, 1, 101, 'File or directory "%s" existed already!', array($folderName));
746 } catch (\RuntimeException $e) {
747 $this->writelog(6, 1, 100, 'Directory "%s" not created. Write-permission problem in "%s"?', array($folderName, $targetFolderObject->getIdentifier() . '/'));
748 }
749 return $resultObject;
750 }
751
752 /**
753 * This creates a new file. (action=8)
754 * $cmds['data'] (string): The new file name
755 * $cmds['target'] (string): The path where to create it.
756 * + example "2:targetpath/targetfolder/"
757 *
758 * @param array $cmds Command details as described above
759 * @return string Returns the new filename upon success
760 */
761 public function func_newfile($cmds) {
762 if (!$this->isInit) {
763 return FALSE;
764 }
765 $targetFolderObject = $this->getFileObject($cmds['target']);
766 if (!$targetFolderObject instanceof Folder) {
767 $this->writelog(8, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
768 return FALSE;
769 }
770 $resultObject = NULL;
771 try {
772 $fileName = $cmds['data'];
773 $resultObject = $targetFolderObject->createFile($fileName);
774 $this->writelog(8, 0, 1, 'File created: "%s"', array($fileName));
775 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
776 $this->writeLog(8, 1, 106, 'Extension of file "%s" was not allowed!', array($fileName));
777 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException $e) {
778 $this->writelog(8, 1, 103, 'You are not allowed to create files!', '');
779 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
780 $this->writelog(8, 1, 102, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier()));
781 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
782 $this->writelog(8, 1, 101, 'File existed already in "%s"!', array($targetFolderObject->getIdentifier()));
783 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException $e) {
784 $this->writelog(8, 1, 106, 'File name "%s" was not allowed!', $fileName);
785 } catch (\RuntimeException $e) {
786 $this->writelog(8, 1, 100, 'File "%s" was not created! Write-permission problem in "%s"?', array($fileName, $targetFolderObject->getIdentifier()));
787 }
788 return $resultObject;
789 }
790
791 /**
792 * Editing textfiles or folders (action=9)
793 *
794 * @param array $cmds $cmds['data'] is the new content. $cmds['target'] is the target (file or dir)
795 * @return bool Returns TRUE on success
796 */
797 public function func_edit($cmds) {
798 if (!$this->isInit) {
799 return FALSE;
800 }
801 // Example indentifier for $cmds['target'] => "4:mypath/tomyfolder/myfile.jpg"
802 // for backwards compatibility: the combined file identifier was the path+filename
803 $fileIdentifier = $cmds['target'];
804 $fileObject = $this->getFileObject($fileIdentifier);
805 // Example indentifier for $cmds['target'] => "2:targetpath/targetfolder/"
806 $content = $cmds['data'];
807 if (!$fileObject instanceof File) {
808 $this->writelog(9, 2, 123, 'Target "%s" was not a file!', array($fileIdentifier));
809 return FALSE;
810 }
811 $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
812 if (!GeneralUtility::inList($extList, $fileObject->getExtension())) {
813 $this->writelog(9, 1, 102, 'File extension "%s" is not a textfile format! (%s)', array($fileObject->getExtension(), $extList));
814 return FALSE;
815 }
816 try {
817 $fileObject->setContents($content);
818 clearstatcache();
819 $this->writelog(9, 0, 1, 'File saved to "%s", bytes: %s, MD5: %s ', array($fileObject->getIdentifier(), $fileObject->getSize(), md5($content)));
820 return TRUE;
821 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
822 $this->writelog(9, 1, 104, 'You are not allowed to edit files!', '');
823 return FALSE;
824 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileWritePermissionsException $e) {
825 $this->writelog(9, 1, 100, 'File "%s" was not saved! Write-permission problem?', array($fileObject->getIdentifier()));
826 return FALSE;
827 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
828 $this->writelog(9, 1, 100, 'File "%s" was not saved! File extension rejected!', array($fileObject->getIdentifier()));
829 return FALSE;
830 }
831 }
832
833 /**
834 * Upload of files (action=1)
835 * when having multiple uploads (HTML5-style), the array $_FILES looks like this:
836 * Array(
837 * [upload_1] => Array(
838 * [name] => Array(
839 * [0] => GData - Content-Elements and Media-Gallery.pdf
840 * [1] => CMS Expo 2011.txt
841 * )
842 * [type] => Array(
843 * [0] => application/pdf
844 * [1] => text/plain
845 * )
846 * [tmp_name] => Array(
847 * [0] => /Applications/MAMP/tmp/php/phpNrOB43
848 * [1] => /Applications/MAMP/tmp/php/phpD2HQAK
849 * )
850 * [size] => Array(
851 * [0] => 373079
852 * [1] => 1291
853 * )
854 * )
855 * )
856 * in HTML you'd need sth like this: <input type="file" name="upload_1[]" multiple="true" />
857 *
858 * @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)
859 * @return File[] | FALSE Returns an array of new file objects upon success. False otherwise
860 */
861 public function func_upload($cmds) {
862 if (!$this->isInit) {
863 return FALSE;
864 }
865 $uploadPosition = $cmds['data'];
866 $uploadedFileData = $_FILES['upload_' . $uploadPosition];
867 if (empty($uploadedFileData['name']) || is_array($uploadedFileData['name']) && empty($uploadedFileData['name'][0])) {
868 $this->writelog(1, 2, 108, 'No file was uploaded!', '');
869 return FALSE;
870 }
871 // Example indentifier for $cmds['target'] => "2:targetpath/targetfolder/"
872 $targetFolderObject = $this->getFileObject($cmds['target']);
873 // Uploading with non HTML-5-style, thus, make an array out of it, so we can loop over it
874 if (!is_array($uploadedFileData['name'])) {
875 $uploadedFileData = array(
876 'name' => array($uploadedFileData['name']),
877 'type' => array($uploadedFileData['type']),
878 'tmp_name' => array($uploadedFileData['tmp_name']),
879 'size' => array($uploadedFileData['size'])
880 );
881 }
882 $resultObjects = array();
883 $numberOfUploadedFilesForPosition = count($uploadedFileData['name']);
884 // Loop through all uploaded files
885 for ($i = 0; $i < $numberOfUploadedFilesForPosition; $i++) {
886 $fileInfo = array(
887 'name' => $uploadedFileData['name'][$i],
888 'type' => $uploadedFileData['type'][$i],
889 'tmp_name' => $uploadedFileData['tmp_name'][$i],
890 'size' => $uploadedFileData['size'][$i]
891 );
892 try {
893 // @todo can be improved towards conflict mode naming
894 if ($this->dontCheckForUnique) {
895 $conflictMode = 'replace';
896 } else {
897 $conflictMode = 'cancel';
898 }
899 /** @var $fileObject File */
900 $fileObject = $targetFolderObject->addUploadedFile($fileInfo, $conflictMode);
901 $fileObject = ResourceFactory::getInstance()->getFileObjectByStorageAndIdentifier($targetFolderObject->getStorage()->getUid(), $fileObject->getIdentifier());
902 if ($conflictMode === 'replace') {
903 $this->getIndexer($fileObject->getStorage())->updateIndexEntry($fileObject);
904 }
905 $resultObjects[] = $fileObject;
906 $this->internalUploadMap[$uploadPosition] = $fileObject->getCombinedIdentifier();
907 $this->writelog(1, 0, 1, 'Uploading file "%s" to "%s"', array($fileInfo['name'], $targetFolderObject->getIdentifier()));
908 } catch (\TYPO3\CMS\Core\Resource\Exception\UploadException $e) {
909 $this->writelog(1, 2, 106, 'The upload has failed, no uploaded file found!', '');
910 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
911 $this->writelog(1, 1, 105, 'You are not allowed to upload files!', '');
912 } catch (\TYPO3\CMS\Core\Resource\Exception\UploadSizeException $e) {
913 $this->writelog(1, 1, 104, 'The uploaded file "%s" exceeds the size-limit', array($fileInfo['name']));
914 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException $e) {
915 $this->writelog(1, 1, 103, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier()));
916 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
917 $this->writelog(1, 1, 102, 'Extension of file name "%s" is not allowed in "%s"!', array($fileInfo['name'], $targetFolderObject->getIdentifier()));
918 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
919 $this->writelog(1, 1, 101, 'No unique filename available in "%s"!', array($targetFolderObject->getIdentifier()));
920 } catch (\RuntimeException $e) {
921 $this->writelog(1, 1, 100, 'Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolderObject->getIdentifier()));
922 }
923 }
924
925 return $resultObjects;
926 }
927
928 /**
929 * Unzipping file (action=7)
930 * This is permitted only if the user has fullAccess or if the file resides
931 *
932 * @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.
933 * @return bool Returns TRUE on success
934 */
935 public function func_unzip($cmds) {
936 if (!$this->isInit || $this->dont_use_exec_commands) {
937 return FALSE;
938 }
939 $theFile = $cmds['data'];
940 if (!@is_file($theFile)) {
941 $this->writelog(7, 2, 105, 'The file "%s" did not exist!', array($theFile));
942 return FALSE;
943 }
944 $fI = GeneralUtility::split_fileref($theFile);
945 if (!isset($cmds['target'])) {
946 $cmds['target'] = $fI['path'];
947 }
948 // Clean up destination directory
949 // !!! Method has been put in the local driver, can be saftely removed
950 $theDest = $this->is_directory($cmds['target']);
951 if (!$theDest) {
952 $this->writelog(7, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
953 return FALSE;
954 }
955 if (!$this->actionPerms['unzipFile']) {
956 $this->writelog(7, 1, 103, 'You are not allowed to unzip files', '');
957 return FALSE;
958 }
959 if ($fI['fileext'] != 'zip') {
960 $this->writelog(7, 1, 102, 'File extension is not "zip"', '');
961 return FALSE;
962 }
963 if (!$this->checkIfFullAccess($theDest)) {
964 $this->writelog(7, 1, 101, 'You don\'t have full access to the destination directory "%s"!', array($theDest));
965 return FALSE;
966 }
967 // !!! Method has been put in the sotrage driver, can be saftely removed
968 if ($this->checkPathAgainstMounts($theFile) && $this->checkPathAgainstMounts($theDest . '/')) {
969 // No way to do this under windows.
970 $cmd = $this->unzipPath . 'unzip -qq ' . escapeshellarg($theFile) . ' -d ' . escapeshellarg($theDest);
971 CommandUtility::exec($cmd);
972 $this->writelog(7, 0, 1, 'Unzipping file "%s" in "%s"', array($theFile, $theDest));
973 return TRUE;
974 } else {
975 $this->writelog(7, 1, 100, 'File "%s" or destination "%s" was not within your mountpoints!', array($theFile, $theDest));
976 return FALSE;
977 }
978 }
979
980 /**
981 * Add flash message to message queue
982 *
983 * @param FlashMessage $flashMessage
984 * @return void
985 */
986 protected function addFlashMessage(FlashMessage $flashMessage) {
987 /** @var $flashMessageService FlashMessageService */
988 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
989
990 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
991 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
992 $defaultFlashMessageQueue->enqueue($flashMessage);
993 }
994
995 /**
996 * Gets Indexer
997 *
998 * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
999 * @return \TYPO3\CMS\Core\Resource\Index\Indexer
1000 */
1001 protected function getIndexer(ResourceStorage $storage) {
1002 return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Index\Indexer::class, $storage);
1003 }
1004
1005 /**
1006 * Get database connection
1007 *
1008 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
1009 */
1010 protected function getDatabaseConnection() {
1011 return $GLOBALS['TYPO3_DB'];
1012 }
1013
1014 /**
1015 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1016 */
1017 protected function getBackendUser() {
1018 return $GLOBALS['BE_USER'];
1019 }
1020
1021 }