[BUGFIX] Set correct workspace ID when updating referenceIndex for files 81/36481/3
authorMarkus Klösges <mkloesges@gmx.de>
Fri, 16 Jan 2015 13:00:35 +0000 (14:00 +0100)
committerMarkus Klein <klein.t3@reelworx.at>
Thu, 26 Feb 2015 23:18:14 +0000 (00:18 +0100)
When publishing a workspace the referenceIndex entries of the affected
sys_file_reference rows were not updated with the new workspace. That's
because the user is always in the affected workspace and therefore
the workspace is not set to live as expected.
Now updating referenceIndex for both workspaces when swapping.

Resolves: #64253
Releases: master, 6.2
Change-Id: Icfb4fcd1ae92da4ea881105b387c3d6db20ece95
Reviewed-on: http://review.typo3.org/36481
Tested-by: Michael Schams <typo3@2014.trash.schams.net>
Reviewed-by: Stephan Großberndt <stephan@grossberndt.de>
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/core/Classes/Database/ReferenceIndex.php
typo3/sysext/version/Classes/Hook/DataHandlerHook.php

index 7365a5a..86f87e4 100644 (file)
@@ -118,6 +118,9 @@ class ReferenceIndex {
                        if (is_array($relations)) {
                                // Traverse the generated index:
                                foreach ($relations as $k => $datRec) {
+                                       if (!is_array($relations[$k])){
+                                               continue;
+                                       }
                                        $relations[$k]['hash'] = md5(implode('///', $relations[$k]) . '///' . $this->hashVersion);
                                        // First, check if already indexed and if so, unset that row (so in the end we know which rows to remove!)
                                        if (isset($currentRels[$relations[$k]['hash']])) {
@@ -237,6 +240,14 @@ class ReferenceIndex {
         * @todo Define visibility
         */
        public function createEntryData($table, $uid, $field, $flexpointer, $deleted, $ref_table, $ref_uid, $ref_string = '', $sort = -1, $softref_key = '', $softref_id = '') {
+               if (BackendUtility::isTableWorkspaceEnabled($table)) {
+                       $element = BackendUtility::getRecord($table, $uid, 't3ver_wsid');
+                       if ($element !== NULL && isset($element['t3ver_wsid']) && (int)$element['t3ver_wsid'] !== $this->getWorkspaceId()) {
+                               //The given Element is ws-enabled but doesn't live in the selected workspace
+                               // => don't add index as it's not actually there
+                               return FALSE;
+                       }
+               }
                return array(
                        'tablename' => $table,
                        'recuid' => $uid,
index bb10665..ac03ed4 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Version\Hook;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Database\ReferenceIndex;
 use TYPO3\CMS\Core\DataHandling\DataHandler;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Versioning\VersionState;
@@ -948,6 +949,13 @@ class DataHandlerHook {
                                                                                                // For delete + completely delete!
                                                                                                $tcemainObj->deleteEl($table, $swapWith, TRUE, TRUE);
                                                                                        }
+
+                                                                                       //Update reference index for live workspace too:
+                                                                                       /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */
+                                                                                       $refIndexObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\ReferenceIndex');
+                                                                                       $refIndexObj->setWorkspaceId(0);
+                                                                                       $refIndexObj->updateRefIndexTable($table, $id);
+                                                                                       $refIndexObj->updateRefIndexTable($table, $swapWith);
                                                                                } else {
                                                                                        $tcemainObj->newlog('During Swapping: SQL errors happened: ' . implode('; ', $sqlErrors), 2);
                                                                                }