[BUGFIX] Cleanup AbstractExceptionHandler and fix variable access 08/40608/2
authorMathias Schreiber <mathias.schreiber@wmdb.de>
Tue, 23 Jun 2015 16:52:01 +0000 (18:52 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 25 Jun 2015 09:05:53 +0000 (11:05 +0200)
AbstractExceptionHandler still used a formerly public property which
has been defined as protected in the meantime.
Cleaning up the code and using a getter method for access of $GLOBALS
revealed the issue.

Resolves: #67703
Releases: master, 6.2
Change-Id: I36ec96312769e09734891cc78ea4f800bb5af976
Reviewed-on: http://review.typo3.org/40608
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Error/AbstractExceptionHandler.php

index c01f941..b5cad95 100644 (file)
@@ -13,6 +13,8 @@ namespace TYPO3\CMS\Core\Error;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
+use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -93,30 +95,32 @@ abstract class AbstractExceptionHandler implements ExceptionHandlerInterface, \T
         * @return void
         */
        protected function writeLog($logMessage) {
-               if (is_object($GLOBALS['TYPO3_DB']) && !empty($GLOBALS['TYPO3_DB']->link)) {
-                       $userId = 0;
-                       $workspace = 0;
-                       if (is_object($GLOBALS['BE_USER'])) {
-                               if (isset($GLOBALS['BE_USER']->user['uid'])) {
-                                       $userId = $GLOBALS['BE_USER']->user['uid'];
-                               }
-                               if (isset($GLOBALS['BE_USER']->workspace)) {
-                                       $workspace = $GLOBALS['BE_USER']->workspace;
-                               }
+               $databaseConnection = $this->getDatabaseConnection();
+               if (!is_object($databaseConnection) || !$databaseConnection->isConnected()) {
+                       return;
+               }
+               $userId = 0;
+               $workspace = 0;
+               if (is_object($GLOBALS['BE_USER'])) {
+                       if (isset($GLOBALS['BE_USER']->user['uid'])) {
+                               $userId = $GLOBALS['BE_USER']->user['uid'];
+                       }
+                       if (isset($GLOBALS['BE_USER']->workspace)) {
+                               $workspace = $GLOBALS['BE_USER']->workspace;
                        }
-                       $fields_values = array(
-                               'userid' => $userId,
-                               'type' => 5,
-                               'action' => 0,
-                               'error' => 2,
-                               'details_nr' => 0,
-                               'details' => str_replace('%', '%%', $logMessage),
-                               'IP' => (string)GeneralUtility::getIndpEnv('REMOTE_ADDR'),
-                               'tstamp' => $GLOBALS['EXEC_TIME'],
-                               'workspace' => $workspace
-                       );
-                       $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_log', $fields_values);
                }
+               $fields_values = array(
+                       'userid' => $userId,
+                       'type' => 5,
+                       'action' => 0,
+                       'error' => 2,
+                       'details_nr' => 0,
+                       'details' => str_replace('%', '%%', $logMessage),
+                       'IP' => (string)GeneralUtility::getIndpEnv('REMOTE_ADDR'),
+                       'tstamp' => $GLOBALS['EXEC_TIME'],
+                       'workspace' => $workspace
+               );
+               $databaseConnection->exec_INSERTquery('sys_log', $fields_values);
        }
 
        /**
@@ -139,4 +143,12 @@ abstract class AbstractExceptionHandler implements ExceptionHandlerInterface, \T
                }
        }
 
+       /**
+        * Gets the Database Object
+        * @return DatabaseConnection
+        */
+       protected function getDatabaseConnection() {
+               return $GLOBALS['TYPO3_DB'];
+       }
+
 }