[CLEANUP] Early returns in various DataHandler methods 80/40280/2
authorAndreas Wolf <andreas.wolf@typo3.org>
Sun, 7 Jun 2015 08:55:34 +0000 (10:55 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 16 Jun 2015 11:34:41 +0000 (13:34 +0200)
Related: #67336
Releases: master
Change-Id: Ied575832fdb942f5cb0e82116148e9b336e01715
Reviewed-on: http://review.typo3.org/40280
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Daniel Maier <dani-maier@gmx.de>
Tested-by: Daniel Maier <dani-maier@gmx.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/DataHandling/DataHandler.php

index 90e2989..93990b2 100644 (file)
@@ -747,17 +747,23 @@ class DataHandler {
         * @return void
         */
        public function setMirror($mirror) {
-               if (is_array($mirror)) {
-                       foreach ($mirror as $table => $uid_array) {
-                               if (isset($this->datamap[$table])) {
-                                       foreach ($uid_array as $id => $uidList) {
-                                               if (isset($this->datamap[$table][$id])) {
-                                                       $theIdsInArray = GeneralUtility::trimExplode(',', $uidList, TRUE);
-                                                       foreach ($theIdsInArray as $copyToUid) {
-                                                               $this->datamap[$table][$copyToUid] = $this->datamap[$table][$id];
-                                                       }
-                                               }
-                                       }
+               if (!is_array($mirror)) {
+                       return;
+               }
+
+               foreach ($mirror as $table => $uid_array) {
+                       if (!isset($this->datamap[$table])) {
+                               continue;
+                       }
+
+                       foreach ($uid_array as $id => $uidList) {
+                               if (!isset($this->datamap[$table][$id])) {
+                                       continue;
+                               }
+
+                               $theIdsInArray = GeneralUtility::trimExplode(',', $uidList, TRUE);
+                               foreach ($theIdsInArray as $copyToUid) {
+                                       $this->datamap[$table][$copyToUid] = $this->datamap[$table][$id];
                                }
                        }
                }
@@ -770,16 +776,20 @@ class DataHandler {
         * @return void
         */
        public function setDefaultsFromUserTS($userTS) {
-               if (is_array($userTS)) {
-                       foreach ($userTS as $k => $v) {
-                               $k = substr($k, 0, -1);
-                               if ($k && is_array($v) && isset($GLOBALS['TCA'][$k])) {
-                                       if (is_array($this->defaultValues[$k])) {
-                                               $this->defaultValues[$k] = array_merge($this->defaultValues[$k], $v);
-                                       } else {
-                                               $this->defaultValues[$k] = $v;
-                                       }
-                               }
+               if (!is_array($userTS)) {
+                       return;
+               }
+
+               foreach ($userTS as $k => $v) {
+                       $k = substr($k, 0, -1);
+                       if (!$k || !is_array($v) || !isset($GLOBALS['TCA'][$k])) {
+                               continue;
+                       }
+
+                       if (is_array($this->defaultValues[$k])) {
+                               $this->defaultValues[$k] = array_merge($this->defaultValues[$k], $v);
+                       } else {
+                               $this->defaultValues[$k] = $v;
                        }
                }
        }
@@ -792,26 +802,28 @@ class DataHandler {
         * @return void
         */
        public function process_uploads($postFiles) {
-               if (is_array($postFiles)) {
-                       // Editing frozen:
-                       if ($this->BE_USER->workspace !== 0 && $this->BE_USER->workspaceRec['freeze']) {
-                               if ($this->enableLogging) {
-                                       $this->newlog('All editing in this workspace has been frozen!', 1);
-                               }
-                               return FALSE;
+               if (!is_array($postFiles)) {
+                       return;
+               }
+
+               // Editing frozen:
+               if ($this->BE_USER->workspace !== 0 && $this->BE_USER->workspaceRec['freeze']) {
+                       if ($this->enableLogging) {
+                               $this->newlog('All editing in this workspace has been frozen!', 1);
                        }
-                       $subA = reset($postFiles);
-                       if (is_array($subA)) {
-                               if (is_array($subA['name']) && is_array($subA['type']) && is_array($subA['tmp_name']) && is_array($subA['size'])) {
-                                       // Initialize the uploadedFilesArray:
-                                       $this->uploadedFileArray = array();
-                                       // For each entry:
-                                       foreach ($subA as $key => $values) {
-                                               $this->process_uploads_traverseArray($this->uploadedFileArray, $values, $key);
-                                       }
-                               } else {
-                                       $this->uploadedFileArray = $subA;
+                       return FALSE;
+               }
+               $subA = reset($postFiles);
+               if (is_array($subA)) {
+                       if (is_array($subA['name']) && is_array($subA['type']) && is_array($subA['tmp_name']) && is_array($subA['size'])) {
+                               // Initialize the uploadedFilesArray:
+                               $this->uploadedFileArray = array();
+                               // For each entry:
+                               foreach ($subA as $key => $values) {
+                                       $this->process_uploads_traverseArray($this->uploadedFileArray, $values, $key);
                                }
+                       } else {
+                               $this->uploadedFileArray = $subA;
                        }
                }
        }
@@ -2425,28 +2437,32 @@ class DataHandler {
         * @param array $actionCMDs
         */
        protected function _ACTION_FLEX_FORMdata(&$valueArray, $actionCMDs) {
-               if (is_array($valueArray) && is_array($actionCMDs)) {
-                       foreach ($actionCMDs as $key => $value) {
-                               if ($key == '_ACTION') {
-                                       // First, check if there are "commands":
-                                       if (current($actionCMDs[$key]) !== '') {
-                                               asort($actionCMDs[$key]);
-                                               $newValueArray = array();
-                                               foreach ($actionCMDs[$key] as $idx => $order) {
-                                                       if (substr($idx, 0, 3) == 'ID-') {
-                                                               $idx = $this->newIndexMap[$idx];
-                                                       }
-                                                       // Just one reflection here: It is clear that when removing elements from a flexform, then we will get lost files unless we act on this delete operation by traversing and deleting files that were referred to.
-                                                       if ($order != 'DELETE') {
-                                                               $newValueArray[$idx] = $valueArray[$idx];
-                                                       }
-                                                       unset($valueArray[$idx]);
-                                               }
-                                               $valueArray = $valueArray + $newValueArray;
+               if (!is_array($valueArray) || !is_array($actionCMDs)) {
+                       return;
+               }
+
+               foreach ($actionCMDs as $key => $value) {
+                       if ($key == '_ACTION') {
+                               // First, check if there are "commands":
+                               if (current($actionCMDs[$key]) === '') {
+                                       continue;
+                               }
+
+                               asort($actionCMDs[$key]);
+                               $newValueArray = array();
+                               foreach ($actionCMDs[$key] as $idx => $order) {
+                                       if (substr($idx, 0, 3) == 'ID-') {
+                                               $idx = $this->newIndexMap[$idx];
+                                       }
+                                       // Just one reflection here: It is clear that when removing elements from a flexform, then we will get lost files unless we act on this delete operation by traversing and deleting files that were referred to.
+                                       if ($order != 'DELETE') {
+                                               $newValueArray[$idx] = $valueArray[$idx];
                                        }
-                               } elseif (is_array($actionCMDs[$key]) && isset($valueArray[$key])) {
-                                       $this->_ACTION_FLEX_FORMdata($valueArray[$key], $actionCMDs[$key]);
+                                       unset($valueArray[$idx]);
                                }
+                               $valueArray = $valueArray + $newValueArray;
+                       } elseif (is_array($actionCMDs[$key]) && isset($valueArray[$key])) {
+                               $this->_ACTION_FLEX_FORMdata($valueArray[$key], $actionCMDs[$key]);
                        }
                }
        }