[TASK] Doctrine: Migrate error handlers 64/49264/3
authorWouter Wolters <typo3@wouterwolters.nl>
Fri, 29 Jul 2016 11:55:18 +0000 (13:55 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 2 Aug 2016 08:35:18 +0000 (10:35 +0200)
Migrate ErrorHandler and AbstractExceptionHandler to doctrine.

Resolves: #77303
Releases: master
Change-Id: Iae16efbed298b1fd3f8ab2bcd1289df1d2d14919
Reviewed-on: https://review.typo3.org/49264
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Error/AbstractExceptionHandler.php
typo3/sysext/core/Classes/Error/ErrorHandler.php

index a3f06e9..bffd2f2 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Error;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -95,8 +96,10 @@ abstract class AbstractExceptionHandler implements ExceptionHandlerInterface, \T
      */
     protected function writeLog($logMessage)
     {
-        $databaseConnection = $this->getDatabaseConnection();
-        if (!is_object($databaseConnection) || !$databaseConnection->isConnected()) {
+        $connection = GeneralUtility::makeInstance(ConnectionPool::class)
+            ->getConnectionForTable('sys_log');
+
+        if (!$connection->isConnected()) {
             return;
         }
         $userId = 0;
@@ -114,19 +117,22 @@ abstract class AbstractExceptionHandler implements ExceptionHandlerInterface, \T
                 $data['originalUser'] = $backendUser->user['ses_backuserid'];
             }
         }
-        $fields_values = array(
-            'userid' => $userId,
-            'type' => 5,
-            'action' => 0,
-            'error' => 2,
-            'details_nr' => 0,
-            'details' => str_replace('%', '%%', $logMessage),
-            'log_data' => (empty($data) ? '' : serialize($data)),
-            'IP' => (string)GeneralUtility::getIndpEnv('REMOTE_ADDR'),
-            'tstamp' => $GLOBALS['EXEC_TIME'],
-            'workspace' => $workspace
+
+        $connection->insert(
+            'sys_log',
+            [
+                'userid' => $userId,
+                'type' => 5,
+                'action' => 0,
+                'error' => 2,
+                'details_nr' => 0,
+                'details' => str_replace('%', '%%', $logMessage),
+                'log_data' => empty($data) ? '' : serialize($data),
+                'IP' => (string)GeneralUtility::getIndpEnv('REMOTE_ADDR'),
+                'tstamp' => $GLOBALS['EXEC_TIME'],
+                'workspace' => $workspace
+            ]
         );
-        $databaseConnection->exec_INSERTquery('sys_log', $fields_values);
     }
 
     /**
@@ -157,13 +163,4 @@ abstract class AbstractExceptionHandler implements ExceptionHandlerInterface, \T
     {
         return $GLOBALS['BE_USER'];
     }
-
-    /**
-     * Gets the Database Object
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
 }
index 89f8426..24604b3 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Error;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
@@ -182,8 +183,9 @@ class ErrorHandler implements ErrorHandlerInterface
      */
     protected function writeLog($logMessage, $severity)
     {
-        $databaseConnection = $this->getDatabaseConnection();
-        if (is_object($databaseConnection) && $databaseConnection->isConnected()) {
+        $connection = GeneralUtility::makeInstance(ConnectionPool::class)
+            ->getConnectionForTable('sys_log');
+        if ($connection->isConnected()) {
             $userId = 0;
             $workspace = 0;
             $data = array();
@@ -199,19 +201,22 @@ class ErrorHandler implements ErrorHandlerInterface
                     $data['originalUser'] = $backendUser->user['ses_backuserid'];
                 }
             }
-            $fields_values = array(
-                'userid' => $userId,
-                'type' => 5,
-                'action' => 0,
-                'error' => $severity,
-                'details_nr' => 0,
-                'details' => str_replace('%', '%%', $logMessage),
-                'log_data' => (empty($data) ? '' : serialize($data)),
-                'IP' => (string)GeneralUtility::getIndpEnv('REMOTE_ADDR'),
-                'tstamp' => $GLOBALS['EXEC_TIME'],
-                'workspace' => $workspace
+
+            $connection->insert(
+                'sys_log',
+                [
+                    'userid' => $userId,
+                    'type' => 5,
+                    'action' => 0,
+                    'error' => $severity,
+                    'details_nr' => 0,
+                    'details' => str_replace('%', '%%', $logMessage),
+                    'log_data' => (empty($data) ? '' : serialize($data)),
+                    'IP' => (string)GeneralUtility::getIndpEnv('REMOTE_ADDR'),
+                    'tstamp' => $GLOBALS['EXEC_TIME'],
+                    'workspace' => $workspace
+                ]
             );
-            $databaseConnection->exec_INSERTquery('sys_log', $fields_values);
         }
     }
 
@@ -230,12 +235,4 @@ class ErrorHandler implements ErrorHandlerInterface
     {
         return $GLOBALS['BE_USER'];
     }
-
-    /**
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
 }