[TASK] Doctrine: Migrate error handlers
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Error / ErrorHandler.php
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'];
-    }
 }