|
From: Ulf E. <ulf...@us...> - 2005-05-31 18:50:28
|
Update of /cvsroot/phpbt/phpbt In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv819 Modified Files: upgrade.php Log Message: Logging of the upgrade process Index: upgrade.php =================================================================== RCS file: /cvsroot/phpbt/phpbt/upgrade.php,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- upgrade.php 30 May 2005 19:59:35 -0000 1.39 +++ upgrade.php 31 May 2005 18:50:18 -0000 1.40 @@ -23,89 +23,168 @@ // $Id$ define ('NO_AUTH', 1); +define ('RAWERROR', true); +define ('THEME', 'default'); $upgrading = true; @include 'include.php'; +$comment_text = ""; +$log_text = ""; +$num_errors = 0; + +// Handle a database error +function handle_upgrade_error(&$obj) { + global $log_text; + + $log_text .= "<div class=\"error\">"; + $log_text .= htmlentities($obj->message).'<br>'.htmlentities($obj->userinfo); + $log_text .= "</div>\n"; +} + +function log_query($str) { + global $db, $log_text, $num_errors; + + $log_text .= "SQL: " . $str . "<br>\n"; + $result = $db->query($str); + if (DB::isError($result)) { + $num_errors = $num_errors + 1; + } + $log_text .= "<br>\n"; +} + function upgrade() { - global $db; + global $db, $comment_text, $log_text, $num_errors; + + $thisvers = 0; + + $tmp_log = "Using the following information from config.php:<br>\n"; + $tmp_log .= "DB_TYPE: '".DB_TYPE."'<br>\n"; + $tmp_log .= "DB_HOST: '".DB_HOST."'<br>\n"; + $tmp_log .= "DB_DATABASE: '".DB_DATABASE."'<br>\n"; + $tmp_log .= "DB_USER: '".DB_USER."'<br>\n"; + $tmp_log .= "DB_PASSWORD: '".DB_PASSWORD."'<br>\n"; + $tmp_log .= "<br>\n"; + + $db->setErrorHandling(PEAR_ERROR_CALLBACK, "handle_upgrade_error"); + + $query = 'select count(*) from '.TBL_CONFIGURATION; + $tmp_log .= "SQL: ".$query."<br>\n"; + $count = $db->getOne($query); + if (DB::isError($count)) { + $tmp_log .= $log_text; + $log_text = ""; + $count = 0; + } + + $tmp_log .= "<p>count = ".$count."</p>\n"; + + if ($count > 30) { + $query = 'select varvalue from '.TBL_CONFIGURATION.' where varname = \'DB_VERSION\''; + $tmp_log .= "SQL: ".$query."<br>\n"; + $thisvers = $db->getOne($query); + if (DB::isError($thisvers)) { + $tmp_log .= $log_text; + $log_text = ""; + $thisvers = 0; + } + } + + $tmp_log .= "<p>DB_VERSION = ".$thisvers."</p>\n"; + + $comment_text .= "Current DB version = $thisvers<br>\n"; + $comment_text .= "Upgrading to version = ".CUR_DB_VERSION."<br>\n"; + $comment_text .= "<br>\n"; + + $log_text = $tmp_log; - $thisvers = $db->getOne('select varvalue from '.TBL_CONFIGURATION.' where varname = \'DB_VERSION\''); if ($thisvers == CUR_DB_VERSION) $upgraded = 1; - if (!$upgraded or DB::isError($thisvers)) { + if (!$upgraded) { switch(DB_TYPE) { case 'pgsql' : - $db->query("create table ".TBL_PROJECT_PERM." ( project_id INT4 NOT NULL DEFAULT '0', user_id INT4 NOT NULL DEFAULT '0' )"); + log_query("create table ".TBL_PROJECT_PERM." ( project_id INT4 NOT NULL DEFAULT '0', user_id INT4 NOT NULL DEFAULT '0' )"); if ($thisvers < 2) { - $db->query("alter table ".TBL_AUTH_GROUP." ADD assignable INT2"); - $db->query("alter table ".TBL_AUTH_GROUP." alter assignable set DEFAULT 0"); - $db->query("update ".TBL_AUTH_GROUP." set assignable = 0"); - $db->query("alter table ".TBL_AUTH_GROUP." alter assignable set NOT NULL"); + log_query("alter table ".TBL_AUTH_GROUP." ADD assignable INT2"); + log_query("alter table ".TBL_AUTH_GROUP." alter assignable set DEFAULT 0"); + log_query("update ".TBL_AUTH_GROUP." set assignable = 0"); + log_query("alter table ".TBL_AUTH_GROUP." alter assignable set NOT NULL"); } if ($thisvers < 3) { - $db->query("ALTER TABLE ".TBL_USER_PREF." ADD def_results INT4"); - $db->query("ALTER TABLE ".TBL_USER_PREF." alter def_results set DEFAULT 20"); - $db->query("update ".TBL_USER_PREF." set def_results = 20"); - $db->query("ALTER TABLE ".TBL_USER_PREF." alter def_results set NOT NULL"); + log_query("ALTER TABLE ".TBL_USER_PREF." ADD def_results INT4"); + log_query("ALTER TABLE ".TBL_USER_PREF." alter def_results set DEFAULT 20"); + log_query("update ".TBL_USER_PREF." set def_results = 20"); + log_query("ALTER TABLE ".TBL_USER_PREF." alter def_results set NOT NULL"); } if ($thisvers < 4) { - $db->query('ALTER TABLE '.TBL_STATUS.' ADD bug_open INT2'); - $db->query("ALTER TABLE ".TBL_STATUS." alter bug_open set DEFAULT 1"); - $db->query("update ".TBL_STATUS." set bug_open = 1"); - $db->query("ALTER TABLE ".TBL_STATUS." alter bug_open set NOT NULL"); + log_query('ALTER TABLE '.TBL_STATUS.' ADD bug_open INT2'); + log_query("ALTER TABLE ".TBL_STATUS." alter bug_open set DEFAULT 1"); + log_query("update ".TBL_STATUS." set bug_open = 1"); + log_query("ALTER TABLE ".TBL_STATUS." alter bug_open set NOT NULL"); } break; case 'mysqli' : case 'mysql' : - $db->query("create table if not exists ".TBL_PROJECT_PERM." ( project_id int(11) NOT NULL default '0', user_id int(11) NOT NULL default '0' )"); + log_query("create table if not exists ".TBL_PROJECT_PERM." ( project_id int(11) NOT NULL default '0', user_id int(11) NOT NULL default '0' )"); if ($thisvers < 2) { - $db->query("alter table ".TBL_AUTH_GROUP." ADD assignable TINYINT DEFAULT 0 NOT NULL AFTER locked"); + log_query("alter table ".TBL_AUTH_GROUP." ADD assignable TINYINT DEFAULT 0 NOT NULL AFTER locked"); } if ($thisvers < 3) { - $db->query("ALTER TABLE ".TBL_USER_PREF." ADD def_results INT DEFAULT '20' NOT NULL"); + log_query("ALTER TABLE ".TBL_USER_PREF." ADD def_results INT DEFAULT '20' NOT NULL"); } if ($thisvers < 4) { - $db->query('ALTER TABLE '.TBL_STATUS.' ADD bug_open TINYINT DEFAULT \'1\' NOT NULL'); + log_query('ALTER TABLE '.TBL_STATUS.' ADD bug_open TINYINT DEFAULT \'1\' NOT NULL'); } break; case 'oci8' : - echo "Oracle is not supported in version 1.0"; + if (true) { + $comment_text .= "<div class=\"error\">Oracle is not supported in version 1.0</div>"; - echo "<p>An attempt to restore Oracle support has been made (by copy-paste-and-edit), but it is completely UNTESTED! Proceed At Your Own Risk...</p>"; - echo "<p>Don't forget to report your success (or failure) story to <a href=\"mailto:php...@li...\">php...@li...</a> if you do proceed. We have interest in detailed error reports and patches from people who use Oracle.</p>"; - exit; + $comment_text .= "<p>An attempt to restore Oracle support has been made (by copy-paste-and-edit), but it is completely UNTESTED! Proceed At Your Own Risk...</p>"; + $comment_text .= "<p>Don't forget to report your success (or failure) story to <a href=\"mailto:php...@li...\">php...@li...</a> if you do proceed. We have interest in detailed error reports and patches from people who use Oracle.</p>"; + include 'templates/default/upgrade-finished.html'; + exit; + } - $db->query("create table ".TBL_PROJECT_PERM." ( project_id number(10) default '0' NOT NULL, user_id number(10) default '0' NOT NULL )"); + log_query("create table ".TBL_PROJECT_PERM." ( project_id number(10) default '0' NOT NULL, user_id number(10) default '0' NOT NULL )"); if ($thisvers < 2) { - $db->query("alter table ".TBL_AUTH_GROUP." ADD (assignable number(1) default '0' NOT NULL)"); + log_query("alter table ".TBL_AUTH_GROUP." ADD (assignable number(1) default '0' NOT NULL)"); } if ($thisvers < 3) { - $db->query("ALTER TABLE ".TBL_USER_PREF." ADD (def_results number(10) default '20' NOT NULL)"); + log_query("ALTER TABLE ".TBL_USER_PREF." ADD (def_results number(10) default '20' NOT NULL)"); } if ($thisvers < 4) { - $db->query("ALTER TABLE ".TBL_STATUS." ADD (bug_open number(1) default '1' NOT NULL)"); + log_query("ALTER TABLE ".TBL_STATUS." ADD (bug_open number(1) default '1' NOT NULL)"); } break; } /** Database-independent changes */ if ($thisvers < 2) { - $db->query("DELETE FROM ".TBL_CONFIGURATION." WHERE varname = 'GROUP_ASSIGN_TO'"); - $db->query("UPDATE ".TBL_AUTH_GROUP." SET assignable = 1 WHERE group_id = 3"); - $db->query("INSERT INTO ".TBL_CONFIGURATION." VALUES ('EMAIL_DISABLED', '0', 'Whether to disable all mail sent from the system', 'bool');"); + log_query("DELETE FROM ".TBL_CONFIGURATION." WHERE varname = 'GROUP_ASSIGN_TO'"); + log_query("UPDATE ".TBL_AUTH_GROUP." SET assignable = 1 WHERE group_id = 3"); + log_query("INSERT INTO ".TBL_CONFIGURATION." VALUES ('EMAIL_DISABLED', '0', 'Whether to disable all mail sent from the system', 'bool');"); /* add db-version attribute */ - $db->query("INSERT INTO ".TBL_CONFIGURATION." VALUES ('DB_VERSION', '".CUR_DB_VERSION."', 'Database Version <b>Warning:</b> Changing this might make things go horribly wrong.', 'string')"); + log_query("INSERT INTO ".TBL_CONFIGURATION." VALUES ('DB_VERSION', '".(int)CUR_DB_VERSION."', 'Database Version <b>Warning:</b> Changing this might make things go horribly wrong.', 'string')"); } if ($thisvers < 4) { - $db->query('DELETE FROM '.TBL_CONFIGURATION.' WHERE varname = \'BUG_CLOSED\''); - echo 'You must set your Statuses to either open or closed. Default settings should be modified so that "resolved", "closed", and "verified" are shown as being closed, and all other statuses are set to open.'; - $db->query("INSERT INTO ".TBL_AUTH_PERM." (perm_id, perm_name) VALUES (3, 'EditAssignment')"); + log_query('DELETE FROM '.TBL_CONFIGURATION.' WHERE varname = \'BUG_CLOSED\''); + $comment_text .= "You must set your Statuses to either open or closed. Default settings should be modified so that \"resolved\", \"closed\", and \"verified\" are shown as being closed, and all other statuses are set to open.<br><br>\n"; + log_query("INSERT INTO ".TBL_AUTH_PERM." (perm_id, perm_name) VALUES (3, 'EditAssignment')"); } /* update to current DB_VERSION */ - $db->query("UPDATE ".TBL_CONFIGURATION." SET varvalue = '".CUR_DB_VERSION."' WHERE varname = 'DB_VERSION'"); - + log_query("UPDATE ".TBL_CONFIGURATION." SET varvalue = '".CUR_DB_VERSION."' WHERE varname = 'DB_VERSION'"); + if ($num_errors == 0) { + $comment_text .= "Success!<br>\n"; + } + else { + $comment_text .= "Done, but with ".$num_errors." error(s)<br>\n"; + } } + else { + $comment_text .= "Nothing to do...<br>\n"; + } + include 'templates/default/upgrade-finished.html'; } |