diff options
Diffstat (limited to 'classes/logger/sql.php')
-rwxr-xr-x | classes/logger/sql.php | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/classes/logger/sql.php b/classes/logger/sql.php index d21934aa6..784ebef31 100755 --- a/classes/logger/sql.php +++ b/classes/logger/sql.php @@ -3,12 +3,18 @@ class Logger_SQL implements Logger_Adapter { private $pdo; - function log_error(int $errno, string $errstr, string $file, int $line, $context) { + function __construct() { + $conn = get_class($this); - // separate PDO connection object is used for logging - if (!$this->pdo) $this->pdo = Db::instance()->pdo_connect(); + ORM::configure(Db::get_dsn(), null, $conn); + ORM::configure('username', Config::get(Config::DB_USER), $conn); + ORM::configure('password', Config::get(Config::DB_PASS), $conn); + ORM::configure('return_result_sets', true, $conn); + } - if ($this->pdo && get_schema_version() > 117) { + function log_error(int $errno, string $errstr, string $file, int $line, $context) { + + if (Config::get_schema_version() > 117) { // limit context length, DOMDocument dumps entire XML in here sometimes, which may be huge $context = mb_substr($context, 0, 8192); @@ -36,12 +42,19 @@ class Logger_SQL implements Logger_Adapter { // this would cause a PDOException on insert below $owner_uid = !empty($_SESSION["uid"]) ? $_SESSION["uid"] : null; - $sth = $this->pdo->prepare("INSERT INTO ttrss_error_log - (errno, errstr, filename, lineno, context, owner_uid, created_at) VALUES - (?, ?, ?, ?, ?, ?, NOW())"); - $sth->execute([$errno, $errstr, $file, (int)$line, $context, $owner_uid]); + $entry = ORM::for_table('ttrss_error_log', get_class($this))->create(); + + $entry->set([ + 'errno' => $errno, + 'errstr' => $errstr, + 'filename' => $file, + 'lineno' => (int)$line, + 'context' => $context, + 'owner_uid' => $owner_uid, + 'created_at' => Db::NOW(), + ]); - return $sth->rowCount(); + return $entry->save(); } return false; |