[BUGFIX] Prevent folder deletion with referenced files
[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(array $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 $e) {
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 /** @var Folder $fileObject */
435 if (!$this->folderHasFilesInUse($fileObject)) {
436 try {
437 $result = $fileObject->delete(TRUE);
438 if ($result) {
439 // notify the user that the folder was deleted
440 /** @var FlashMessage $flashMessage */
441 $flashMessage = GeneralUtility::makeInstance(
442 FlashMessage::class,
443 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderDeleted'), $fileObject->getName()),
444 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.folderDeleted'),
445 FlashMessage::OK,
446 TRUE
447 );
448 $this->addFlashMessage($flashMessage);
449 // Log success
450 $this->writelog(4, 0, 3, 'Directory "%s" deleted', array($fileObject->getIdentifier()));
451 }
452 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
453 $this->writelog(4, 1, 120, 'Could not delete directory! Is directory "%s" empty? (You are not allowed to delete directories recursively).', array($fileObject->getIdentifier()));
454 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException $e) {
455 $this->writelog(4, 1, 123, 'You are not allowed to access the directory', array($fileObject->getIdentifier()));
456 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
457 $this->writelog(4, 1, 121, 'Target was not within your mountpoints! T="%s"', array($fileObject->getIdentifier()));
458 } catch (\TYPO3\CMS\Core\Resource\Exception\FileOperationErrorException $e) {
459 $this->writelog(4, 1, 120, 'Could not delete directory "%s"! Write-permission problem?', array($fileObject->getIdentifier()));
460 }
461 }
462 }
463
464 return $result;
465 }
466
467 /**
468 * Checks files in given folder recursively for for existing references.
469 *
470 * Creates a flash message if there are references.
471 *
472 * @param Folder $folder
473 * @return bool TRUE if folder has files in use, FALSE otherwise
474 */
475 public function folderHasFilesInUse(Folder $folder) {
476 $files = $folder->getFiles(0, 0, Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, TRUE);
477 if (empty($files)) {
478 return FALSE;
479 }
480
481 /** @var int[] $fileUids */
482 $fileUids = array();
483 foreach ($files as $file) {
484 $fileUids[] = $file->getUid();
485 }
486 $numberOfReferences = $this->getDatabaseConnection()->exec_SELECTcountRows(
487 '*',
488 'sys_refindex',
489 'deleted=0 AND ref_table="sys_file" AND ref_uid IN (' . implode(',', $fileUids) . ') AND tablename<>"sys_file_metadata"'
490 );
491
492 $hasReferences = $numberOfReferences > 0;
493 if ($hasReferences) {
494 /** @var FlashMessage $flashMessage */
495 $flashMessage = GeneralUtility::makeInstance(
496 FlashMessage::class,
497 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.description.folderNotDeletedHasFilesWithReferences'),
498 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:message.header.folderNotDeletedHasFilesWithReferences'),
499 FlashMessage::WARNING,
500 TRUE
501 );
502 $this->addFlashMessage($flashMessage);
503 }
504
505 return $hasReferences;
506 }
507
508 /**
509 * Maps results from the fal file reference table on the
510 * structure of the normal reference index table.
511 *
512 * @param array $referenceRecord
513 * @return array
514 */
515 protected function transformFileReferenceToRecordReference(array $referenceRecord) {
516 $fileReference = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
517 '*',
518 'sys_file_reference',
519 'uid=' . (int)$referenceRecord['recuid']
520 );
521 return array(
522 'recuid' => $fileReference['uid_foreign'],
523 'tablename' => $fileReference['tablenames'],
524 'field' => $fileReference['fieldname'],
525 'flexpointer' => '',
526 'softref_key' => '',
527 'sorting' => $fileReference['sorting_foreign']
528 );
529 }
530
531 /**
532 * Gets a File or a Folder object from an identifier [storage]:[fileId]
533 *
534 * @param string $identifier
535 * @return \TYPO3\CMS\Core\Resource\Folder|\TYPO3\CMS\Core\Resource\File
536 * @throws \TYPO3\CMS\Core\Resource\Exception\InvalidFileException
537 */
538 protected function getFileObject($identifier) {
539 $object = $this->fileFactory->retrieveFileOrFolderObject($identifier);
540 if (!is_object($object)) {
541 throw new \TYPO3\CMS\Core\Resource\Exception\InvalidFileException('The item ' . $identifier . ' was not a file or directory!!', 1320122453);
542 }
543 if ($object->getStorage()->getUid() === 0) {
544 throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1375889830);
545 }
546 return $object;
547 }
548
549 /**
550 * Copying files and folders (action=2)
551 *
552 * $cmds['data'] (string): The file/folder to copy
553 * + example "4:mypath/tomyfolder/myfile.jpg")
554 * + for backwards compatibility: the identifier was the path+filename
555 * $cmds['target'] (string): The path where to copy to.
556 * + example "2:targetpath/targetfolder/"
557 * $cmds['altName'] (string): Use an alternative name if the target already exists
558 *
559 * @param array $cmds Command details as described above
560 * @return \TYPO3\CMS\Core\Resource\File
561 */
562 protected function func_copy($cmds) {
563 if (!$this->isInit) {
564 return FALSE;
565 }
566 $sourceFileObject = $this->getFileObject($cmds['data']);
567 /** @var $targetFolderObject \TYPO3\CMS\Core\Resource\Folder */
568 $targetFolderObject = $this->getFileObject($cmds['target']);
569 // Basic check
570 if (!$targetFolderObject instanceof Folder) {
571 $this->writelog(2, 2, 100, 'Destination "%s" was not a directory', array($cmds['target']));
572 return FALSE;
573 }
574 // If this is TRUE, we append _XX to the file name if
575 $appendSuffixOnConflict = (string)$cmds['altName'];
576 $resultObject = NULL;
577 // Copying the file
578 if ($sourceFileObject instanceof File) {
579 try {
580 $conflictMode = $appendSuffixOnConflict !== '' ? 'renameNewFile' : 'cancel';
581 $resultObject = $sourceFileObject->copyTo($targetFolderObject, NULL, $conflictMode);
582 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
583 $this->writelog(2, 1, 114, 'You are not allowed to copy files', '');
584 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
585 $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()));
586 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
587 $this->writelog(2, 1, 111, 'Extension of file name "%s" is not allowed in "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
588 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
589 $this->writelog(2, 1, 112, 'File "%s" already exists in folder "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
590 } catch (\BadMethodCallException $e) {
591 $this->writelog(3, 1, 128, 'The function to copy a file between storages is not yet implemented', array());
592 } catch (\RuntimeException $e) {
593 $this->writelog(2, 2, 109, 'File "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
594 }
595 if ($resultObject) {
596 $this->writelog(2, 0, 1, 'File "%s" copied to "%s"', array($sourceFileObject->getIdentifier(), $resultObject->getIdentifier()));
597 }
598 } else {
599 // Else means this is a Folder
600 $sourceFolderObject = $sourceFileObject;
601 try {
602 $conflictMode = $appendSuffixOnConflict !== '' ? 'renameNewFile' : 'cancel';
603 $resultObject = $sourceFolderObject->copyTo($targetFolderObject, NULL, $conflictMode);
604 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
605 $this->writelog(2, 1, 125, 'You are not allowed to copy directories', '');
606 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
607 $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()));
608 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException $e) {
609 $this->writelog(2, 1, 121, 'You don\'t have full access to the destination directory "%s"!', array($targetFolderObject->getIdentifier()));
610 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidTargetFolderException $e) {
611 $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()));
612 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException $e) {
613 $this->writelog(2, 1, 123, 'Target "%s" already exists!', array($targetFolderObject->getIdentifier()));
614 } catch (\BadMethodCallException $e) {
615 $this->writelog(3, 1, 129, 'The function to copy a folder between storages is not yet implemented', array());
616 } catch (\RuntimeException $e) {
617 $this->writelog(2, 2, 119, 'Directory "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
618 }
619 if ($resultObject) {
620 $this->writelog(2, 0, 2, 'Directory "%s" copied to "%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
621 }
622 }
623 return $resultObject;
624 }
625
626 /**
627 * Moving files and folders (action=3)
628 *
629 * $cmds['data'] (string): The file/folder to move
630 * + example "4:mypath/tomyfolder/myfile.jpg")
631 * + for backwards compatibility: the identifier was the path+filename
632 * $cmds['target'] (string): The path where to move to.
633 * + example "2:targetpath/targetfolder/"
634 * $cmds['altName'] (string): Use an alternative name if the target already exists
635 *
636 * @param array $cmds Command details as described above
637 * @return \TYPO3\CMS\Core\Resource\File
638 */
639 protected function func_move($cmds) {
640 if (!$this->isInit) {
641 return FALSE;
642 }
643 $sourceFileObject = $this->getFileObject($cmds['data']);
644 $targetFolderObject = $this->getFileObject($cmds['target']);
645 // Basic check
646 if (!$targetFolderObject instanceof Folder) {
647 $this->writelog(3, 2, 100, 'Destination "%s" was not a directory', array($cmds['target']));
648 return FALSE;
649 }
650 $alternativeName = (string)$cmds['altName'];
651 $resultObject = NULL;
652 // Moving the file
653 if ($sourceFileObject instanceof File) {
654 try {
655 if ($alternativeName !== '') {
656 // Don't allow overwriting existing files, but find a new name
657 $resultObject = $sourceFileObject->moveTo($targetFolderObject, $alternativeName, 'renameNewFile');
658 } else {
659 // Don't allow overwriting existing files
660 $resultObject = $sourceFileObject->moveTo($targetFolderObject, NULL, 'cancel');
661 }
662 $this->writelog(3, 0, 1, 'File "%s" moved to "%s"', array($sourceFileObject->getIdentifier(), $resultObject->getIdentifier()));
663 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
664 $this->writelog(3, 1, 114, 'You are not allowed to move files', '');
665 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
666 $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()));
667 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
668 $this->writelog(3, 1, 111, 'Extension of file name "%s" is not allowed in "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
669 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
670 $this->writelog(3, 1, 112, 'File "%s" already exists in folder "%s"!', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
671 } catch (\BadMethodCallException $e) {
672 $this->writelog(3, 1, 126, 'The function to move a file between storages is not yet implemented', array());
673 } catch (\RuntimeException $e) {
674 $this->writelog(3, 2, 109, 'File "%s" WAS NOT copied to "%s"! Write-permission problem?', array($sourceFileObject->getIdentifier(), $targetFolderObject->getIdentifier()));
675 }
676 } else {
677 // Else means this is a Folder
678 $sourceFolderObject = $sourceFileObject;
679 try {
680 if ($alternativeName !== '') {
681 // Don't allow overwriting existing files, but find a new name
682 $resultObject = $sourceFolderObject->moveTo($targetFolderObject, $alternativeName, 'renameNewFile');
683 } else {
684 // Don't allow overwriting existing files
685 $resultObject = $sourceFolderObject->moveTo($targetFolderObject, NULL, 'renameNewFile');
686 }
687 $this->writelog(3, 0, 2, 'Directory "%s" moved to "%s"', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
688 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
689 $this->writelog(3, 1, 125, 'You are not allowed to move directories', '');
690 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
691 $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()));
692 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException $e) {
693 $this->writelog(3, 1, 121, 'You don\'t have full access to the destination directory "%s"!', array($targetFolderObject->getIdentifier()));
694 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidTargetFolderException $e) {
695 $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()));
696 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException $e) {
697 $this->writelog(3, 1, 123, 'Target "%s" already exists!', array($targetFolderObject->getIdentifier()));
698 } catch (\BadMethodCallException $e) {
699 $this->writelog(3, 1, 127, 'The function to move a folder between storages is not yet implemented', array());
700 } catch (\RuntimeException $e) {
701 $this->writelog(3, 2, 119, 'Directory "%s" WAS NOT moved to "%s"! Write-permission problem?', array($sourceFolderObject->getIdentifier(), $targetFolderObject->getIdentifier()));
702 }
703 }
704 return $resultObject;
705 }
706
707 /**
708 * Renaming files or foldes (action=5)
709 *
710 * $cmds['data'] (string): The file/folder to copy
711 * + example "4:mypath/tomyfolder/myfile.jpg")
712 * + for backwards compatibility: the identifier was the path+filename
713 * $cmds['target'] (string): New name of the file/folder
714 *
715 * @param array $cmds Command details as described above
716 * @return \TYPO3\CMS\Core\Resource\File Returns the new file upon success
717 */
718 public function func_rename($cmds) {
719 if (!$this->isInit) {
720 return FALSE;
721 }
722 $sourceFileObject = $this->getFileObject($cmds['data']);
723 $targetFile = $cmds['target'];
724 $resultObject = NULL;
725 if ($sourceFileObject instanceof File) {
726 try {
727 // Try to rename the File
728 $resultObject = $sourceFileObject->rename($targetFile);
729 $this->writelog(5, 0, 1, 'File renamed from "%s" to "%s"', array($sourceFileObject->getName(), $targetFile));
730 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
731 $this->writelog(5, 1, 102, 'You are not allowed to rename files!', '');
732 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
733 $this->writelog(5, 1, 101, 'Extension of file name "%s" or "%s" was not allowed!', array($sourceFileObject->getName(), $targetFile));
734 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
735 $this->writelog(5, 1, 120, 'Destination "%s" existed already!', array($targetFile));
736 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
737 $this->writelog(5, 1, 121, 'Destination path "%s" was not within your mountpoints!', array($targetFile));
738 } catch (\RuntimeException $e) {
739 $this->writelog(5, 1, 100, 'File "%s" was not renamed! Write-permission problem in "%s"?', array($sourceFileObject->getName(), $targetFile));
740 }
741 } else {
742 // Else means this is a Folder
743 try {
744 // Try to rename the Folder
745 $resultObject = $sourceFileObject->rename($targetFile);
746 $this->writelog(5, 0, 2, 'Directory renamed from "%s" to "%s"', array($sourceFileObject->getName(), $targetFile));
747 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
748 $this->writelog(5, 1, 111, 'You are not allowed to rename directories!', '');
749 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
750 $this->writelog(5, 1, 120, 'Destination "%s" existed already!', array($targetFile));
751 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
752 $this->writelog(5, 1, 121, 'Destination path "%s" was not within your mountpoints!', array($targetFile));
753 } catch (\RuntimeException $e) {
754 $this->writelog(5, 1, 110, 'Directory "%s" was not renamed! Write-permission problem in "%s"?', array($sourceFileObject->getName(), $targetFile));
755 }
756 }
757 return $resultObject;
758 }
759
760 /**
761 * This creates a new folder. (action=6)
762 *
763 * $cmds['data'] (string): The new folder name
764 * $cmds['target'] (string): The path where to copy to.
765 * + example "2:targetpath/targetfolder/"
766 *
767 * @param array $cmds Command details as described above
768 * @return \TYPO3\CMS\Core\Resource\Folder Returns the new foldername upon success
769 */
770 public function func_newfolder($cmds) {
771 if (!$this->isInit) {
772 return FALSE;
773 }
774 $targetFolderObject = $this->getFileObject($cmds['target']);
775 if (!$targetFolderObject instanceof Folder) {
776 $this->writelog(6, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
777 return FALSE;
778 }
779 $resultObject = NULL;
780 try {
781 $folderName = $cmds['data'];
782 $resultObject = $targetFolderObject->createFolder($folderName);
783 $this->writelog(6, 0, 1, 'Directory "%s" created in "%s"', array($folderName, $targetFolderObject->getIdentifier() . '/'));
784 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException $e) {
785 $this->writelog(6, 1, 103, 'You are not allowed to create directories!', '');
786 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
787 $this->writelog(6, 1, 102, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier() . '/'));
788 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException $e) {
789 $this->writelog(6, 1, 101, 'File or directory "%s" existed already!', array($folderName));
790 } catch (\RuntimeException $e) {
791 $this->writelog(6, 1, 100, 'Directory "%s" not created. Write-permission problem in "%s"?', array($folderName, $targetFolderObject->getIdentifier() . '/'));
792 }
793 return $resultObject;
794 }
795
796 /**
797 * This creates a new file. (action=8)
798 * $cmds['data'] (string): The new file name
799 * $cmds['target'] (string): The path where to create it.
800 * + example "2:targetpath/targetfolder/"
801 *
802 * @param array $cmds Command details as described above
803 * @return string Returns the new filename upon success
804 */
805 public function func_newfile($cmds) {
806 if (!$this->isInit) {
807 return FALSE;
808 }
809 $targetFolderObject = $this->getFileObject($cmds['target']);
810 if (!$targetFolderObject instanceof Folder) {
811 $this->writelog(8, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
812 return FALSE;
813 }
814 $resultObject = NULL;
815 try {
816 $fileName = $cmds['data'];
817 $resultObject = $targetFolderObject->createFile($fileName);
818 $this->writelog(8, 0, 1, 'File created: "%s"', array($fileName));
819 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
820 $this->writeLog(8, 1, 106, 'Extension of file "%s" was not allowed!', array($fileName));
821 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException $e) {
822 $this->writelog(8, 1, 103, 'You are not allowed to create files!', '');
823 } catch (\TYPO3\CMS\Core\Resource\Exception\NotInMountPointException $e) {
824 $this->writelog(8, 1, 102, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier()));
825 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
826 $this->writelog(8, 1, 101, 'File existed already in "%s"!', array($targetFolderObject->getIdentifier()));
827 } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException $e) {
828 $this->writelog(8, 1, 106, 'File name "%s" was not allowed!', $fileName);
829 } catch (\RuntimeException $e) {
830 $this->writelog(8, 1, 100, 'File "%s" was not created! Write-permission problem in "%s"?', array($fileName, $targetFolderObject->getIdentifier()));
831 }
832 return $resultObject;
833 }
834
835 /**
836 * Editing textfiles or folders (action=9)
837 *
838 * @param array $cmds $cmds['data'] is the new content. $cmds['target'] is the target (file or dir)
839 * @return bool Returns TRUE on success
840 */
841 public function func_edit($cmds) {
842 if (!$this->isInit) {
843 return FALSE;
844 }
845 // Example indentifier for $cmds['target'] => "4:mypath/tomyfolder/myfile.jpg"
846 // for backwards compatibility: the combined file identifier was the path+filename
847 $fileIdentifier = $cmds['target'];
848 $fileObject = $this->getFileObject($fileIdentifier);
849 // Example indentifier for $cmds['target'] => "2:targetpath/targetfolder/"
850 $content = $cmds['data'];
851 if (!$fileObject instanceof File) {
852 $this->writelog(9, 2, 123, 'Target "%s" was not a file!', array($fileIdentifier));
853 return FALSE;
854 }
855 $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
856 if (!GeneralUtility::inList($extList, $fileObject->getExtension())) {
857 $this->writelog(9, 1, 102, 'File extension "%s" is not a textfile format! (%s)', array($fileObject->getExtension(), $extList));
858 return FALSE;
859 }
860 try {
861 $fileObject->setContents($content);
862 clearstatcache();
863 $this->writelog(9, 0, 1, 'File saved to "%s", bytes: %s, MD5: %s ', array($fileObject->getIdentifier(), $fileObject->getSize(), md5($content)));
864 return TRUE;
865 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
866 $this->writelog(9, 1, 104, 'You are not allowed to edit files!', '');
867 return FALSE;
868 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileWritePermissionsException $e) {
869 $this->writelog(9, 1, 100, 'File "%s" was not saved! Write-permission problem?', array($fileObject->getIdentifier()));
870 return FALSE;
871 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
872 $this->writelog(9, 1, 100, 'File "%s" was not saved! File extension rejected!', array($fileObject->getIdentifier()));
873 return FALSE;
874 }
875 }
876
877 /**
878 * Upload of files (action=1)
879 * when having multiple uploads (HTML5-style), the array $_FILES looks like this:
880 * Array(
881 * [upload_1] => Array(
882 * [name] => Array(
883 * [0] => GData - Content-Elements and Media-Gallery.pdf
884 * [1] => CMS Expo 2011.txt
885 * )
886 * [type] => Array(
887 * [0] => application/pdf
888 * [1] => text/plain
889 * )
890 * [tmp_name] => Array(
891 * [0] => /Applications/MAMP/tmp/php/phpNrOB43
892 * [1] => /Applications/MAMP/tmp/php/phpD2HQAK
893 * )
894 * [size] => Array(
895 * [0] => 373079
896 * [1] => 1291
897 * )
898 * )
899 * )
900 * in HTML you'd need sth like this: <input type="file" name="upload_1[]" multiple="true" />
901 *
902 * @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)
903 * @return File[] | FALSE Returns an array of new file objects upon success. False otherwise
904 */
905 public function func_upload($cmds) {
906 if (!$this->isInit) {
907 return FALSE;
908 }
909 $uploadPosition = $cmds['data'];
910 $uploadedFileData = $_FILES['upload_' . $uploadPosition];
911 if (empty($uploadedFileData['name']) || is_array($uploadedFileData['name']) && empty($uploadedFileData['name'][0])) {
912 $this->writelog(1, 2, 108, 'No file was uploaded!', '');
913 return FALSE;
914 }
915 // Example indentifier for $cmds['target'] => "2:targetpath/targetfolder/"
916 $targetFolderObject = $this->getFileObject($cmds['target']);
917 // Uploading with non HTML-5-style, thus, make an array out of it, so we can loop over it
918 if (!is_array($uploadedFileData['name'])) {
919 $uploadedFileData = array(
920 'name' => array($uploadedFileData['name']),
921 'type' => array($uploadedFileData['type']),
922 'tmp_name' => array($uploadedFileData['tmp_name']),
923 'size' => array($uploadedFileData['size'])
924 );
925 }
926 $resultObjects = array();
927 $numberOfUploadedFilesForPosition = count($uploadedFileData['name']);
928 // Loop through all uploaded files
929 for ($i = 0; $i < $numberOfUploadedFilesForPosition; $i++) {
930 $fileInfo = array(
931 'name' => $uploadedFileData['name'][$i],
932 'type' => $uploadedFileData['type'][$i],
933 'tmp_name' => $uploadedFileData['tmp_name'][$i],
934 'size' => $uploadedFileData['size'][$i]
935 );
936 try {
937 // @todo can be improved towards conflict mode naming
938 if ($this->dontCheckForUnique) {
939 $conflictMode = 'replace';
940 } else {
941 $conflictMode = 'cancel';
942 }
943 /** @var $fileObject File */
944 $fileObject = $targetFolderObject->addUploadedFile($fileInfo, $conflictMode);
945 $fileObject = ResourceFactory::getInstance()->getFileObjectByStorageAndIdentifier($targetFolderObject->getStorage()->getUid(), $fileObject->getIdentifier());
946 if ($conflictMode === 'replace') {
947 $this->getIndexer($fileObject->getStorage())->updateIndexEntry($fileObject);
948 }
949 $resultObjects[] = $fileObject;
950 $this->internalUploadMap[$uploadPosition] = $fileObject->getCombinedIdentifier();
951 $this->writelog(1, 0, 1, 'Uploading file "%s" to "%s"', array($fileInfo['name'], $targetFolderObject->getIdentifier()));
952 } catch (\TYPO3\CMS\Core\Resource\Exception\UploadException $e) {
953 $this->writelog(1, 2, 106, 'The upload has failed, no uploaded file found!', '');
954 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException $e) {
955 $this->writelog(1, 1, 105, 'You are not allowed to upload files!', '');
956 } catch (\TYPO3\CMS\Core\Resource\Exception\UploadSizeException $e) {
957 $this->writelog(1, 1, 104, 'The uploaded file "%s" exceeds the size-limit', array($fileInfo['name']));
958 } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException $e) {
959 $this->writelog(1, 1, 103, 'Destination path "%s" was not within your mountpoints!', array($targetFolderObject->getIdentifier()));
960 } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
961 $this->writelog(1, 1, 102, 'Extension of file name "%s" is not allowed in "%s"!', array($fileInfo['name'], $targetFolderObject->getIdentifier()));
962 } catch (\TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException $e) {
963 $this->writelog(1, 1, 101, 'No unique filename available in "%s"!', array($targetFolderObject->getIdentifier()));
964 } catch (\RuntimeException $e) {
965 $this->writelog(1, 1, 100, 'Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolderObject->getIdentifier()));
966 }
967 }
968
969 return $resultObjects;
970 }
971
972 /**
973 * Unzipping file (action=7)
974 * This is permitted only if the user has fullAccess or if the file resides
975 *
976 * @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.
977 * @return bool Returns TRUE on success
978 */
979 public function func_unzip($cmds) {
980 if (!$this->isInit || $this->dont_use_exec_commands) {
981 return FALSE;
982 }
983 $theFile = $cmds['data'];
984 if (!@is_file($theFile)) {
985 $this->writelog(7, 2, 105, 'The file "%s" did not exist!', array($theFile));
986 return FALSE;
987 }
988 $fI = GeneralUtility::split_fileref($theFile);
989 if (!isset($cmds['target'])) {
990 $cmds['target'] = $fI['path'];
991 }
992 // Clean up destination directory
993 // !!! Method has been put in the local driver, can be saftely removed
994 $theDest = $this->is_directory($cmds['target']);
995 if (!$theDest) {
996 $this->writelog(7, 2, 104, 'Destination "%s" was not a directory', array($cmds['target']));
997 return FALSE;
998 }
999 if (!$this->actionPerms['unzipFile']) {
1000 $this->writelog(7, 1, 103, 'You are not allowed to unzip files', '');
1001 return FALSE;
1002 }
1003 if ($fI['fileext'] != 'zip') {
1004 $this->writelog(7, 1, 102, 'File extension is not "zip"', '');
1005 return FALSE;
1006 }
1007 if (!$this->checkIfFullAccess($theDest)) {
1008 $this->writelog(7, 1, 101, 'You don\'t have full access to the destination directory "%s"!', array($theDest));
1009 return FALSE;
1010 }
1011 // !!! Method has been put in the sotrage driver, can be saftely removed
1012 if ($this->checkPathAgainstMounts($theFile) && $this->checkPathAgainstMounts($theDest . '/')) {
1013 // No way to do this under windows.
1014 $cmd = $this->unzipPath . 'unzip -qq ' . escapeshellarg($theFile) . ' -d ' . escapeshellarg($theDest);
1015 CommandUtility::exec($cmd);
1016 $this->writelog(7, 0, 1, 'Unzipping file "%s" in "%s"', array($theFile, $theDest));
1017 return TRUE;
1018 } else {
1019 $this->writelog(7, 1, 100, 'File "%s" or destination "%s" was not within your mountpoints!', array($theFile, $theDest));
1020 return FALSE;
1021 }
1022 }
1023
1024 /**
1025 * Add flash message to message queue
1026 *
1027 * @param FlashMessage $flashMessage
1028 * @return void
1029 */
1030 protected function addFlashMessage(FlashMessage $flashMessage) {
1031 /** @var $flashMessageService FlashMessageService */
1032 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
1033
1034 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
1035 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
1036 $defaultFlashMessageQueue->enqueue($flashMessage);
1037 }
1038
1039 /**
1040 * Gets Indexer
1041 *
1042 * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
1043 * @return \TYPO3\CMS\Core\Resource\Index\Indexer
1044 */
1045 protected function getIndexer(ResourceStorage $storage) {
1046 return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Index\Indexer::class, $storage);
1047 }
1048
1049 /**
1050 * Get database connection
1051 *
1052 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
1053 */
1054 protected function getDatabaseConnection() {
1055 return $GLOBALS['TYPO3_DB'];
1056 }
1057
1058 /**
1059 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1060 */
1061 protected function getBackendUser() {
1062 return $GLOBALS['BE_USER'];
1063 }
1064
1065 }