[FEATURE] Save current workspace in ReferenceIndex 72/28472/4
authorOliver Hader <oliver@typo3.org>
Mon, 17 Mar 2014 14:08:15 +0000 (15:08 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Fri, 21 Mar 2014 19:25:46 +0000 (20:25 +0100)
To reduce queries to accordant relations saved in the reference
index, add the current workspace that is used. This information
will be used later during publishing nested record sets (e.g.
for Inline Relational Record Editing).

Resolves: #56977
Releases: 6.2
Change-Id: I92851e243581a525bb99fafc9ed656fd613eeb82
Reviewed-on: https://review.typo3.org/28472
Reviewed-by: Wouter Wolters
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Classes/Database/ReferenceIndex.php
typo3/sysext/core/Classes/Database/RelationHandler.php
typo3/sysext/core/ext_tables.sql

index 7db57c7..a1e4108 100644 (file)
@@ -6020,7 +6020,10 @@ class DataHandler {
        public function updateRefIndex($table, $id) {
                /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */
                $refIndexObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\ReferenceIndex');
-               $result = $refIndexObj->updateRefIndexTable($table, $id);
+               if (BackendUtility::isTableWorkspaceEnabled($table)) {
+                       $refIndexObj->setWorkspaceId($this->BE_USER->workspace);
+               }
+               $refIndexObj->updateRefIndexTable($table, $id);
        }
 
        /*********************************************
index f6551da..29a023f 100644 (file)
@@ -81,6 +81,29 @@ class ReferenceIndex {
        public $hashVersion = 1;
 
        /**
+        * @var int
+        */
+       protected $workspaceId = 0;
+
+       /**
+        * Sets the current workspace id.
+        *
+        * @param int $workspaceId
+        */
+       public function setWorkspaceId($workspaceId) {
+               $this->workspaceId = (int)$workspaceId;
+       }
+
+       /**
+        * Gets the current workspace id.
+        *
+        * @return int
+        */
+       public function getWorkspaceId() {
+               return $this->workspaceId;
+       }
+
+       /**
         * Call this function to update the sys_refindex table for a record (even one just deleted)
         * NOTICE: Currently, references updated for a deleted-flagged record will not include those from within flexform fields in some cases where the data structure is defined by another record since the resolving process ignores deleted records! This will also result in bad cleaning up in tcemain I think... Anyway, thats the story of flexforms; as long as the DS can change, lots of references can get lost in no time.
         *
@@ -242,6 +265,7 @@ class ReferenceIndex {
                        'softref_id' => $softref_id,
                        'sorting' => $sort,
                        'deleted' => $deleted,
+                       'workspace' => $this->getWorkspaceId(),
                        'ref_table' => $ref_table,
                        'ref_uid' => $ref_uid,
                        'ref_string' => $ref_string
@@ -895,7 +919,6 @@ class ReferenceIndex {
         * @param boolean $testOnly If set, only a test
         * @param boolean $cli_echo If set, output CLI status
         * @return array Header and body status content
-        * @todo Define visibility
         */
        public function updateIndex($testOnly, $cli_echo = FALSE) {
                $errors = array();
@@ -909,7 +932,8 @@ class ReferenceIndex {
                // Traverse all tables:
                foreach ($GLOBALS['TCA'] as $tableName => $cfg) {
                        // Traverse all records in tables, including deleted records:
-                       $allRecs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', $tableName, '1=1');
+                       $fieldNames = (BackendUtility::isTableWorkspaceEnabled($tableName) ? 'uid,t3ver_wsid' : 'uid');
+                       $allRecs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($fieldNames, $tableName, '1=1');
                        if (!is_array($allRecs)) {
                                // Table exists in $TCA but does not exist in the database
                                GeneralUtility::sysLog(sprintf('Table "%s" exists in $TCA but does not exist in the database. You should run the Database Analyzer in the Install Tool to fix this.', $tableName), 'core', GeneralUtility::SYSLOG_SEVERITY_ERROR);
@@ -919,7 +943,11 @@ class ReferenceIndex {
                        $tableCount++;
                        $uidList = array(0);
                        foreach ($allRecs as $recdat) {
+                               /** @var $refIndexObj ReferenceIndex */
                                $refIndexObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\ReferenceIndex');
+                               if (isset($recdat['t3ver_wsid'])) {
+                                       $refIndexObj->setWorkspaceId($recdat['t3ver_wsid']);
+                               }
                                $result = $refIndexObj->updateRefIndexTable($tableName, $recdat['uid'], $testOnly);
                                $uidList[] = $recdat['uid'];
                                $recCount++;
index 9a2b4e8..2efd0ba 100644 (file)
@@ -1030,6 +1030,9 @@ class RelationHandler {
                if ($this->updateReferenceIndex) {
                        /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */
                        $refIndexObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\ReferenceIndex');
+                       if (BackendUtility::isTableWorkspaceEnabled($table)) {
+                               $refIndexObj->setWorkspaceId($GLOBALS['BE_USER']->workspace);
+                       }
                        $statisticsArray = $refIndexObj->updateRefIndexTable($table, $id);
                }
                return $statisticsArray;
index e98eff6..681ce50 100644 (file)
@@ -588,6 +588,7 @@ CREATE TABLE sys_refindex (
   softref_id varchar(40) DEFAULT '' NOT NULL,
   sorting int(11) DEFAULT '0' NOT NULL,
   deleted tinyint(1) DEFAULT '0' NOT NULL,
+  workspace int(11) DEFAULT '0' NOT NULL,
   ref_table varchar(255) DEFAULT '' NOT NULL,
   ref_uid int(11) DEFAULT '0' NOT NULL,
   ref_string varchar(200) DEFAULT '' NOT NULL,