[BUGFIX] Set correct workspace ID when updating referenceIndex for files 44/36044/7
authorMarkus Klösges <mkloesges@gmx.de>
Fri, 16 Jan 2015 13:00:35 +0000 (14:00 +0100)
committerFrans Saris <franssaris@gmail.com>
Fri, 30 Jan 2015 22:42:06 +0000 (23:42 +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/36044
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Fabien Udriot <fabien.udriot@ecodev.ch>
Tested-by: Fabien Udriot <fabien.udriot@ecodev.ch>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
typo3/sysext/core/Classes/Database/ReferenceIndex.php
typo3/sysext/version/Classes/Hook/DataHandlerHook.php

index 3f1f724..04016ec 100644 (file)
@@ -109,6 +109,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']])) {
@@ -223,6 +226,14 @@ class ReferenceIndex {
         * @return array Array record to insert into table.
         */
        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 fbe3223..9c9fd65 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(ReferenceIndex::class);
+                                                                                       $refIndexObj->setWorkspaceId(0);
+                                                                                       $refIndexObj->updateRefIndexTable($table, $id);
+                                                                                       $refIndexObj->updateRefIndexTable($table, $swapWith);
                                                                                } else {
                                                                                        $tcemainObj->newlog('During Swapping: SQL errors happened: ' . implode('; ', $sqlErrors), 2);
                                                                                }