Fixed bug #16310: Migrate regular workspaces to custom-stage workspaces (Thanks to...
authorSteffen Kamper <info@sk-typo3.de>
Tue, 16 Nov 2010 20:26:42 +0000 (20:26 +0000)
committerSteffen Kamper <info@sk-typo3.de>
Tue, 16 Nov 2010 20:26:42 +0000 (20:26 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9412 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/install/updates/class.tx_coreupdates_migrateworkspaces.php

index 1ddb5d0..d9a7786 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -25,6 +25,7 @@
 
 2010-11-16  Steffen Kamper  <steffen@typo3.org>
 
+       * Fixed bug #16310: Migrate regular workspaces to custom-stage workspaces (Thanks to Tolleiv Nietsch)
        * Fixed bug #16421: missing CSS style for pressed buttons in ExtJS / enable qtips / remove toolbar margin (Thanks to Fabien Udriot)
        * Fixed bug #16405: pageRenderer call addJsFile with leaving out 2nd parameter
        * Follow-up to #16408: Support for Custom Navigation Components: removed warning
index b297c95..42febb0 100644 (file)
@@ -52,14 +52,17 @@ class tx_coreupdates_migrateworkspaces extends tx_coreupdates_installsysexts {
         */
        public function checkForUpdate(&$description) {
                $result = FALSE;
-               $description = 'Migrates the old hardcoded draft workspace to be a real workspace element and update workspace owner fields  to support either users or groups.';
+               $description = 'Migrates the old hardcoded draft workspace to be a real workspace element,
+               updates workspace owner fields  to support either users or groups and
+               migrates the old-style workspaces with fixed workflow to a custom-stage workflow';
 
                        // TYPO3 version 4.5 and above
                if ($this->versionNumber >= 4005000) {
                        $tables = array_keys($GLOBALS['TYPO3_DB']->admin_get_tables());
                                // sys_workspace table might not exists if version extension was never installed
                        if (in_array('sys_workspace', $tables)) {
-                               $result = $this->isOldStyleAdminFieldUsed();
+                               $wsCount = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', 'sys_workspace', '');
+                               $result = $wsCount > 0;
                        }
 
                        if (!$result) {
@@ -102,8 +105,8 @@ class tx_coreupdates_migrateworkspaces extends tx_coreupdates_installsysexts {
                        // There's no TCA available yet
                $this->includeTCA();
 
-                       // install version extension (especially when updating from very old TYPO3 versions
-               $this->installExtensions(array('version'));
+                       // install version and workspace extension (especially when updating from very old TYPO3 versions
+               $this->installExtensions(array('version', 'workspaces'));
 
                        // migrate all workspaces to support groups and be_users
                if ($this->isOldStyleAdminFieldUsed()) {
@@ -118,6 +121,26 @@ class tx_coreupdates_migrateworkspaces extends tx_coreupdates_installsysexts {
                        }
                }
 
+               $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid, reviewers', 'sys_workspace', '', '', '', '1');
+               $this->sqlQueries[] =  $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
+               $label = 'Review';
+               foreach($workspaces as $workspace) {
+                       $where = 'parentid=' . $workspace['uid'] . ' AND parenttable="sys_workspace" AND deleted=0';
+                       $stageCount = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', 'sys_workspace_stage', $where);
+                       $this->sqlQueries[] =  $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
+                       if ($stageCount == 0) {
+                                       // Find all workspaces and add "review" stage record
+                                       // Add review users and groups to the new IRRE record
+                               $reviewStageId = $this->createReviewStageForWorkspace($workspace['uid'], $label, $workspace['reviewers']);
+                                       // Update all "review" state records in the database to point to the new state
+                               $this->migrateOldRecordsToStage($workspace['uid'], 1, $reviewStageId);
+                                       // Update all "ready to publish" records in the database to point to the new ready to publish state
+                               $this->migrateOldRecordsToStage($workspace['uid'], 10, -99);
+                       } else {
+                               // this workspace has stages already at this point we might break something if we continue
+                       }
+               }
+
                if (is_array($this->sqlQueries) && is_array($databaseQueries)) {
                        $databaseQueries = array_merge($databaseQueries, $this->sqlQueries);
                }
@@ -168,6 +191,51 @@ class tx_coreupdates_migrateworkspaces extends tx_coreupdates_installsysexts {
        }
 
        /**
+        * Create a new stage for the given workspace
+        *
+        * @param               integer Workspace ID
+        * @param               string          The label of the new stage
+        * @param               string          The users or groups which are authorized for that stage
+        * @return      integer The id of the new stage
+        */
+       protected function createReviewStageForWorkspace($workspaceId, $stageLabel, $stageMembers) {
+               $data = array(
+                       'parentid' => $workspaceId,
+                       'parenttable' => 'sys_workspace',
+                       'title' => $stageLabel,
+                       'responsible_persons' => $stageMembers
+               );
+               $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_workspace_stage', $data);
+               $this->sqlQueries[] =  $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
+               return $GLOBALS['TYPO3_DB']->sql_insert_id();
+       }
+
+       /**
+        * Updates the stages of placeholder records within the given workspace from $oldId to $newId
+        *
+        * @param               integer Workspace ID
+        * @param               integer Old stage od
+        * @param               integer New stage od
+        * @return      void
+        */
+       protected function migrateOldRecordsToStage($workspaceId, $oldStageId, $newStageId) {
+               $tables = array_keys($GLOBALS['TCA']);
+
+               $where = 't3ver_wsid = ' . intval($workspaceId) . ' AND t3ver_stage = ' . intval($oldStageId) . ' AND pid = -1';
+               $values = array(
+                       't3ver_stage' => intval($newStageId)
+               );
+               foreach($tables as $table) {
+                       $versioningVer = t3lib_div::intInRange($GLOBALS['TCA'][$table]['ctrl']['versioningWS'], 0, 2, 0);
+                       if ($versioningVer > 0) {
+                               $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, $where, $values);
+                               $this->sqlQueries[] =  $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
+                       }
+               }
+       }
+
+
+       /**
         * Check if there's any workspace which doesn't support the new admin-field format yet
         * @return bool
         */