[BUGFIX] Missing behaviour of options.workspaces.changeStageMode
authorOliver Hader <oliver@typo3.org>
Mon, 13 Jun 2011 15:34:39 +0000 (17:34 +0200)
committerOliver Hader <oliver@typo3.org>
Mon, 13 Jun 2011 15:34:39 +0000 (17:34 +0200)
The mentioned User TSconfig setting was ignored for elements
that are not stored using an IRRE scheme. By applying the modifications
directly to the commandMap, independently to and IRRE structure, the
behaviour will be the same as in TYPO3 4.4.

Change-Id: I23c814ef21274d2831b1fcaa83961d75f131f0d2
Resolves: #26086
Releases: 4.6, 4.5

typo3/sysext/version/class.tx_version_tcemain_commandmap.php

index 8e5dec6..7d18922 100644 (file)
@@ -206,35 +206,81 @@ class tx_version_tcemain_CommandMap {
        }
 
        /**
-        * Resolves workspaces related dependencies for swapping/publishing of the command map.
-        * Workspaces records that have children or (relative) parents which are versionized
-        * but not published with this request, are removed from the command map. Otherwise
-        * this would produce hanging record sets and lost references.
+        * Invokes all items for swapping/publishing with a callback method.
         *
+        * @param string $callbackMethod
+        * @param array $arguments Optional leading arguments for the callback method
         * @return void
         */
-       protected function resolveWorkspacesSwapDependencies() {
-               $scope = self::SCOPE_WorkspacesSwap;
-               $dependency = $this->getDependencyUtility($scope);
-
+       protected function invokeWorkspacesSwapItems($callbackMethod, array $arguments = array()) {
                        // Traverses the cmd[] array and fetches the accordant actions:
                foreach ($this->commandMap as $table => $liveIdCollection) {
                        foreach ($liveIdCollection as $liveId => $commandCollection) {
                                foreach ($commandCollection as $command => $properties) {
                                        if ($command === 'version' && isset($properties['action']) && $properties['action'] === 'swap') {
                                                if (isset($properties['swapWith']) && t3lib_div::testInt($properties['swapWith'])) {
-                                                       $this->addWorkspacesSwapElements($dependency, $table, $liveId, $properties);
+                                                       call_user_func_array(
+                                                               array($this, $callbackMethod),
+                                                               array_merge($arguments, array($table, $liveId, $properties))
+                                                       );
                                                }
                                        }
                                }
                        }
                }
+       }
+
+       /**
+        * Resolves workspaces related dependencies for swapping/publishing of the command map.
+        * Workspaces records that have children or (relative) parents which are versionized
+        * but not published with this request, are removed from the command map. Otherwise
+        * this would produce hanging record sets and lost references.
+        *
+        * @return void
+        */
+       protected function resolveWorkspacesSwapDependencies() {
+               $scope = self::SCOPE_WorkspacesSwap;
+               $dependency = $this->getDependencyUtility($scope);
+
+               if (t3lib_div::inList('any,pages', $this->workspacesSwapMode)) {
+                       $this->invokeWorkspacesSwapItems('applyWorkspacesSwapBehaviour');
+               }
+               $this->invokeWorkspacesSwapItems('addWorkspacesSwapElements', array($dependency));
 
                $this->applyWorkspacesDependencies($dependency, $scope);
        }
 
        /**
-        * Adds workspaces elements for swapping/publishing and takes care of the swapMode.
+        * Applies workspaces behaviour for swapping/publishing and takes care of the swapMode.
+        *
+        * @param string $table
+        * @param integer $liveId
+        * @param array $properties
+        * @return void
+        */
+       protected function applyWorkspacesSwapBehaviour($table, $liveId, array $properties) {
+               $extendedCommandMap = array();
+               $elementList = array();
+
+               // Fetch accordant elements if the swapMode is 'any' or 'pages':
+               if ($this->workspacesSwapMode === 'any' || $this->workspacesSwapMode === 'pages' && $table === 'pages') {
+                       $elementList = $this->getParent()->findPageElementsForVersionSwap($table, $liveId, $properties['swapWith']);
+               }
+
+               foreach ($elementList as $elementTable => $elementIdArray) {
+                       foreach ($elementIdArray as $elementIds) {
+                               $extendedCommandMap[$elementTable][$elementIds[0]]['version'] = array_merge($properties, array('swapWith' => $elementIds[1]));
+                       }
+               }
+
+               if (count($elementList) > 0) {
+                       $this->remove($table, $liveId, 'version');
+                       $this->mergeToBottom($extendedCommandMap);
+               }
+       }
+
+       /**
+        * Adds workspaces elements for swapping/publishing.
         *
         * @param t3lib_utility_Dependency $dependency
         * @param string $table
@@ -267,43 +313,60 @@ class tx_version_tcemain_CommandMap {
        }
 
        /**
-        * Resolves workspaces related dependencies for staging of the command map.
-        * Workspaces records that have children or (relative) parents which are versionized
-        * but not staged with this request, are removed from the command map.
+        * Invokes all items for staging with a callback method.
         *
+        * @param string $callbackMethod
+        * @param array $arguments Optional leading arguments for the callback method
         * @return void
         */
-       protected function resolveWorkspacesSetStageDependencies() {
-               $scope = self::SCOPE_WorkspacesSetStage;
-               $dependency = $this->getDependencyUtility($scope);
-
+       protected function invokeWorkspacesSetStageItems($callbackMethod, array $arguments = array()) {
                        // Traverses the cmd[] array and fetches the accordant actions:
                foreach ($this->commandMap as $table => $liveIdCollection) {
                        foreach ($liveIdCollection as $liveIdList => $commandCollection) {
                                foreach ($commandCollection as $command => $properties) {
                                        if ($command === 'version' && isset($properties['action']) && $properties['action'] === 'setStage') {
                                                if (isset($properties['stageId']) && t3lib_div::testInt($properties['stageId'])) {
-                                                       $this->addWorkspacesSetStageElements($dependency, $table, $liveIdList, $properties);
-                                                       $this->explodeSetStage($table, $liveIdList, $properties);
+                                                       call_user_func_array(
+                                                               array($this, $callbackMethod),
+                                                               array_merge($arguments, array($table, $liveIdList, $properties))
+                                                       );
                                                }
                                        }
                                }
                        }
                }
+       }
+
+       /**
+        * Resolves workspaces related dependencies for staging of the command map.
+        * Workspaces records that have children or (relative) parents which are versionized
+        * but not staged with this request, are removed from the command map.
+        *
+        * @return void
+        */
+       protected function resolveWorkspacesSetStageDependencies() {
+               $scope = self::SCOPE_WorkspacesSetStage;
+               $dependency = $this->getDependencyUtility($scope);
+
+               if (t3lib_div::inList('any,pages', $this->workspacesChangeStageMode)) {
+                       $this->invokeWorkspacesSetStageItems('applyWorkspacesSetStageBehaviour');
+               }
+               $this->invokeWorkspacesSetStageItems('explodeSetStage');
+               $this->invokeWorkspacesSetStageItems('addWorkspacesSetStageElements', array($dependency));
 
                $this->applyWorkspacesDependencies($dependency, $scope);
        }
 
        /**
-        * Adds workspaces elements for staging and takes care of the changeStageMode.
+        * Applies workspaces behaviour for staging and takes care of the changeStageMode.
         *
-        * @param t3lib_utility_Dependency $dependency
         * @param string $table
         * @param string $liveIdList
         * @param array $properties
         * @return void
         */
-       protected function addWorkspacesSetStageElements(t3lib_utility_Dependency $dependency, $table, $liveIdList, array $properties) {
+       protected function applyWorkspacesSetStageBehaviour($table, $liveIdList, array $properties) {
+               $extendedCommandMap = array();
                $liveIds = t3lib_div::trimExplode(',', $liveIdList, TRUE);
                $elementList = array($table => $liveIds);
 
@@ -330,12 +393,28 @@ class tx_version_tcemain_CommandMap {
 
                foreach ($elementList as $elementTable => $elementIds) {
                        foreach($elementIds as $elementId) {
-                               $dependency->addElement(
-                                       $elementTable, $elementId,
-                                       array('properties' => $properties)
-                               );
+                               $extendedCommandMap[$elementTable][$elementId]['version'] = $properties;
                        }
                }
+
+               $this->remove($table, $liveIdList, 'version');
+               $this->mergeToBottom($extendedCommandMap);
+       }
+
+       /**
+        * Adds workspaces elements for staging.
+        *
+        * @param t3lib_utility_Dependency $dependency
+        * @param string $table
+        * @param string $liveIdList
+        * @param array $properties
+        * @return void
+        */
+       protected function addWorkspacesSetStageElements(t3lib_utility_Dependency $dependency, $table, $liveIdList, array $properties) {
+               $dependency->addElement(
+                       $table, $liveIdList,
+                       array('properties' => $properties)
+               );
        }
 
        /**