From ba68b6815ab31d17cda113e7990eeb07558b02a9 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 17 Apr 2013 14:23:35 +0400 Subject: [PATCH] db updates, remove init_connection() --- api/index.php | 2 +- backend.php | 2 +- classes/db.php | 5 +++++ classes/db/mysql.php | 10 ++++++++++ classes/db/pgsql.php | 8 ++++++++ classes/idb.php | 1 + include/functions.php | 38 +++++--------------------------------- index.php | 2 +- opml.php | 2 +- plugins/mobile/article.php | 2 +- plugins/mobile/backend.php | 2 +- plugins/mobile/cat.php | 2 +- plugins/mobile/feed.php | 2 +- plugins/mobile/home.php | 2 +- plugins/mobile/index.php | 2 +- plugins/mobile/prefs.php | 2 +- prefs.php | 2 +- public.php | 2 +- register.php | 2 +- update.php | 2 +- update_daemon2.php | 6 +++--- 21 files changed, 47 insertions(+), 51 deletions(-) diff --git a/api/index.php b/api/index.php index 53b78b010..823b9527e 100644 --- a/api/index.php +++ b/api/index.php @@ -54,7 +54,7 @@ @session_start(); } - if (!init_connection($link)) return; + if (!init_plugins($link)) return; $method = strtolower($_REQUEST["op"]); diff --git a/backend.php b/backend.php index 6ee0e081f..40e40aeb3 100644 --- a/backend.php +++ b/backend.php @@ -49,7 +49,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) return; + if (!init_plugins($link)) return; header("Content-Type: text/json; charset=utf-8"); diff --git a/classes/db.php b/classes/db.php index 403cbc93a..71fc01ae1 100644 --- a/classes/db.php +++ b/classes/db.php @@ -16,6 +16,7 @@ class Db implements IDb { } $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT); + $this->adapter->init(); } private function __clone() { @@ -33,6 +34,10 @@ class Db implements IDb { return("'$str'"); } + function init() { + // + } + function connect($host, $user, $pass, $db, $port) { //return $this->adapter->connect($host, $user, $pass, $db, $port); } diff --git a/classes/db/mysql.php b/classes/db/mysql.php index 512ea3894..fa97dcff1 100644 --- a/classes/db/mysql.php +++ b/classes/db/mysql.php @@ -55,5 +55,15 @@ class Db_Mysql implements IDb { return mysql_affected_rows($this->link); } + function init() { + $this->query("SET time_zone = '+0:0'"); + + if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { + $this->query("SET NAMES " . MYSQL_CHARSET); + } + + return true; + } + } ?> diff --git a/classes/db/pgsql.php b/classes/db/pgsql.php index 87c2abefd..c9ec33887 100644 --- a/classes/db/pgsql.php +++ b/classes/db/pgsql.php @@ -69,5 +69,13 @@ class Db_Pgsql implements IDb { return pg_last_error($this->link); } + function init() { + $this->query("set client_encoding = 'UTF-8'"); + pg_set_client_encoding("UNICODE"); + $this->query("set datestyle = 'ISO, european'"); + $this->query("set TIME ZONE 0"); + + return true; + } } ?> diff --git a/classes/idb.php b/classes/idb.php index 16f760bf6..1ca6925b4 100644 --- a/classes/idb.php +++ b/classes/idb.php @@ -1,6 +1,7 @@ 0; } - function init_connection_only($link) { - if ($link) { - if (DB_TYPE == "pgsql") { - pg_query($link, "set client_encoding = 'UTF-8'"); - pg_set_client_encoding("UNICODE"); - pg_query($link, "set datestyle = 'ISO, european'"); - pg_query($link, "set TIME ZONE 0"); - } else { - db_query($link, "SET time_zone = '+0:0'"); + function init_plugins($link) { + global $pluginhost; - if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { - db_query($link, "SET NAMES " . MYSQL_CHARSET); - } - } + $pluginhost = new PluginHost($link); + $pluginhost->load(PLUGINS, $pluginhost::KIND_ALL); - return true; - } - - return false; - } - - function init_connection($link) { - if ($link) { - init_connection_only($link); - - global $pluginhost; - - $pluginhost = new PluginHost($link); - $pluginhost->load(PLUGINS, $pluginhost::KIND_ALL); - - return true; - } else { - print "Unable to connect to database:" . db_last_error(); - return false; - } + return true; } function format_tags_string($tags, $id) { diff --git a/index.php b/index.php index 066b25fa5..c21b46809 100644 --- a/index.php +++ b/index.php @@ -31,7 +31,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) return; + if (!init_plugins($link)) return; global $pluginhost; diff --git a/opml.php b/opml.php index b8c9fb6c5..ad866fbd5 100644 --- a/opml.php +++ b/opml.php @@ -11,7 +11,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) return; + if (!init_plugins($link)) return; $op = $_REQUEST['op']; diff --git a/plugins/mobile/article.php b/plugins/mobile/article.php index f6aed994f..c73c0fca5 100644 --- a/plugins/mobile/article.php +++ b/plugins/mobile/article.php @@ -18,7 +18,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - init_connection($link); + init_plugins($link); login_sequence($link, true); diff --git a/plugins/mobile/backend.php b/plugins/mobile/backend.php index a88e02a92..dc657ed40 100644 --- a/plugins/mobile/backend.php +++ b/plugins/mobile/backend.php @@ -23,7 +23,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - init_connection($link); + init_plugins($link); if (!$_SESSION["uid"]) return; diff --git a/plugins/mobile/cat.php b/plugins/mobile/cat.php index 7b5cf43f9..acd7f6f34 100644 --- a/plugins/mobile/cat.php +++ b/plugins/mobile/cat.php @@ -18,7 +18,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - init_connection($link); + init_plugins($link); login_sequence($link, true); diff --git a/plugins/mobile/feed.php b/plugins/mobile/feed.php index 6eae741ac..22590f195 100644 --- a/plugins/mobile/feed.php +++ b/plugins/mobile/feed.php @@ -18,7 +18,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - init_connection($link); + init_plugins($link); login_sequence($link, true); diff --git a/plugins/mobile/home.php b/plugins/mobile/home.php index 03fccb3e2..f0ebf6a11 100644 --- a/plugins/mobile/home.php +++ b/plugins/mobile/home.php @@ -18,7 +18,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - init_connection($link); + init_plugins($link); login_sequence($link, true); diff --git a/plugins/mobile/index.php b/plugins/mobile/index.php index 3feec7531..3fd496d04 100644 --- a/plugins/mobile/index.php +++ b/plugins/mobile/index.php @@ -18,7 +18,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - init_connection($link); + init_plugins($link); login_sequence($link, true); ?> diff --git a/plugins/mobile/prefs.php b/plugins/mobile/prefs.php index 323196254..e6d4a7b40 100644 --- a/plugins/mobile/prefs.php +++ b/plugins/mobile/prefs.php @@ -20,7 +20,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - init_connection($link); + init_plugins($link); login_sequence($link, true); ?> diff --git a/prefs.php b/prefs.php index e3b62da70..046d5eb76 100644 --- a/prefs.php +++ b/prefs.php @@ -21,7 +21,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) return; + if (!init_plugins($link)) return; login_sequence($link); diff --git a/public.php b/public.php index 8477f95fc..1a50538fb 100644 --- a/public.php +++ b/public.php @@ -30,7 +30,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) return; + if (!init_plugins($link)) return; if (ENABLE_GZIP_OUTPUT && function_exists("ob_gzhandler")) { ob_start("ob_gzhandler"); diff --git a/register.php b/register.php index 53627d912..9aec6dde7 100644 --- a/register.php +++ b/register.php @@ -19,7 +19,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) return; + if (!init_plugins($link)) return; if ($_REQUEST["format"] == "feed") { header("Content-Type: text/xml"); diff --git a/update.php b/update.php index 1c43cdb94..ffe54cc7c 100755 --- a/update.php +++ b/update.php @@ -21,7 +21,7 @@ // Create a database connection. $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - init_connection($link); + init_plugins($link); $longopts = array("feeds", "feedbrowser", diff --git a/update_daemon2.php b/update_daemon2.php index 77d05be66..e8a56eec9 100755 --- a/update_daemon2.php +++ b/update_daemon2.php @@ -177,7 +177,7 @@ // It is unnecessary to start the fork loop if database is not ok. $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) die("Can't initialize db connection.\n"); + if (!init_plugins($link)) die("Can't initialize db connection.\n"); $schema_version = get_schema_version($link); @@ -203,7 +203,7 @@ /* Check if schema version changed */ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) die("Can't initialize db connection.\n"); + if (!init_plugins($link)) die("Can't initialize db connection.\n"); $test_schema_version = get_schema_version($link); db_close($link); @@ -255,7 +255,7 @@ $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - if (!init_connection($link)) return; + if (!init_plugins($link)) return; // We disable stamp file, since it is of no use in a multiprocess update. // not really, tho for the time being -fox