[BUGFIX] Ajax handler TYPO3_tcefile::process is broken 80/27080/7
authorFrans Saris <franssaris@gmail.com>
Mon, 27 Jan 2014 20:47:41 +0000 (21:47 +0100)
committerSteffen Ritter <info@rs-websystems.de>
Fri, 31 Jan 2014 13:30:37 +0000 (14:30 +0100)
Several changes in core broke the ajax upload handler response.
There is no error response and it tries to json_encode complete
File objects.

This changes reverts some of the "cleanup" changes fixes the
response and makes sure only the error message from current
request are used.

Resolves: #55371
Releases: 6.2, 6.1
Change-Id: Ia09f5ffd5e002b1ba50d4fafa747340462d15148
Reviewed-on: https://review.typo3.org/27080
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/backend/Classes/Controller/File/FileController.php
typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php
typo3/sysext/filelist/Classes/Controller/FileListController.php

index a861155..fe8704e 100644 (file)
@@ -58,8 +58,12 @@ class FileController {
        // the page where the user should be redirected after everything is done
        protected $redirect;
 
-       // Internal, dynamic:
-       // File processor object
+       /**
+        * Internal, dynamic:
+        * File processor object
+        *
+        * @var \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility
+        */
        protected $fileProcessor;
 
        // the result array from the file processor
@@ -138,8 +142,8 @@ class FileController {
         * @return void
         */
        public function finish() {
-               // Prints errors, if there are any
-               $this->fileProcessor->printLogErrorMessages($this->redirect);
+               // Push errors to flash message queue, if there are any
+               $this->fileProcessor->pushErrorMessagesToFlashMessageQueue();
                \TYPO3\CMS\Backend\Utility\BackendUtility::setUpdateSignal('updateFolderTree');
                if ($this->redirect) {
                        \TYPO3\CMS\Core\Utility\HttpUtility::redirect($this->redirect);
@@ -163,7 +167,16 @@ class FileController {
                if (count($errors)) {
                        $ajaxObj->setError(implode(',', $errors));
                } else {
-                       $ajaxObj->addContent('result', $this->fileData);
+                       $fileData = array();
+                       foreach ($this->fileData as $action => $result) {
+                               foreach ($result as $files) {
+                                       /** @var $file \TYPO3\CMS\Core\Resource\File */
+                                       foreach ($files as $file) {
+                                               $fileData[$action][] = $file->toArray();
+                                       }
+                               }
+                       }
+                       $ajaxObj->addContent('result', $fileData);
                        if ($this->redirect) {
                                $ajaxObj->addContent('redirect', $this->redirect);
                        }
index 9ed5871..aa56281 100644 (file)
@@ -129,6 +129,13 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
        public $lastError = '';
 
        /**
+        * All error messages from the file operations of this script instance
+        *
+        * @var array
+        */
+       protected $errorMessages = array();
+
+       /**
         * @var array
         */
        protected $fileCmdMap;
@@ -271,30 +278,20 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
         *
         * @param string $redirect Redirect URL (for creating link in message)
         * @return void
-        * @todo Define visibility
-        * @deprecated since TYPO3 6.1, will be removed two versions later, use ->getErrorMessages directly instead
+        * @deprecated since TYPO3 6.1, will be removed two versions later, use ->pushErrorMessagesToFlashMessageQueue directly instead
         */
        public function printLogErrorMessages($redirect = '') {
                GeneralUtility::logDeprecatedFunction();
-               $this->getErrorMessages();
+               $this->pushErrorMessagesToFlashMessageQueue();
        }
 
        /**
-        * Adds log error messages from the previous file operations of this script instance
-        * to the FlashMessageQueue
+        * Adds all log error messages from the operations of this script instance to the FlashMessageQueue
         *
         * @return void
-        * @todo Define visibility
         */
-       public function getErrorMessages() {
-               $res = $this->getDatabaseConnection()->exec_SELECTquery(
-                       '*',
-                       'sys_log',
-                       'type = 2 AND userid = ' . intval($this->getBackendUser()->user['uid']) . ' AND tstamp=' . intval($GLOBALS['EXEC_TIME']) . ' AND error<>0'
-               );
-               while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
-                       $logData = unserialize($row['log_data']);
-                       $msg = $row['error'] . ': ' . sprintf($row['details'], $logData[0], $logData[1], $logData[2], $logData[3], $logData[4]);
+       public function pushErrorMessagesToFlashMessageQueue() {
+               foreach ($this->getErrorMessages() as $msg) {
                        $flashMessage = GeneralUtility::makeInstance(
                                'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
                                $msg,
@@ -304,7 +301,15 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                        );
                        $this->addFlashMessage($flashMessage);
                }
-               $this->getDatabaseConnection()->sql_free_result($res);
+       }
+
+       /**
+        * Return all error messages from the file operations of this script instance
+        *
+        * @return array all errorMessages as a numerical array
+        */
+       public function getErrorMessages() {
+               return $this->errorMessages;
        }
 
        /**
@@ -354,7 +359,10 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                if (is_object($this->getBackendUser())) {
                        $this->getBackendUser()->writelog($type, $action, $error, $details_nr, $details, $data);
                }
-               $this->lastError = vsprintf($details, $data);
+               if ($error > 0) {
+                       $this->lastError = vsprintf($details, $data);
+                       $this->errorMessages[] = $this->lastError;
+               }
        }
 
        /*************************************
@@ -871,7 +879,7 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
         * in HTML you'd need sth like this: <input type="file" name="upload_1[]" multiple="true" />
         *
         * @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)
-        * @return string Returns the new filename upon success
+        * @return File[] | FALSE Returns an array of new file objects upon success. False otherwise
         * @todo Define visibility
         */
        public function func_upload($cmds) {
index 96bd6b3..3f6f631 100644 (file)
@@ -300,7 +300,7 @@ class FileListController {
                                        $fileProcessor->dontCheckForUnique = $this->overwriteExistingFiles ? 1 : 0;
                                        $fileProcessor->start($FILE);
                                        $fileProcessor->processData();
-                                       $fileProcessor->printLogErrorMessages();
+                                       $fileProcessor->pushErrorMessagesToFlashMessageQueue();
                                }
                        }
                        if (!isset($this->MOD_SETTINGS['sort'])) {