]> git.wh0rd.org Git - tt-rss.git/commitdiff
reinstate error handlers; better DB error reporting on failed queries
authorAndrew Dolgov <fox@fakecake.org>
Wed, 17 Apr 2013 12:05:52 +0000 (16:05 +0400)
committerAndrew Dolgov <fox@fakecake.org>
Wed, 17 Apr 2013 12:05:54 +0000 (16:05 +0400)
classes/db.php
classes/db/mysql.php
classes/db/pgsql.php
classes/idb.php
classes/logger/sql.php
include/errorhandler.php

index 558d3e6b717b8a438ce494b115da7b3eb48e90a4..c3b6270962a30d44c7951d7d3251b0b73dcc9383 100644 (file)
@@ -13,11 +13,10 @@ class Db implements IDb {
                        $this->adapter = new Db_Pgsql();
                        break;
                default:
-                       user_error("Unknown DB_TYPE: " . DB_TYPE);
+                       die("Unknown DB_TYPE: " . DB_TYPE);
                }
 
                $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT);
-
        }
 
        private function __clone() {
@@ -35,10 +34,6 @@ class Db implements IDb {
                return("'$str'");
        }
 
-       function init() {
-               //
-       }
-
        function connect($host, $user, $pass, $db, $port) {
                //return $this->adapter->connect($host, $user, $pass, $db, $port);
                return $this->link;
index 64c35ebdcd1fba302337ca5996036a4731bee20a..241d2a063b42234a4b614528b5fc9c58690d4552 100644 (file)
@@ -25,10 +25,8 @@ class Db_Mysql implements IDb {
        function query($query, $die_on_error = true) {
                $result = mysql_query($query, $this->link);
                if (!$result) {
-                       $query = htmlspecialchars($query);
-                       if ($die_on_error) {
-                               die("Query <i>$query</i> failed: " . ($this->link ? mysql_error($link) : "No connection"));
-                       }
+                       user_error("Query $query failed: " . ($this->link ? mysql_error($this->link) : "No connection"),
+                               $die_on_error ? E_USER_ERROR : E_USER_WARNING);
                }
                return $result;
        }
index 0f38fb8cb5d124fd47cbcee815d89a4e6cf98d05..bafd54ab247a70856ece313bd234a5a3f0ccadb6 100644 (file)
@@ -39,9 +39,8 @@ class Db_Pgsql implements IDb {
 
                if (!$result) {
                        $query = htmlspecialchars($query); // just in case
-                       if ($die_on_error) {
-                               die("Query <i>$query</i> failed [$result]: " . ($this->link ? pg_last_error($this->link) : "No connection"));
-                       }
+                       user_error("Query $query failed: " . ($this->link ? pg_last_error($this->link) : "No connection"),
+                               $die_on_error ? E_USER_ERROR : E_USER_WARNING);
                }
                return $result;
        }
index 1ca6925b41ad23b748ce5737963b3fc0a4d3ff37..16f760bf6ade60d0d4bc41e4c4b67eb7111a8b1c 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 interface IDb {
        function connect($host, $user, $pass, $db, $port);
-       function init();
        function escape_string($s, $strip_tags = true);
        function query($query, $die_on_error = true);
        function fetch_assoc($result);
index c45841600e623061115b96b39142c23e86739d06..b0e0b0db5e1f05eac78112931c14715ad5049052 100644 (file)
@@ -6,6 +6,7 @@ class Logger_SQL {
                if ($errno == E_NOTICE) return false;
 
                if (Db::get()) {
+
                        $errno = Db::get()->escape_string($errno);
                        $errstr = Db::get()->escape_string($errstr);
                        $file = Db::get()->escape_string($file);
@@ -21,8 +22,8 @@ class Logger_SQL {
                                ($errno, '$errstr', '$file', '$line', '$context', $owner_uid, NOW())");
 
                        return Db::get()->affected_rows($result) != 0;
-
                }
+
                return false;
        }
 
index 45496b18bab04b475ae0b247dc6543ee66e39718..b1a0d3d0cfe2bb358f02cf8fbb22b8ea9f61be40 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 // TODO: make configurable
-//require_once "classes/logger.php";
-//require_once "classes/logger/sql.php";
+require_once "classes/logger.php";
+require_once "classes/logger/sql.php";
 
 function ttrss_error_handler($errno, $errstr, $file, $line, $context) {
        global $logger;
@@ -37,11 +37,16 @@ function ttrss_fatal_handler() {
                if (!$logger) $logger = new Logger_SQL();
 
                if ($logger) {
-                       $logger->log_error($errno, $errstr, $file, $line, $context);
+                       if ($logger->log_error($errno, $errstr, $file, $line, $context)) {
+                               return true;
+                       }
                }
+               return false;
        }
+
+       return false;
 }
 
-//register_shutdown_function('ttrss_fatal_handler');
-//set_error_handler('ttrss_error_handler');
+register_shutdown_function('ttrss_fatal_handler');
+set_error_handler('ttrss_error_handler');
 ?>