Fixed bug #17182: migrateWorkspaces in Install-Tool shows up even if nothing has...
authorErnesto Baschny <ernst@cron-it.de>
Fri, 21 Jan 2011 22:21:20 +0000 (22:21 +0000)
committerErnesto Baschny <ernst@cron-it.de>
Fri, 21 Jan 2011 22:21:20 +0000 (22:21 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@10232 709f56b5-9817-0410-a4d7-c38de5d9e867

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

index 85d9d8b..9c08666 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,7 @@
 
 2011-01-21  Ernesto Baschny  <ernst@cron-it.de>
 
+       * Fixed bug #17182: migrateWorkspaces in Install-Tool shows up even if nothing has to be done (Thanks to Tolleiv Nietsch)
        * Fixed bug #17184: Disable the CSRF protection in ExtDirect calls coming from the frontend (Thanks to Stefan Galinski)
        * Fixed bug #17201: The unit test for t3lib_formprotection_BackendFormProtection is broken (Thanks to Helmut Hummel)
        * Follow-up to issue #15589: Move debug functions to own utility class, missing t3lib_div commit from original patch, and declared all relevant methods "static" (Thanks to Stefan Galinski)
index 33b1089..fc65a53 100644 (file)
@@ -54,6 +54,8 @@ class tx_coreupdates_migrateworkspaces extends tx_coreupdates_installsysexts {
                        // TYPO3 version 4.5 and above
                if ($this->versionNumber >= 4005000) {
 
+                       $this->includeTCA();
+
                        if(!t3lib_extMgm::isLoaded('version') || !t3lib_extMgm::isLoaded('workspaces')) {
                                $result = TRUE;
                                $reason .= ' The extensions "version" and "workspaces" need to be
@@ -65,13 +67,12 @@ class tx_coreupdates_migrateworkspaces extends tx_coreupdates_installsysexts {
                        if (!in_array('sys_workspace', $tables) || !in_array('sys_workspace_stage', $tables)) {
                                $result = TRUE;
                                $reason .= ' The database tables for the workspace functionality are missing.';
-                       } else {
+                       } elseif ($this->isOldStyleAdminFieldUsed() || $this->isOldStyleWorkspace()) {
                                $wsCount = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', 'sys_workspace', '');
                                $result |= $wsCount > 0;
                                $reason .= ' The existing workspaces will be checked for compatibility with the new features.';
                        }
 
-                       $this->includeTCA();
                        $draftWorkspaceTestResult = $this->isDraftWorkspaceUsed();
                        if ($draftWorkspaceTestResult) {
                                $reason .= ' The old style draft workspace is used.
@@ -132,24 +133,17 @@ class tx_coreupdates_migrateworkspaces extends tx_coreupdates_installsysexts {
                        }
                }
 
-               $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid, reviewers', 'sys_workspace', '', '', '', '1');
+               $workspaces = $this->getWorkspacesWithoutStages();
                $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
-                       }
+                               // 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);
                }
 
                if (is_array($this->sqlQueries) && is_array($databaseQueries)) {
@@ -182,6 +176,43 @@ class tx_coreupdates_migrateworkspaces extends tx_coreupdates_installsysexts {
        }
 
        /**
+        * Find workspaces which have no sys_workspace_state(s) but have records using states
+        * If "
+        *
+        * @return bool
+        */
+       protected function isOldStyleWorkspace() {
+               $foundOldStyleStages = FALSE;
+               $workspaces = $this->getWorkspacesWithoutStages();
+               $workspacesWithReviewers = 0;
+               $workspaceUids = array();
+               foreach ($workspaces as $workspace) {
+                       $workspaceUids[] = $workspace['uid'];
+                       if ($workspace['reviewers']) {
+                               $workspacesWithReviewers++;
+                       }
+               }
+               if (!$workspacesWithReviewers && !empty($workspaceUids)) {
+                       $tables = array_keys($GLOBALS['TCA']);
+                       foreach ($tables as $table) {
+                               $versioningVer = t3lib_div::intInRange($GLOBALS['TCA'][$table]['ctrl']['versioningWS'], 0, 2, 0);
+                               if ($versioningVer > 0) {
+                                       $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
+                                               'uid',
+                                               $table,
+                                               't3ver_wsid IN (' . implode(',', $workspaceUids) . ') AND t3ver_stage IN (-1,1,10) AND pid = -1'
+                                       );
+                                       if ($count > 0) {
+                                               $foundOldStyleStages = TRUE;
+                                               break;
+                                       }
+                               }
+                       }
+               }
+               return $foundOldStyleStages || $workspacesWithReviewers;
+       }
+
+       /**
         * Create a new stage for the given workspace
         *
         * @param               integer Workspace ID
@@ -336,5 +367,21 @@ class tx_coreupdates_migrateworkspaces extends tx_coreupdates_installsysexts {
 
                return ($count > 0);
        }
+
+       /**
+        * Returns all sys_workspace records which are not referenced by  anysys_workspace_stages record
+        *
+        * @return array
+        */
+       protected function getWorkspacesWithoutStages() {
+               $stages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('parentid', 'sys_workspace_stages', 'parenttable="sys_workspace"');
+               $wsWhitelist = array();
+               foreach ($stages as $stage) {
+                       $wsWhitelist[] = $stage['parentid'];
+               }
+               $where = 'deleted=0';
+               $where .= (!empty($wsWhitelist) ? ' AND uid NOT IN (' . implode(',', $wsWhitelist) . ')' : '');
+               return $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_workspace', $where);
+       }
 }
 ?>