From 0b11a548dc6635b0b293c188d22fe4141041c2de Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 17 Apr 2009 02:08:05 +0000 Subject: [PATCH] - upgrade script: do DB update even if stop_web is present, rather than spewing an HTML error message. Fixes #875 svn path=/trunk/boinc/; revision=17839 --- checkin_notes | 17 +++++++++++++- html/inc/boinc_db.inc | 50 +++++++++++++++++++++++++++--------------- html/inc/util.inc | 2 +- html/ops/db_update.php | 2 +- html/user/apps.php | 2 +- 5 files changed, 51 insertions(+), 22 deletions(-) diff --git a/checkin_notes b/checkin_notes index e1cee3133f..152476f5a4 100644 --- a/checkin_notes +++ b/checkin_notes @@ -3952,7 +3952,7 @@ David 15 Apr 2009 samples/example_app/ uc2.cpp -Davaid 16 Apr 2009 +David 16 Apr 2009 - client: another try at fixing the above crash - web: don't show plan class in separate column in apps list; fixes #874 @@ -3960,3 +3960,18 @@ Davaid 16 Apr 2009 app_control.cpp html/user/ apps.php + +David 16 Apr 2009 + - upgrade script: do DB update even if stop_web is present, + rather than spewing an HTML error message. + Fixes #875 + + html/ + inc/ + boinc_db.inc + util.inc + ops/ + db_update.php + user/ + apps.php + diff --git a/html/inc/boinc_db.inc b/html/inc/boinc_db.inc index 7e090ae33d..5d5e1558cc 100644 --- a/html/inc/boinc_db.inc +++ b/html/inc/boinc_db.inc @@ -22,33 +22,47 @@ require_once("../inc/util_basic.inc"); class BoincDb extends DbConn { static $instance; + // connect to the database (possibly to a read-only replica) + // + static function get_aux($readonly) { + $config = get_config(); + $user = parse_config($config, ''); + $passwd = parse_config($config, ''); + $host = parse_config($config, ''); + $replica_host = parse_config($config, ''); + $name = parse_config($config, ''); + if ($host == null) { + $host = "localhost"; + } + $instance = new DbConn(); + if ($readonly && $replica_host) { + $retval = $instance->init_conn($user, $passwd, $replica_host, $name); + if ($retval) return $instance; + } + $retval = $instance->init_conn($user, $passwd, $host, $name); + if (!$retval) { + $instance = null; + } + self::$instance = $instance; + } + + // same, but + // 1) check for a cached connection + // 2) check whether the "stop_web" trigger file is present + // static function get($readonly = false) { - if (!isset($instance)) { + if (!isset(self::$instance)) { if (web_stopped()) { show_page("Project down for maintenence", "Please check back in a few hours." ); exit; } - $config = get_config(); - $user = parse_config($config, ''); - $passwd = parse_config($config, ''); - $host = parse_config($config, ''); - $replica_host = parse_config($config, ''); - $name = parse_config($config, ''); - if ($host == null) { - $host = "localhost"; - } - $instance = new DbConn(); - if ($readonly && $replica_host) { - $retval = $instance->init_conn($user, $passwd, $replica_host, $name); - if ($retval) return $instance; - } - $retval = $instance->init_conn($user, $passwd, $host, $name); - if (!$retval) return null; + self::get_aux($readonly); } - return $instance; + return self::$instance; } + static function escape_string($string) { $db = self::get(); return parent::base_escape_string(trim($string)); diff --git a/html/inc/util.inc b/html/inc/util.inc index 3a9c3daa9d..91a224d9a7 100644 --- a/html/inc/util.inc +++ b/html/inc/util.inc @@ -739,7 +739,7 @@ function check_web_stopped() { // Connects to database server and selects database as noted in config.xml // If only read-only access is necessary, // tries instead to connect to if tag exists. -// DEPRECATED - use boinc_db.h +// DEPRECATED - use boinc_db.inc // function db_init($try_replica=false) { check_web_stopped(); diff --git a/html/ops/db_update.php b/html/ops/db_update.php index c8b97037f6..867a5f8d23 100755 --- a/html/ops/db_update.php +++ b/html/ops/db_update.php @@ -25,7 +25,7 @@ require_once("../inc/util.inc"); require_once("../inc/ops.inc"); cli_only(); -db_init(); +BoincDb::get_aux(false); set_time_limit(0); diff --git a/html/user/apps.php b/html/user/apps.php index e77da6a974..cba446261d 100644 --- a/html/user/apps.php +++ b/html/user/apps.php @@ -22,7 +22,7 @@ require_once("../inc/translation.inc"); $platforms = BoincPlatform::enum("deprecated=0"); -$xml = $_GET['xml']; +$xml = get_str('xml', true); if ($xml) { require_once('../inc/xml.inc'); xml_header();