|
From: Benjamin C. <php...@be...> - 2005-03-10 13:31:34
|
A popup or an iframe could be used to log the queries, to keep it separate from the main output. Ulf Erikson wrote: > Hoi, > > There are two fairly new threads about failures with upgrading: > http://sourceforge.net/forum/message.php?msg_id=2664123 > http://sourceforge.net/forum/message.php?msg_id=3000998 > > Both reports indicate that upgrade.php doesn't change the database as > intended, and one of them that the problem is that v0.9 doesn't have a > DB_VERSION field. > > My first attempt would be to count the number of fields before querying > for the DB_VERSION. (just in case it is possible to have a setup that > throws an error or returns a big positive "value" when the field doesn't > exists) > > My next suggestion would be to log all queries and replies. That would > make it quite simple to spot any issues of this kind. You probably want > something similar for install.php. > > The alternative upgrade.php attached implements these two ideas. > Unfortunately is a full log a bit too much text.. Your comment about > manually changes needed for closed states gets a bit lost. Somewhat > better might be to show the log in a textarea but only if there has been > an error? Still I think a log would greatly help debugging this issue. > > Thoughts? Comments? > > > ------------------------------------------------------------------------ > > "; echo htmlentities($obj->message).' > '.htmlentities($obj->userinfo); echo "\n"; } function log_query($str) { > global $db; echo "\t\t\tSQL: " . $str . " > \n"; $result = $db->query($str); if (DB::isError($result)) { echo > "\t\t\t" . DB::errorMessage($result) . " > \n"; } echo "\t\t\t > \n"; } function upgrade() { global $db; echo "\n"; echo "\t\n"; echo > "\t\t\n"; echo "\t\t\n"; echo "\t\n"; echo "\t\n"; echo "\t\t > \n"; echo "\t\t\t > \n"; echo "\t\t\t".translate("Your database is being updated.")."\n"; > echo "\t\t\t > \n"; echo "\t\t\t > \n"; $db->setErrorHandling(PEAR_ERROR_CALLBACK, "handle_upgrade_error"); > $thisvers = 0; echo "\t\t\tSQL: select count(*) from ".TBL_CONFIGURATION." > \n"; $count = $db->getOne('select count(*) from '.TBL_CONFIGURATION); > echo "\t\t\tcount = $count > > \n"; if ($count > 30) { echo "\t\t\tSQL: select varvalue from > ".TBL_CONFIGURATION." where varname = 'DB_VERSION' > \n"; $thisvers = $db->getOne('select varvalue from '.TBL_CONFIGURATION.' > where varname = \'DB_VERSION\''); if (DB::isError($thisvers)) { echo > DB::errorMessage($thisvers) . " > "; $thisvers = 0; } } echo "\t\t\tCurrent DB version = $thisvers > \n"; echo "\t\t\tUpgrading to version = ".CUR_DB_VERSION." > \n"; echo "\t\t\t > \n"; if ($thisvers == CUR_DB_VERSION) $upgraded = 1; if (!$upgraded) { > switch(DB_TYPE) { case 'pgsql' : log_query("create table > ".TBL_PROJECT_PERM." ( project_id INT4 NOT NULL DEFAULT '0', user_id > INT4 NOT NULL DEFAULT '0' )"); if ($thisvers < 2) { 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) > { 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) { 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 'mysql' : 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) { log_query("alter > table ".TBL_AUTH_GROUP." ADD assignable TINYINT DEFAULT 0 NOT NULL AFTER > locked"); } if ($thisvers < 3) { log_query("ALTER TABLE > ".TBL_USER_PREF." ADD def_results INT DEFAULT '20' NOT NULL"); } if > ($thisvers < 4) { 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"; exit; log_query("create table > ".TBL_PROJECT_PERM." ( project_id number(10) default '0' NOT NULL, > user_id number(10) default '0' NOT NULL )"); //! TBL_AUTH_GROUP //! > TBL_USER_PERM.def_results (see mysql) break; } /** Database-independent > changes */ if ($thisvers < 2) { 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 */ log_query("INSERT > INTO ".TBL_CONFIGURATION." VALUES ('DB_VERSION', > '".(int)CUR_DB_VERSION."', 'Database Version *Warning:* Changing this > might make things go horribly wrong.', 'string')"); } if ($thisvers < 4) > { log_query('DELETE FROM '.TBL_CONFIGURATION.' WHERE varname = > \'BUG_CLOSED\''); echo "\t\t\tYou 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. > > \n"; log_query("INSERT INTO ".TBL_AUTH_PERM." (perm_id, perm_name) > VALUES (3, 'EditAssignment')"); } /* update to current DB_VERSION */ > log_query("UPDATE ".TBL_CONFIGURATION." SET varvalue = > '".CUR_DB_VERSION."' WHERE varname = 'DB_VERSION'"); echo "\t\t\t > \n"; echo "\t\t\t".translate("Done!")."\n"; echo "\t\t\t > \n"; } else { echo "\t\t\t > \n"; echo "\t\t\t".translate("Nothing to do.")."\n"; echo "\t\t\t > \n"; } echo "\t\t > \n"; echo "\t\t".translate("phpBugTracker home")." <\"index.php\">\n"; > echo "\t\t > \n"; echo "\t\n"; echo "\n"; } if (isset($_GET['doit'])) { upgrade(); } > else { include 'templates/default/upgrade.html'; } ?> |