From: Matteo Nastasi (mop) Date: Thu, 24 Feb 2011 07:59:19 +0000 (+0100) Subject: BriskDB and DBConn classes now have a static constructor method that can be failed X-Git-Tag: 3.4.0~1 X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=commitdiff_plain;h=a3111de89c89bb1a3a81e748592d26d85e4fd79d;p=brisk.git BriskDB and DBConn classes now have a static constructor method that can be failed --- diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index 34e08b0..480f3a2 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -1627,7 +1627,8 @@ class Room { $user->name = $name_new; // OK - nick changed /* se nome gia' in uso, segnala cosa potrebbe capitare */ if (($user->flags & USER_FLAG_AUTH) == 0) { - $bdb = new BriskDB(); + // FIXME: now create can return FALSE + $bdb = BriskDB::create(); $bdb->users_load(); /* MLANG: "Il nickname \'%s\' è già registrato, se il suo proprietario si autentificherà verrai rinominato d\'ufficio come ghostN." */ if ($bdb->login_exists($name_new)) { @@ -1905,9 +1906,11 @@ class Room { /* if pass != FALSE verify the login with pass */ log_auth("XXX", "auth1"); - $bdb = new BriskDB(); - $bdb->users_load(); - if ($pass != FALSE) { + + // FIXME: now create can return FALSE + if (($bdb = BriskDB::create()) != FALSE) + $bdb->users_load(); + if ($pass != FALSE && $bdb != FALSE) { // TODO: here add a method to $bdb to check if the db is available. log_auth("XXX", "auth2"); $authenticate = $bdb->login_verify($name_new, $pass, $code); log_auth("XXX", "authenticate: ".($authenticate != FALSE ? "TRUE" : "FALSE")); diff --git a/web/Obj/dbase_file.phh b/web/Obj/dbase_file.phh index 6801031..9e8331a 100644 --- a/web/Obj/dbase_file.phh +++ b/web/Obj/dbase_file.phh @@ -38,6 +38,13 @@ class BriskDB { log_main("BriskDB create:end"); } + static function &create() + { + $ret = new BriskDB(); + + return ($ret); + } + function users_load() { GLOBAL $DOCUMENT_ROOT; diff --git a/web/Obj/dbase_pgsql.phh b/web/Obj/dbase_pgsql.phh index a205b32..c3643bb 100644 --- a/web/Obj/dbase_pgsql.phh +++ b/web/Obj/dbase_pgsql.phh @@ -41,17 +41,24 @@ class DBConn function DBConn() { - GLOBAL $G_dbauth; + $this->db = DBConn::$dbcnnx; + } + + static function &create() + { + GLOBAL $G_dbauth, $G_false; + $ret = &$G_false; + if (DBConn::$dbcnnx == FALSE) { if (!(DBConn::$dbcnnx = @pg_connect ($G_dbauth))) { - echo "DB connection failed."; - exit; + return FALSE; } } - $this->db = DBConn::$dbcnnx; - return; + $ret = new DBConn(); + + return $ret; } function db() { @@ -65,14 +72,29 @@ class BriskDB var $item; var $item_n; - function BriskDB() + function BriskDB($dbconn) + { + $this->dbconn = $dbconn; + } + + static function &create() { GLOBAL $DOCUMENT_ROOT, $G_dbpfx, $G_false; + + $dbconn = $G_false; + $ret = $G_false; + log_main("BriskDB create:start"); - $this->dbconn = new DBConn(); + do { + if (($dbconn = DBConn::create()) == FALSE) + break; + + $ret = new BriskDB($dbconn); + } while (0); log_main("BriskDB create:end"); + return ($ret); } function users_load() diff --git a/web/admin.php b/web/admin.php index c36e475..7c87e1d 100644 --- a/web/admin.php +++ b/web/admin.php @@ -101,7 +101,9 @@ function main() $cont .= sprintf("Loading failed.
\n"); break; } - $newdb = new BriskDB(); + + // FIXME: now create can return FALSE + $newdb = BriskDB::create(); $newdb->users_load(); if ($newdb->addusers_from_olddb($olddb, $cont) == FALSE) { $cont .= sprintf("Insert failed.
\n"); @@ -123,7 +125,8 @@ function main() break; } - $newdb = new BriskDB(); + // FIXME: now create can return FALSE + $newdb = BriskDB::create(); $newdb->users_load(); $dbconn = $newdb->getdbconn(); for ($pts_n = 0 ; !feof($fp) ; $pts_n++) { diff --git a/web/briskin5/Obj/placing.phh b/web/briskin5/Obj/placing.phh index 31b97a3..5e1144a 100644 --- a/web/briskin5/Obj/placing.phh +++ b/web/briskin5/Obj/placing.phh @@ -142,7 +142,8 @@ function placing_time_file() function placing_time_pgsql() { GLOBAL $G_dbpfx; - $bdb = new BriskDB(); + // FIXME: now create can return FALSE + $bdb = BriskDB::create(); $mti_sql = sprintf("SELECT CAST(EXTRACT(EPOCH FROM mtime) AS INTEGER) as mtime FROM %sbin5_places_mtime WHERE code = 0;", $G_dbpfx); @@ -250,8 +251,9 @@ function placing_show_file(&$user, $ty, $subty) function placing_show_pgsql(&$user, $ty, $subty) { GLOBAL $G_dbpfx; - - $bdb = new BriskDB(); + + // FIXME: now create can return FALSE + $bdb = BriskDB::create(); if ($user != FALSE) { $pla_sql = sprintf("SELECT * from %sbin5_places where type = %d AND (rank <= %d OR ucode = '%s');", diff --git a/web/briskin5/index_wr.php b/web/briskin5/index_wr.php index 5045a54..6c27840 100644 --- a/web/briskin5/index_wr.php +++ b/web/briskin5/index_wr.php @@ -495,7 +495,8 @@ else if ($user->stat == 'table') { require_once("../Obj/dbase_".$G_dbasetype.".phh"); log_points($curtime, $user, "STAT:BRISKIN5:FINISH_GAME", $plist); - $bdb = new BriskDB(); + // FIXME: now create can return FALSE + $bdb = BriskDB::create(); $bdb->bin5_points_save($curtime, $table->table_token, $user->table_orig, $ucodes, $pt_cur); unset($bdb); } diff --git a/web/briskin5/statadm.php b/web/briskin5/statadm.php index 3c3e3e1..15fd27c 100644 --- a/web/briskin5/statadm.php +++ b/web/briskin5/statadm.php @@ -58,7 +58,8 @@ function main_file($curtime) fclose($fp_start); } - $bdb = new BriskDB(); + // FIXME: now create can return FALSE + $bdb = BriskDB::create(); $bdb->users_load(); for ($i = 0 ; $i < $bdb->count() ; $i++) { @@ -210,7 +211,8 @@ function main_pgsql($curtime) { GLOBAL $G_dbpfx; - $bdb = new BriskDB(); + // FIXME: now create can return FALSE + $bdb = BriskDB::create(); $limi = array( TRI_LIMIT, MON_LIMIT, WEE_LIMIT ); $ming = array( TRI_MIN_GAMES, MON_MIN_GAMES, WEE_MIN_GAMES ); diff --git a/web/index_wr.php b/web/index_wr.php index b030aff..8e20cd9 100644 --- a/web/index_wr.php +++ b/web/index_wr.php @@ -246,7 +246,8 @@ else if ($argz[0] == 'mesgtoadm') { log_wr("INFO:SKIP:argz == mesgtoadm name: [".$cli_name."] AUTH: ".($user->flags & USER_FLAG_AUTH)); if ($user->flags & USER_FLAG_AUTH) { if (($wa_lock = Warrant::lock_data()) != FALSE) { - $bdb = new BriskDB(); + // FIXME: now create can return FALSE + $bdb = BriskDB::create(); $bdb->users_load(); if (($ema = $bdb->getmail($user->name)) != FALSE) {