From: Glenn H. <thr...@us...> - 2005-07-14 21:38:10
|
Update of /cvsroot/mantisbt/mantisbt/admin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21513/admin Modified Files: db_table_names_inc.php install.php upgrade.php upgrade_inc.php Log Message: Completed linking new installer into main pages - no config file will redirect to installer - checks on login_page for out of date database Rearranged admin/upgrade.php and upgrade_inc.php to support out of date check Index: upgrade_inc.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/admin/upgrade_inc.php,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- upgrade_inc.php 2 Jul 2005 00:56:04 -0000 1.16 +++ upgrade_inc.php 14 Jul 2005 21:38:00 -0000 1.17 @@ -8,38 +8,8 @@ # -------------------------------------------------------- # $Id$ # -------------------------------------------------------- -?> -<?php - $g_skip_open_db = true; # don't open the database in database_api.php - require_once ( dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'core.php' ); -$g_error_send_page_header = false; - require_once( 'db_table_names_inc.php' ); - $result = @db_connect( config_get_global( 'hostname' ), config_get_global( 'db_username' ), config_get_global( 'db_password' ), config_get_global( 'database_name' ) ); - if ( false == $result ) { -?> -<html> -<head> -<title> Mantis Administration - Upgrade Installation </title> -<link rel="stylesheet" type="text/css" href="admin.css" /> -</head> -<body> -<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff"> - <tr class="top-bar"> - <td class="links"> - [ <a href="index.php">Back to Administration</a> ] - </td> - <td class="title"> - Upgrade Installation - </td> - </tr> -</table> -<br /><br /> -<p>Opening connection to database [<?php echo config_get_global( 'database_name' ) ?>] on host [<?php echo config_get_global( 'hostname' ) ?>] with username [<?php echo config_get_global( 'db_username' ) ?>] failed.</p> -</body> -<?php - exit(); - } + require_once( 'db_table_names_inc.php' ); # Compatibility function # @@ -52,45 +22,13 @@ $result = db_query( "DESCRIBE $c_table_name $c_field_name" ); - if ( $result && db_num_rows($result) ) { + if ( $result && ( 0 < db_num_rows( $result ) ) ) { return true; } else { return false; } } - # -------------------- - # Returns true if the current PHP version is higher than the one - # specified in the given string - function db_version_at_least( $p_version_string ) { - global $g_cached_db_version; - - if ( isset( $g_cached_db_version[$p_version_string] ) ) { - return $g_cached_db_version[$p_version_string]; - } - - $t_curver = array_pad( explode( '.', config_get( 'database_version', '0.0.0' ) ), 3, 0 ); - $t_minver = array_pad( explode( '.', $p_version_string ), 3, 0 ); - - for ($i = 0 ; $i < 3 ; $i = $i + 1 ) { - $t_cur = (int)$t_curver[$i]; - $t_min = (int)$t_minver[$i]; - - if ( $t_cur < $t_min ) { - $g_cached_db_version[$p_version_string] = false; - return false; - } else if ( $t_cur > $t_min ) { - $g_cached_db_version[$p_version_string] = true; - return true; - } - } - - # if we get here, the versions must match exactly so: - $g_cached_db_version[$p_version_string] = true; - return true; - } - - ?> <?php class Upgrade { @@ -243,15 +181,14 @@ } # add items, and check if they can be marked as completed - function add_items_with_check( $p_upgrade_file, $p_table_check='', $p_version_check='0.0.0' ) { + function add_items_with_check( $p_upgrade_file, $p_table_check='' ) { $t_start_count = $this->count_items(); $this->add_items( include( $p_upgrade_file ) ); $t_end_count = $this->count_items(); # check for table presence and db version and mark as applied if either the table # is present, or our version stamp is lower than the actual db - if ( ( ( $p_table_check != '' ) && admin_check_applied( $p_table_check ) ) || - ( db_version_at_least( $p_version_check ) ) ) { + if ( ( ( $p_table_check != '' ) && admin_check_applied( $p_table_check ) ) ) { for ( $i = $t_start_count; $i < $t_end_count; $i++ ) { if ( ! $this->is_applied( $i ) ) { $this->set_applied( $i ); @@ -431,4 +368,19 @@ } } } + + $upgrade_set = new UpgradeSet(); + + $upgrade_set->add_items_with_check( 'upgrades/0_13_inc.php', $t_project_table ); + $upgrade_set->add_items_with_check( 'upgrades/0_14_inc.php', $t_bug_file_table ); + $upgrade_set->add_items_with_check( 'upgrades/0_15_inc.php', $t_bug_history_table ); + $upgrade_set->add_items_with_check( 'upgrades/0_16_inc.php', $t_bug_monitor_table ); + + # this upgrade process was introduced in 0.17.x, so beyond here, the + # process of checking the upgrade_table to see if updates are applied should work + $upgrade_set->add_items_with_check( 'upgrades/0_17_inc.php', '', '0.17.0' ); + $upgrade_set->add_items_with_check( 'upgrades/0_18_inc.php', '', '0.18.0' ); + $upgrade_set->add_items_with_check( 'upgrades/0_19_inc.php', '', '0.19.0' ); + $upgrade_set->add_items_with_check( 'upgrades/1_00_inc.php', '', '1.0.0' ); + ?> Index: db_table_names_inc.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/admin/db_table_names_inc.php,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- db_table_names_inc.php 28 Feb 2005 14:42:52 -0000 1.7 +++ db_table_names_inc.php 14 Jul 2005 21:38:00 -0000 1.8 @@ -1,5 +1,13 @@ <?php - require_once( '../core.php' ); + # Mantis - a php based bugtracking system + # Copyright (C) 2000 - 2002 Kenzaburo Ito - ke...@30... + # Copyright (C) 2002 - 2004 Mantis Team - man...@li... + # This program is distributed under the terms and conditions of the GPL + # See the README and LICENSE files for details + + # -------------------------------------------------------- + # $Id$ + # -------------------------------------------------------- # Load all the table names for use by the upgrade statements $t_bug_file_table = config_get_global( 'mantis_bug_file_table' ); Index: install.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/admin/install.php,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- install.php 5 Jul 2005 23:48:49 -0000 1.4 +++ install.php 14 Jul 2005 21:38:00 -0000 1.5 @@ -75,11 +75,11 @@ $t_install_state = gpc_get_int( 'install', 0 ); # read control variables with defaults - $f_hostname = gpc_get('hostname', 'localhost'); - $f_db_type = gpc_get('db_type', ''); - $f_database_name = gpc_get('database_name', 'bugtrack'); - $f_db_username = gpc_get('db_username', ''); - $f_db_password = gpc_get('db_password', ''); + $f_hostname = gpc_get( 'hostname', config_get( 'hostname', 'localhost' ) ); + $f_db_type = gpc_get( 'db_type', config_get( 'db_type', '' ) ); + $f_database_name = gpc_get( 'database_name', config_get( 'database_name', 'bugtrack') ); + $f_db_username = gpc_get( 'db_username', config_get( 'db_username', '' ) ); + $f_db_password = gpc_get( 'db_password', config_get( 'db_password', '' ) ); $f_admin_username = gpc_get( 'admin_username', '' ); $f_admin_password = gpc_get( 'admin_password', ''); ?> @@ -266,7 +266,7 @@ ?> </tr> <?php - if ( $t_database_exists ) { + if ( $t_db_exists ) { ?> <tr> <td bgcolor="#ffffff"> @@ -445,7 +445,8 @@ $t_result = @$g_db->Connect( $f_hostname, $f_admin_username, $f_admin_password, $f_database_name ); $g_db_connected = true; # fake out database access routines $t_last_update = config_get( 'database_version', 0 ); - $lastid = sizeof( $upgrade ); + $lastid = sizeof( $upgrade ) - 1; + var_dump($lastid); $i = $t_last_update; while ( ( $i < $lastid ) && ! $g_failed ) { ?> @@ -469,9 +470,12 @@ } echo '</tr>'; $i++; +var_dump($i); } } - + if ( false == $g_failed ) { + $t_install_state++; + } ?> </table> @@ -498,6 +502,7 @@ # all checks have passed, install the database if ( 5 == $t_install_state ) { +echo 'wcf'; ?> <table width="100%" border="0" cellpadding="10" cellspacing="1"> <tr> @@ -531,9 +536,17 @@ print_test_result( BAD, false, 'cannot write ' . $g_absolute_path . 'config_inc.php' ); } } else { - // already exists - print_test_result( BAD, false, 'file ' . $g_absolute_path . 'config_inc.php' . ' already exists' ); - + # already exists, see if the information is the same + if ( ( $f_hostname != config_get( 'hostname', '' ) ) || + ( $f_db_type != config_get( 'db_type', '' ) ) || + ( $f_database_name != config_get( 'database_name', '') ) || + ( $f_db_username != config_get( 'db_username', '' ) ) || + ( $f_db_password != config_get( 'db_password', '' ) ) ) { + print_test_result( BAD, false, 'file ' . $g_absolute_path . 'config_inc.php' . ' already exists and has different settings' ); + } else { + print_test_result( GOOD, false, 'file not updated' ); + $t_write_failed = false; + } } ?> </tr> Index: upgrade.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/admin/upgrade.php,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- upgrade.php 2 Jul 2005 00:56:04 -0000 1.8 +++ upgrade.php 14 Jul 2005 21:38:00 -0000 1.9 @@ -10,41 +10,20 @@ # -------------------------------------------------------- ?> <?php - require_once ( 'upgrade_inc.php' ); - - if ( ! db_table_exists( $t_upgrade_table ) ) { - # Create the upgrade table if it does not exist - $query = "CREATE TABLE IF NOT EXISTS $t_upgrade_table - (upgrade_id char(20) NOT NULL, - description char(255) NOT NULL, - PRIMARY KEY (upgrade_id))"; - - $result = db_query( $query ); - } - - $upgrade_set = new UpgradeSet(); - - $upgrade_set->add_items_with_check( 'upgrades/0_13_inc.php', $t_project_table ); - $upgrade_set->add_items_with_check( 'upgrades/0_14_inc.php', $t_bug_file_table ); - $upgrade_set->add_items_with_check( 'upgrades/0_15_inc.php', $t_bug_history_table ); - $upgrade_set->add_items_with_check( 'upgrades/0_16_inc.php', $t_bug_monitor_table ); + $g_skip_open_db = true; # don't open the database in database_api.php + require_once ( dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'core.php' ); + $g_error_send_page_header = false; # suppress page headers in the error handler - # this upgrade process was introduced in 0.17.x, so beyond here, the - # process of checking the upgrade_table to see if updates are applied should work - $upgrade_set->add_items_with_check( 'upgrades/0_17_inc.php', '', '0.17.0' ); - $upgrade_set->add_items_with_check( 'upgrades/0_18_inc.php', '', '0.18.0' ); - $upgrade_set->add_items_with_check( 'upgrades/0_19_inc.php', '', '0.19.0' ); - $upgrade_set->add_items_with_check( 'upgrades/1_00_inc.php', '', '1.0.0' ); - + # @@@ upgrade list moved to the bottom of upgrade_inc.php + $f_advanced = gpc_get_bool( 'advanced', false ); ?> <html> <head> -<title> Mantis Administration - Database Upgrade </title> +<title> Mantis Administration - Upgrade Installation </title> <link rel="stylesheet" type="text/css" href="admin.css" /> </head> <body> - <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff"> <tr class="top-bar"> <td class="links"> @@ -58,8 +37,30 @@ </tr> </table> <br /><br /> +<?php + $result = @db_connect( config_get_global( 'hostname' ), config_get_global( 'db_username' ), config_get_global( 'db_password' ), config_get_global( 'database_name' ) ); + if ( false == $result ) { +?> +<p>Opening connection to database [<?php echo config_get_global( 'database_name' ) ?>] on host [<?php echo config_get_global( 'hostname' ) ?>] with username [<?php echo config_get_global( 'db_username' ) ?>] failed.</p> +</body> <?php + exit(); + } + + if ( ! db_table_exists( config_get( 'mantis_upgrade_table' ) ) ) { + # Create the upgrade table if it does not exist + $query = "CREATE TABLE IF NOT EXISTS" . config_get( 'mantis_upgrade_table' ) . + "(upgrade_id char(20) NOT NULL, + description char(255) NOT NULL, + PRIMARY KEY (upgrade_id))"; + + $result = db_query( $query ); + } + + # link the data structures and upgrade list + require_once ( 'upgrade_inc.php' ); + $upgrade_set->process_post_data( $f_advanced ); ?> </body> |