summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--classes/logger.php24
-rw-r--r--classes/logger/sql.php35
-rw-r--r--include/errorhandler.php50
-rw-r--r--include/functions.php15
-rw-r--r--include/sessions.php1
-rw-r--r--schema/ttrss_schema_mysql.sql13
-rw-r--r--schema/ttrss_schema_pgsql.sql13
-rw-r--r--schema/versions/mysql/118.sql16
-rw-r--r--schema/versions/pgsql/118.sql15
9 files changed, 177 insertions, 5 deletions
diff --git a/classes/logger.php b/classes/logger.php
new file mode 100644
index 000000000..6370e1425
--- /dev/null
+++ b/classes/logger.php
@@ -0,0 +1,24 @@
+<?php
+class Logger {
+
+ protected $errornames = array(
+ 2 => 'E_WARNING',
+ 8 => 'E_NOTICE',
+ 256 => 'E_USER_ERROR',
+ 512 => 'E_USER_WARNING',
+ 1024 => 'E_USER_NOTICE',
+ 2048 => 'E_STRICT',
+ 4096 => 'E_RECOVERABLE_ERROR',
+ 8192 => 'E_DEPRECATED',
+ 16384 => 'E_USER_DEPRECATED',
+ 32767 => 'E_ALL');
+
+ function log_error($errno, $errstr, $file, $line, $context) {
+ return false;
+ }
+
+ function log($string) {
+ return false;
+ }
+}
+?>
diff --git a/classes/logger/sql.php b/classes/logger/sql.php
new file mode 100644
index 000000000..7ee22844e
--- /dev/null
+++ b/classes/logger/sql.php
@@ -0,0 +1,35 @@
+<?php
+class Logger_SQL {
+
+ private $link;
+
+ function __construct() {
+ $this->link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
+ }
+
+ function log_error($errno, $errstr, $file, $line, $context) {
+
+ if ($errno == E_NOTICE) return false;
+
+ if ($this->link) {
+ $errno = db_escape_string($this->link, $errno);
+ $errstr = db_escape_string($this->link, $errstr);
+ $file = db_escape_string($this->link, $file);
+ $line = db_escape_string($this->link, $line);
+ $context = db_escape_string($this->link, json_encode($context));
+
+ $owner_uid = $_SESSION["uid"] ? $_SESSION["uid"] : "NULL";
+
+ $result = db_query($this->link,
+ "INSERT INTO ttrss_error_log
+ (errno, errstr, filename, lineno, context, owner_uid, created_at) VALUES
+ ($errno, '$errstr', '$file', '$line', '$context', $owner_uid, NOW())");
+
+ return db_affected_rows($this->link, $result) != 0;
+
+ }
+ return false;
+ }
+
+}
+?>
diff --git a/include/errorhandler.php b/include/errorhandler.php
new file mode 100644
index 000000000..13eed0e30
--- /dev/null
+++ b/include/errorhandler.php
@@ -0,0 +1,50 @@
+<?php
+// TODO: make configurable
+require_once "classes/logger.php";
+require_once "classes/logger/sql.php";
+
+function ttrss_error_handler($errno, $errstr, $file, $line, $context) {
+ global $logger;
+
+ if (!$logger) $logger = new Logger_SQL();
+
+ $errfile = str_replace(dirname(dirname(__FILE__)), "", $errfile);
+
+ if ($logger) {
+ return $logger->log_error($errno, $errstr, $file, $line, $context);
+ }
+
+ return false;
+}
+
+function ttrss_fatal_handler() {
+ global $logger;
+
+ $file = "UNKNOWN FILE";
+ $errstr = "UNKNOWN";
+ $errno = E_CORE_ERROR;
+ $line = -1;
+
+ $error = error_get_last();
+
+ if ($error !== NULL) {
+ $errno = $error["type"];
+ $file = $error["file"];
+ $line = $error["line"];
+ $errstr = $error["message"];
+
+ $context = debug_backtrace();
+
+ $file = str_replace(dirname(dirname(__FILE__)) . "/", "", $file);
+
+ if (!$logger) $logger = new Logger_SQL();
+
+ if ($logger) {
+ $logger->log_error($errno, $errstr, $file, $line, $context);
+ }
+ }
+}
+
+register_shutdown_function('ttrss_fatal_handler');
+set_error_handler('ttrss_error_handler');
+?>
diff --git a/include/functions.php b/include/functions.php
index 659950be0..621357ea6 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1,6 +1,6 @@
<?php
define('EXPECTED_CONFIG_VERSION', 26);
- define('SCHEMA_VERSION', 117);
+ define('SCHEMA_VERSION', 118);
define('LABEL_BASE_INDEX', -1024);
define('PLUGIN_FEED_BASE_INDEX', -128);
@@ -3369,9 +3369,8 @@
return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0;
}
- function init_connection($link) {
+ function init_connection_only($link) {
if ($link) {
-
if (DB_TYPE == "pgsql") {
pg_query($link, "set client_encoding = 'UTF-8'");
pg_set_client_encoding("UNICODE");
@@ -3385,6 +3384,16 @@
}
}
+ return true;
+ }
+
+ return false;
+ }
+
+ function init_connection($link) {
+ if ($link) {
+ init_connection_only($link);
+
global $pluginhost;
$pluginhost = new PluginHost($link);
diff --git a/include/sessions.php b/include/sessions.php
index 402e8b8de..bc8b7cff1 100644
--- a/include/sessions.php
+++ b/include/sessions.php
@@ -3,6 +3,7 @@
require_once "config.php";
require_once "db.php";
+ require_once "errorhandler.php";
require_once "lib/accept-to-gettext.php";
require_once "lib/gettext/gettext.inc";
require_once "version.php";
diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql
index 3773d9a45..0d0a8f460 100644
--- a/schema/ttrss_schema_mysql.sql
+++ b/schema/ttrss_schema_mysql.sql
@@ -1,6 +1,7 @@
SET NAMES utf8;
SET CHARACTER SET utf8;
+drop table if exists ttrss_error_log;
drop table if exists ttrss_plugin_storage;
drop table if exists ttrss_linked_feeds;
drop table if exists ttrss_linked_instances;
@@ -299,7 +300,7 @@ create table ttrss_tags (id integer primary key auto_increment,
create table ttrss_version (schema_version int not null) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
-insert into ttrss_version values (117);
+insert into ttrss_version values (118);
create table ttrss_enclosures (id integer primary key auto_increment,
content_url text not null,
@@ -478,5 +479,15 @@ create table ttrss_plugin_storage (
content longtext not null,
foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
+create table ttrss_error_log(
+ id integer not null auto_increment primary key,
+ owner_uid integer,
+ errno integer not null,
+ errstr text not null,
+ filename text not null,
+ lineno integer not null,
+ context text not null,
+ created_at datetime not null,
+ foreign key (owner_uid) references ttrss_users(id) ON DELETE SET NULL) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
commit;
diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql
index 3fc58555d..d81f65f2b 100644
--- a/schema/ttrss_schema_pgsql.sql
+++ b/schema/ttrss_schema_pgsql.sql
@@ -1,3 +1,4 @@
+drop table if exists ttrss_error_log;
drop table if exists ttrss_plugin_storage;
drop table if exists ttrss_linked_feeds;
drop table if exists ttrss_linked_instances;
@@ -257,7 +258,7 @@ create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id);
create table ttrss_version (schema_version int not null);
-insert into ttrss_version values (117);
+insert into ttrss_version values (118);
create table ttrss_enclosures (id serial not null primary key,
content_url text not null,
@@ -421,4 +422,14 @@ create table ttrss_plugin_storage (
owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
content text not null);
+create table ttrss_error_log(
+ id serial not null primary key,
+ owner_uid integer references ttrss_users(id) ON DELETE SET NULL,
+ errno integer not null,
+ errstr text not null,
+ filename text not null,
+ lineno integer not null,
+ context text not null,
+ created_at timestamp not null);
+
commit;
diff --git a/schema/versions/mysql/118.sql b/schema/versions/mysql/118.sql
new file mode 100644
index 000000000..add2b0c1f
--- /dev/null
+++ b/schema/versions/mysql/118.sql
@@ -0,0 +1,16 @@
+begin;
+
+create table ttrss_error_log(
+ id integer not null auto_increment primary key,
+ owner_uid integer,
+ errno integer not null,
+ errstr text not null,
+ filename text not null,
+ lineno integer not null,
+ context text not null,
+ created_at datetime not null,
+ foreign key (owner_uid) references ttrss_users(id) ON DELETE SET NULL) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
+
+update ttrss_version set schema_version = 118;
+
+commit;
diff --git a/schema/versions/pgsql/118.sql b/schema/versions/pgsql/118.sql
new file mode 100644
index 000000000..161cf4e3c
--- /dev/null
+++ b/schema/versions/pgsql/118.sql
@@ -0,0 +1,15 @@
+begin;
+
+create table ttrss_error_log(
+ id serial not null primary key,
+ owner_uid integer references ttrss_users(id) ON DELETE SET NULL,
+ errno integer not null,
+ errstr text not null,
+ filename text not null,
+ lineno integer not null,
+ context text not null,
+ created_at timestamp not null);
+
+update ttrss_version set schema_version = 118;
+
+commit;