[TASK] Allow to define multiple DataHandler commands for one element 50/44350/3
authorOliver Hader <oliver@typo3.org>
Thu, 29 Oct 2015 12:31:16 +0000 (13:31 +0100)
committerBenni Mack <benni@typo3.org>
Thu, 5 Nov 2015 11:40:47 +0000 (12:40 +0100)
The method DataHandler::process_cmdmap currently allows only one command
to be executed for one element. A command-map like the following is
currently not possible - the second command would be ignored:

[tt_content][13][localize] = 1
[tt_content][13][inlineLocalizeSynchronize] = children:14

Resolves: #71125
Releases: master, 6.2
Change-Id: I473ea0de3789d77cb913ad64a26a666ab73c2a52
Reviewed-on: https://review.typo3.org/44350
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Classes/DataHandling/DataHandler.php

index 1d52c9a..86e3f98 100644 (file)
@@ -3262,7 +3262,6 @@ class DataHandler
 
             // Traverse the command map:
             foreach ($this->cmdmap[$table] as $id => $incomingCmdArray) {
-                $pasteUpdate = false;
                 if (!is_array($incomingCmdArray)) {
                     continue;
                 }
@@ -3272,77 +3271,75 @@ class DataHandler
                     $this->pagetreeNeedsRefresh = true;
                 }
 
-                // have found a command.
-                // Get command and value (notice, only one command is observed at a time!):
-                reset($incomingCmdArray);
-                $command = key($incomingCmdArray);
-                $value = current($incomingCmdArray);
-                if (is_array($value) && isset($value['action']) && $value['action'] === 'paste') {
-                    // Extended paste command: $command is set to "move" or "copy"
-                    // $value['update'] holds field/value pairs which should be updated after copy/move operation
-                    // $value['target'] holds original $value (target of move/copy)
-                    $pasteUpdate = $value['update'];
-                    $value = $value['target'];
-                }
-                foreach ($hookObjectsArr as $hookObj) {
-                    if (method_exists($hookObj, 'processCmdmap_preProcess')) {
-                        $hookObj->processCmdmap_preProcess($command, $table, $id, $value, $this, $pasteUpdate);
+                foreach ($incomingCmdArray as $command => $value) {
+                    $pasteUpdate = false;
+                    if (is_array($value) && isset($value['action']) && $value['action'] === 'paste') {
+                        // Extended paste command: $command is set to "move" or "copy"
+                        // $value['update'] holds field/value pairs which should be updated after copy/move operation
+                        // $value['target'] holds original $value (target of move/copy)
+                        $pasteUpdate = $value['update'];
+                        $value = $value['target'];
                     }
-                }
-                // Init copyMapping array:
-                // Must clear this array before call from here to those functions:
-                // Contains mapping information between new and old id numbers.
-                $this->copyMappingArray = array();
-                // process the command
-                $commandIsProcessed = false;
-                foreach ($hookObjectsArr as $hookObj) {
-                    if (method_exists($hookObj, 'processCmdmap')) {
-                        $hookObj->processCmdmap($command, $table, $id, $value, $commandIsProcessed, $this, $pasteUpdate);
+                    foreach ($hookObjectsArr as $hookObj) {
+                        if (method_exists($hookObj, 'processCmdmap_preProcess')) {
+                            $hookObj->processCmdmap_preProcess($command, $table, $id, $value, $this, $pasteUpdate);
+                        }
                     }
-                }
-                // Only execute default commands if a hook hasn't been processed the command already
-                if (!$commandIsProcessed) {
-                    $procId = $id;
-                    // Branch, based on command
-                    switch ($command) {
-                        case 'move':
-                            $this->moveRecord($table, $id, $value);
-                            break;
-                        case 'copy':
-                            if ($table === 'pages') {
-                                $this->copyPages($id, $value);
-                            } else {
-                                $this->copyRecord($table, $id, $value, 1);
-                            }
-                            $procId = $this->copyMappingArray[$table][$id];
-                            break;
-                        case 'localize':
-                            $this->localize($table, $id, $value);
-                            break;
-                        case 'inlineLocalizeSynchronize':
-                            $this->inlineLocalizeSynchronize($table, $id, $value);
-                            break;
-                        case 'copyFromLanguage':
-                            $this->copyRecordFromLanguage($table, $id, $value);
-                            break;
-                        case 'delete':
-                            $this->deleteAction($table, $id);
-                            break;
-                        case 'undelete':
-                            $this->undeleteRecord($table, $id);
-                            break;
+                    // Init copyMapping array:
+                    // Must clear this array before call from here to those functions:
+                    // Contains mapping information between new and old id numbers.
+                    $this->copyMappingArray = array();
+                    // process the command
+                    $commandIsProcessed = false;
+                    foreach ($hookObjectsArr as $hookObj) {
+                        if (method_exists($hookObj, 'processCmdmap')) {
+                            $hookObj->processCmdmap($command, $table, $id, $value, $commandIsProcessed, $this, $pasteUpdate);
+                        }
                     }
-                    if (is_array($pasteUpdate)) {
-                        $pasteDatamap[$table][$procId] = $pasteUpdate;
+                    // Only execute default commands if a hook hasn't been processed the command already
+                    if (!$commandIsProcessed) {
+                        $procId = $id;
+                        // Branch, based on command
+                        switch ($command) {
+                            case 'move':
+                                $this->moveRecord($table, $id, $value);
+                                break;
+                            case 'copy':
+                                if ($table === 'pages') {
+                                    $this->copyPages($id, $value);
+                                } else {
+                                    $this->copyRecord($table, $id, $value, 1);
+                                }
+                                $procId = $this->copyMappingArray[$table][$id];
+                                break;
+                            case 'localize':
+                                $this->localize($table, $id, $value);
+                                break;
+                            case 'inlineLocalizeSynchronize':
+                                $this->inlineLocalizeSynchronize($table, $id, $value);
+                                break;
+                            case 'copyFromLanguage':
+                                $this->copyRecordFromLanguage($table, $id, $value);
+                                break;
+                            case 'delete':
+                                $this->deleteAction($table, $id);
+                                break;
+                            case 'undelete':
+                                $this->undeleteRecord($table, $id);
+                                break;
+                        }
+                        if (is_array($pasteUpdate)) {
+                            $pasteDatamap[$table][$procId] = $pasteUpdate;
+                        }
                     }
-                }
-                foreach ($hookObjectsArr as $hookObj) {
-                    if (method_exists($hookObj, 'processCmdmap_postProcess')) {
-                        $hookObj->processCmdmap_postProcess($command, $table, $id, $value, $this, $pasteUpdate, $pasteDatamap);
+                    foreach ($hookObjectsArr as $hookObj) {
+                        if (method_exists($hookObj, 'processCmdmap_postProcess')) {
+                            $hookObj->processCmdmap_postProcess($command, $table, $id, $value, $this, $pasteUpdate, $pasteDatamap);
+                        }
                     }
+                    // Merging the copy-array info together for remapping purposes.
+                    ArrayUtility::mergeRecursiveWithOverrule($this->copyMappingArray_merged, $this->copyMappingArray);
                 }
-                // Merging the copy-array info together for remapping purposes.
-                ArrayUtility::mergeRecursiveWithOverrule($this->copyMappingArray_merged, $this->copyMappingArray);
             }
         }
         /** @var $copyTCE DataHandler */