[BUGFIX] Fix BackendUtility::selectVersionsOfRecord parameter 20/42720/5
authorAlexander Opitz <opitz.alexander@googlemail.com>
Tue, 18 Aug 2015 17:02:44 +0000 (19:02 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Thu, 10 Sep 2015 06:36:17 +0000 (08:36 +0200)
The fix in #60249 accidently changed the meaning of the workspace
parameter, so that some lowlevel_cleaner didn't worked correct anymore.
We now add the old ability to find versions over all workspaces.

Resolves: #69135
Releases: master, 6.2
Change-Id: I8999bf2e6487391d41cc7ce80461afb8e813ce97
Reviewed-on: http://review.typo3.org/42720
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/lowlevel/Classes/CleanerCommand.php
typo3/sysext/lowlevel/Classes/VersionsCommand.php
typo3/sysext/version/Classes/Controller/VersionModuleController.php
typo3/sysext/version/Classes/View/VersionView.php

index b15f374..4fc1f1a 100755 (executable)
@@ -4012,7 +4012,7 @@ class BackendUtility {
         * @param string $table Table name to select from
         * @param int $uid Record uid for which to find versions.
         * @param string $fields Field list to select
-        * @param int $workspace Workspace ID, if zero all versions regardless of workspace is found.
+        * @param int|NULL $workspace Search in workspace ID and Live WS, if 0 search only in LiveWS, if NULL search in all WS.
         * @param bool $includeDeletedRecords If set, deleted-flagged versions are included! (Only for clean-up script!)
         * @param array $row The current record
         * @return array|NULL Array of versions of table/uid
@@ -4020,7 +4020,6 @@ class BackendUtility {
        static public function selectVersionsOfRecord($table, $uid, $fields = '*', $workspace = 0, $includeDeletedRecords = FALSE, $row = NULL) {
                $realPid = 0;
                $outputRows = array();
-               $workspace = (int)$workspace;
                if ($GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
                        if (is_array($row) && !$includeDeletedRecords) {
                                $row['_CURRENT_VERSION'] = TRUE;
@@ -4036,12 +4035,20 @@ class BackendUtility {
                                        $outputRows[] = $row;
                                }
                        }
+                       $workspaceSqlPart = '';
+                       if ($workspace === 0) {
+                               // Only in Live WS
+                               $workspaceSqlPart = ' AND t3ver_wsid=0';
+                       } elseif ($workspace !== NULL) {
+                               // In Live WS and Workspace with given ID
+                               $workspaceSqlPart = ' AND t3ver_wsid IN (0,' . (int)$workspace . ')';
+                       }
                        // Select all offline versions of record:
                        $rows = static::getDatabaseConnection()->exec_SELECTgetRows(
                                $fields,
                                $table,
                                'pid=-1 AND uid<>' . (int)$uid . ' AND t3ver_oid=' . (int)$uid
-                                       . ' AND t3ver_wsid' . ($workspace !== 0 ? ' IN (0,' . (int)$workspace . ')' : '=0')
+                                       . $workspaceSqlPart
                                        . ($includeDeletedRecords ? '' : self::deleteClause($table)),
                                '',
                                't3ver_id DESC'
index 3d67078..f4ca2b6 100644 (file)
@@ -455,7 +455,7 @@ NOW Running --AUTOFIX on result. OK?' . ($this->cli_isArg('--dryrun') ? ' (--dry
                                                }
                                                // Add any versions of those records:
                                                if ($this->genTree_traverseVersions) {
-                                                       $versions = BackendUtility::selectVersionsOfRecord($tableName, $rowSub['uid'], 'uid,t3ver_wsid,t3ver_count' . ($GLOBALS['TCA'][$tableName]['ctrl']['delete'] ? ',' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] : ''), 0, TRUE);
+                                                       $versions = BackendUtility::selectVersionsOfRecord($tableName, $rowSub['uid'], 'uid,t3ver_wsid,t3ver_count' . ($GLOBALS['TCA'][$tableName]['ctrl']['delete'] ? ',' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] : ''), NULL, TRUE);
                                                        if (is_array($versions)) {
                                                                foreach ($versions as $verRec) {
                                                                        if (!$verRec['_CURRENT_VERSION']) {
@@ -524,7 +524,7 @@ NOW Running --AUTOFIX on result. OK?' . ($this->cli_isArg('--dryrun') ? ' (--dry
                        }
                        // Add any versions of pages
                        if ($rootID > 0 && $this->genTree_traverseVersions) {
-                               $versions = BackendUtility::selectVersionsOfRecord('pages', $rootID, 'uid,t3ver_oid,t3ver_wsid,t3ver_count', 0, TRUE);
+                               $versions = BackendUtility::selectVersionsOfRecord('pages', $rootID, 'uid,t3ver_oid,t3ver_wsid,t3ver_count', NULL, TRUE);
                                if (is_array($versions)) {
                                        foreach ($versions as $verRec) {
                                                if (!$verRec['_CURRENT_VERSION']) {
index b084cc2..f6efb52 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Lowlevel;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Versioning\VersionState;
 
 /**
@@ -86,8 +87,8 @@ Automatic Repair:
                                        't3ver_state=' . new VersionState(VersionState::NEW_PLACEHOLDER) . ' AND pid>=0' . BackendUtility::deleteClause($table)
                                );
                                foreach ($placeHolders as $phrec) {
-                                       if (count(BackendUtility::selectVersionsOfRecord($table, $phrec['uid'], 'uid')) <= 1) {
-                                               $resultArray['versions_unused_placeholders'][\TYPO3\CMS\Core\Utility\GeneralUtility::shortmd5($table . ':' . $phrec['uid'])] = $table . ':' . $phrec['uid'];
+                                       if (count(BackendUtility::selectVersionsOfRecord($table, $phrec['uid'], 'uid', '*', NULL)) <= 1) {
+                                               $resultArray['versions_unused_placeholders'][GeneralUtility::shortmd5($table . ':' . $phrec['uid'])] = $table . ':' . $phrec['uid'];
                                        }
                                }
                        }
@@ -104,7 +105,7 @@ Automatic Repair:
                                        't3ver_state=' . new VersionState(VersionState::MOVE_PLACEHOLDER) . ' AND pid>=0' . BackendUtility::deleteClause($table)
                                );
                                foreach ($placeHolders as $phrec) {
-                                       $shortID = \TYPO3\CMS\Core\Utility\GeneralUtility::shortmd5($table . ':' . $phrec['uid']);
+                                       $shortID = GeneralUtility::shortmd5($table . ':' . $phrec['uid']);
                                        if ((int)$phrec['t3ver_wsid'] != 0) {
                                                $phrecCopy = $phrec;
                                                if (BackendUtility::movePlhOL($table, $phrec)) {
@@ -178,7 +179,7 @@ Automatic Repair:
                                        echo $bypass;
                                } else {
                                        // Execute CMD array:
-                                       $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
+                                       $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
                                        $tce->stripslashes_values = FALSE;
                                        $tce->start(array(), array());
                                        $tce->deleteEl($table, $uid, TRUE, TRUE);
@@ -217,7 +218,7 @@ Automatic Repair:
                                echo $bypass;
                        } else {
                                // Execute CMD array:
-                               $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
+                               $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
                                $tce->stripslashes_values = FALSE;
                                $tce->start(array(), array());
                                $tce->deleteAction($table, $uid);
index c7dc26b..ba71e0d 100644 (file)
@@ -487,7 +487,7 @@ class VersionModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass
         * @return int Number of versions for record, FALSE if none.
         */
        public function lookForOwnVersions($table, $uid) {
-               $versions = BackendUtility::selectVersionsOfRecord($table, $uid, 'uid');
+               $versions = BackendUtility::selectVersionsOfRecord($table, $uid, 'uid', NULL);
                if (is_array($versions)) {
                        return count($versions);
                }
index 9808eed..e3ad159 100644 (file)
@@ -44,7 +44,7 @@ class VersionView {
                        // If the selected page is not online, find the right ID
                        $onlineId = $curPage['pid'] == -1 ? $curPage['t3ver_oid'] : $id;
                        // Select all versions of online version:
-                       $versions = BackendUtility::selectVersionsOfRecord('pages', $onlineId, 'uid,pid,t3ver_label,t3ver_oid,t3ver_wsid,t3ver_id');
+                       $versions = BackendUtility::selectVersionsOfRecord('pages', $onlineId, 'uid,pid,t3ver_label,t3ver_oid,t3ver_wsid,t3ver_id', NULL);
                        // If more than one was found...:
                        if (count($versions) > 1) {
                                // Create selector box entries: