Page MenuHomeIn-Portal Phabricator

D410.id1018.diff
No OneTemporary

File Metadata

Created
Wed, Feb 26, 8:58 AM

D410.id1018.diff

Index: core/kernel/utility/logger.php
===================================================================
--- core/kernel/utility/logger.php
+++ core/kernel/utility/logger.php
@@ -150,6 +150,13 @@
const LNS_SENT = 2;
/**
+ * Database connection used for logging.
+ *
+ * @var kDBConnection
+ */
+ protected $dbStorage;
+
+ /**
* List of error/exception handlers
*
* @var Array
@@ -221,6 +228,8 @@
{
parent::__construct();
+ $this->dbStorage = $this->getDBStorage();
+
$system_config = kUtil::getSystemConfig();
$this->_debugMode = $this->Application->isDebugMode();
@@ -241,6 +250,24 @@
}
/**
+ * Create separate connection for logging purposes.
+ *
+ * @return kDBConnection
+ */
+ protected function getDBStorage()
+ {
+ $system_config = new kSystemConfig(true);
+ $vars = $system_config->getData();
+ $db_class = $this->Application->isDebugMode() ? 'kDBConnectionDebug' : 'kDBConnection';
+
+ // Can't use "kApplication::makeClass", because class factory isn't initialized at this point.
+ $db = new $db_class(SQL_TYPE, array($this, 'handleSQLError'), 'logger');
+ $db->setup($vars);
+
+ return $db;
+ }
+
+ /**
* Sets state of the logged (enabled/user-only/disabled)
*
* @param $new_state
@@ -768,11 +795,11 @@
$this->_logRecord['LogDate'] = adodb_date('Y-m-d H:i:s');
if ( $storage_medium == self::LS_AUTOMATIC ) {
- $storage_medium = $this->Conn->connectionOpened() ? self::LS_DATABASE : self::LS_DISK;
+ $storage_medium = $this->dbStorage->connectionOpened() ? self::LS_DATABASE : self::LS_DISK;
}
if ( $storage_medium == self::LS_DATABASE ) {
- $result = $this->Conn->doInsert($this->_logRecord, TABLE_PREFIX . 'SystemLog');
+ $result = $this->dbStorage->doInsert($this->_logRecord, TABLE_PREFIX . 'SystemLog');
}
elseif ( $storage_medium == self::LS_DISK ) {
$result = $this->_saveToFile(RESTRICTED . '/system.log');
@@ -823,13 +850,13 @@
public function delete($unique_id, $storage_medium = self::LS_AUTOMATIC)
{
if ( $storage_medium == self::LS_AUTOMATIC ) {
- $storage_medium = $this->Conn->connectionOpened() ? self::LS_DATABASE : self::LS_DISK;
+ $storage_medium = $this->dbStorage->connectionOpened() ? self::LS_DATABASE : self::LS_DISK;
}
if ( $storage_medium == self::LS_DATABASE ) {
$sql = 'DELETE FROM ' . TABLE_PREFIX . 'SystemLog
WHERE LogUniqueId = ' . $unique_id;
- $this->Conn->Query($sql);
+ $this->dbStorage->Query($sql);
}
elseif ( $storage_medium == self::LS_DISK ) {
// TODO: no way to delete a line from a file

Event Timeline