[TASK] Clean up object access via global variables 00/45500/2
authorOliver Hader <oliver@typo3.org>
Wed, 30 Dec 2015 08:16:41 +0000 (09:16 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Wed, 30 Dec 2015 10:18:36 +0000 (11:18 +0100)
Clean up object access via global variables to TYPO3_DB,
BE_USER and TT in the error handling service layer.

Resolves: #72471
Releases: master, 7.6
Change-Id: I8d4532924fad2eee676e4e87c8e61bb164bfa93d
Reviewed-on: https://review.typo3.org/45500
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Error/AbstractExceptionHandler.php
typo3/sysext/core/Classes/Error/ErrorHandler.php

index 47665ab..1e02d2c 100644 (file)
@@ -14,7 +14,6 @@ namespace TYPO3\CMS\Core\Error;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -108,12 +107,13 @@ abstract class AbstractExceptionHandler implements ExceptionHandlerInterface, \T
         }
         $userId = 0;
         $workspace = 0;
-        if (is_object($GLOBALS['BE_USER'])) {
-            if (isset($GLOBALS['BE_USER']->user['uid'])) {
-                $userId = $GLOBALS['BE_USER']->user['uid'];
+        $backendUser = $this->getBackendUser();
+        if (is_object($backendUser)) {
+            if (isset($backendUser->user['uid'])) {
+                $userId = $backendUser->user['uid'];
             }
-            if (isset($GLOBALS['BE_USER']->workspace)) {
-                $workspace = $GLOBALS['BE_USER']->workspace;
+            if (isset($backendUser->workspace)) {
+                $workspace = $backendUser->workspace;
             }
         }
         $fields_values = array(
@@ -153,8 +153,16 @@ abstract class AbstractExceptionHandler implements ExceptionHandlerInterface, \T
     }
 
     /**
+     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
+     */
+    protected function getBackendUser()
+    {
+        return $GLOBALS['BE_USER'];
+    }
+
+    /**
      * Gets the Database Object
-     * @return DatabaseConnection
+     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
      */
     protected function getDatabaseConnection()
     {
index 584f114..0c49916 100644 (file)
@@ -135,8 +135,9 @@ class ErrorHandler implements ErrorHandlerInterface
                 GeneralUtility::devLog($message, 'core', $severity + 1);
             }
             // Write error message to TSlog (admin panel)
-            if (is_object($GLOBALS['TT'])) {
-                $GLOBALS['TT']->setTSlogMessage($message, $severity + 1);
+            $timeTracker = $this->getTimeTracker();
+            if (is_object($timeTracker)) {
+                $timeTracker->setTSlogMessage($message, $severity + 1);
             }
             // Write error message to sys_log table (ext: belog, Tools->Log)
             if ($errorLevel & $GLOBALS['TYPO3_CONF_VARS']['SYS']['belogErrorReporting']) {
@@ -180,15 +181,17 @@ class ErrorHandler implements ErrorHandlerInterface
      */
     protected function writeLog($logMessage, $severity)
     {
-        if (is_object($GLOBALS['TYPO3_DB']) && $GLOBALS['TYPO3_DB']->isConnected()) {
+        $databaseConnection = $this->getDatabaseConnection();
+        if (is_object($databaseConnection) && $databaseConnection->isConnected()) {
             $userId = 0;
             $workspace = 0;
-            if (is_object($GLOBALS['BE_USER'])) {
-                if (isset($GLOBALS['BE_USER']->user['uid'])) {
-                    $userId = $GLOBALS['BE_USER']->user['uid'];
+            $backendUser = $this->getBackendUser();
+            if (is_object($backendUser)) {
+                if (isset($backendUser->user['uid'])) {
+                    $userId = $backendUser->user['uid'];
                 }
-                if (isset($GLOBALS['BE_USER']->workspace)) {
-                    $workspace = $GLOBALS['BE_USER']->workspace;
+                if (isset($backendUser->workspace)) {
+                    $workspace = $backendUser->workspace;
                 }
             }
             $fields_values = array(
@@ -202,7 +205,31 @@ class ErrorHandler implements ErrorHandlerInterface
                 'tstamp' => $GLOBALS['EXEC_TIME'],
                 'workspace' => $workspace
             );
-            $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_log', $fields_values);
+            $databaseConnection->exec_INSERTquery('sys_log', $fields_values);
         }
     }
+
+    /**
+     * @return \TYPO3\CMS\Core\TimeTracker\TimeTracker
+     */
+    protected function getTimeTracker()
+    {
+        return $GLOBALS['TT'];
+    }
+
+    /**
+     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
+     */
+    protected function getBackendUser()
+    {
+        return $GLOBALS['BE_USER'];
+    }
+
+    /**
+     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
+     */
+    protected function getDatabaseConnection()
+    {
+        return $GLOBALS['TYPO3_DB'];
+    }
 }