[TASK] Streamline assignment of current workspace in DataHandler 25/51325/6
authorOliver Hader <oliver@typo3.org>
Mon, 16 Jan 2017 12:42:36 +0000 (13:42 +0100)
committerSusanne Moog <susanne.moog@typo3.org>
Mon, 16 Jan 2017 16:42:21 +0000 (17:42 +0100)
The processing of data structures in DataHandler and RelationHandler
are bound to each other. DataHandler allows to be initialized with a
custom BE_USER instance and thus with a custom workspace, different
to the actual value of the real instance of $GLOBALS['BE_USER'].

This patch streamlines the workspace disposal by explicitly
forwarding the provided workspace to RelationHandler and avoids
fetching the current workspace for processing from global values.

The consideration of workspace related fields in RelationHandler was
bound to the current workspace of the global backend user - however,
this backend user constraint has been removed now.

Resolves: #79339
Releases: master
Change-Id: I3973d55c5b9d99ed2e976b86136338fee79d5f6e
Reviewed-on: https://review.typo3.org/51325
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Classes/Database/RelationHandler.php
typo3/sysext/version/Classes/Hook/DataHandlerHook.php

index f0e70a6..0608b50 100644 (file)
@@ -8917,13 +8917,13 @@ class DataHandler
     }
 
     /**
-     * function to make the static call to GeneralUtility mockable
-     *
      * @return RelationHandler
      */
     protected function createRelationHandlerInstance()
     {
-        return GeneralUtility::makeInstance(RelationHandler::class);
+        $relationHandler = GeneralUtility::makeInstance(RelationHandler::class);
+        $relationHandler->setWorkspaceId($this->BE_USER->workspace);
+        return $relationHandler;
     }
 
     /**
index f3e4ceb..c2c4359 100644 (file)
@@ -437,7 +437,7 @@ class RelationHandler
             // Skip if not dealing with IRRE in a CSV list on a workspace
             if ($configuration['type'] !== 'inline' || empty($configuration['foreign_table']) || !empty($configuration['foreign_field'])
                 || !empty($configuration['MM']) || count($this->tableArray) !== 1 || empty($this->tableArray[$configuration['foreign_table']])
-                || (int)$GLOBALS['BE_USER']->workspace === 0 || !BackendUtility::isTableWorkspaceEnabled($configuration['foreign_table'])) {
+                || $this->getWorkspaceId() === 0 || !BackendUtility::isTableWorkspaceEnabled($configuration['foreign_table'])) {
                 return;
             }
 
@@ -1066,7 +1066,7 @@ class RelationHandler
             if (!(MathUtility::canBeInterpretedAsInteger($updateToUid) && $updateToUid > 0)) {
                 $updateToUid = 0;
             }
-            $considerWorkspaces = ($GLOBALS['BE_USER']->workspace !== 0 && BackendUtility::isTableWorkspaceEnabled($foreign_table));
+            $considerWorkspaces = BackendUtility::isTableWorkspaceEnabled($foreign_table);
             $fields = 'uid,pid,' . $foreign_field;
             // Consider the symmetric field if defined:
             if ($symmetric_field) {
index ebeafae..5628ab6 100644 (file)
@@ -711,7 +711,7 @@ class DataHandlerHook
             $record = BackendUtility::getRecord($table, $id);
             $stat = $dataHandler->BE_USER->checkWorkspace($record['t3ver_wsid']);
             // check if the usere is allowed to the current stage, so it's also allowed to send to next stage
-            if ($GLOBALS['BE_USER']->workspaceCheckStageForCurrent($record['t3ver_stage'])) {
+            if ($dataHandler->BE_USER->workspaceCheckStageForCurrent($record['t3ver_stage'])) {
                 // Set stage of record:
                 GeneralUtility::makeInstance(ConnectionPool::class)
                     ->getConnectionForTable($table)