Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Fixed a warning where $f_private was used without being defined when
adding a public bug note. 2. Improved the admin_upgrade.php + enhanced the upgrade class to support generation of SQL files, fancy printing, and facy printing + execution. From now on, when we change the db format (till v0.18.0), we should change the file admin_upgrade_0_18_0 and add the new SQL. Before releasing we can update the db_upgrade.sql if we want using the SQL generation feature. git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@1089 f5dc347c-c33d-0410-90a0-b07cc1902cb9
- Loading branch information
Showing
4 changed files
with
142 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
require_once ( 'admin_upgrade_inc.php' ); | ||
|
||
$upgrade_obj = new UpgradeItem(); | ||
$upgrade_obj->SetUpgradeName ( 'Upgrade from 0.17.x to 0.18.x', 'admin_upgrade_0_18_0' ); | ||
|
||
# START OF UPGRADE SQL STATEMENTS | ||
# --- LATEST CHANGES SHOULD GO AT THE BOTTOM --- | ||
|
||
$upgrade_obj->AddItem( "# Bug history" ); | ||
$upgrade_obj->AddItem( "ALTER TABLE mantis_bug_history_table ADD type INT(2) NOT NULL" ); | ||
$upgrade_obj->AddItem(); | ||
|
||
$upgrade_obj->AddItem( "# Auto-assigning of bugs for a default user per category" ); | ||
$upgrade_obj->AddItem( "ALTER TABLE mantis_bug_history_table ADD type INT(2) NOT NULL" ); | ||
|
||
# END OF UPGRADE SQL STATEMENTS | ||
|
||
if ( !isset ( $f_action ) ) { | ||
$upgrade_obj->PrintActions(); | ||
} else { | ||
$upgrade_obj->Execute( $f_action ); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
require_once( 'constant_inc.php' ); | ||
require_once( 'config_inc.php' ); | ||
require_once( 'core_database_API.php' ); | ||
?> | ||
<?php | ||
db_connect( $g_hostname, $g_db_username, $g_db_password, $g_database_name ); | ||
|
||
class UpgradeItem { | ||
var $item_count; | ||
var $query_arr; | ||
var $upgrade_name; | ||
var $upgrade_file; | ||
|
||
function UpgradeItem() { | ||
$this->item_count = 0; | ||
$this->query_arr = array(); | ||
$this->upgrade_name = 'upgrade_name_not_set_call_SetUpgradeName'; | ||
$this->upgrade_file = 'script_name_not_set_call_SetUpgradeName'; | ||
} | ||
|
||
# For example, Upgrade Name = 'Upgrade from 0.17.x to 0.18.x' | ||
# Upgrade File = 'admin_upgrade_0_18_0' | ||
# The upgrade file name will also be used for the name of the generated | ||
# SQL file, it should also be the same as the php script file that has the | ||
# SQL statements and their execution (without extension). | ||
function SetUpgradeName( $p_upgrade_name, $p_upgrade_file ) { | ||
$this->upgrade_name = $p_upgrade_name; | ||
$this->upgrade_file = $p_upgrade_file; | ||
} | ||
|
||
# Valid comments are empty lines or lines that start with a # | ||
function IsValidComment( $p_comment ) { | ||
return ( ( strlen ( $p_comment ) == 0 ) || ( $p_comment[0] == '#' ) ); | ||
} | ||
|
||
function AddComment( $p_comment ) { | ||
if ( !$this->IsValidComment( $p_comment ) ) { | ||
PRINT "Error: Comments must start with # ( $p_comment )"; | ||
return; | ||
} | ||
|
||
$this->AddItem ( $p_comment ); | ||
} | ||
|
||
# Empty lines or lines start with a # are considered comments | ||
function AddItem( $p_string = '' ) { | ||
$this->query_arr[$this->item_count] = $p_string; | ||
$this->item_count++; | ||
} | ||
|
||
# Prints the upgrade title + the execution links, hence SetUpgradeName()) must be called first. | ||
function PrintActions() { | ||
global $g_php; | ||
|
||
PRINT "<tr><td width='300'>$this->upgrade_name</td><td> | ||
[ <a href='$this->upgrade_file$g_php?f_action=print'>Print</a> ] | ||
[ <a href='$this->upgrade_file$g_php?f_action=sql'>Download SQL</a> ] | ||
[ <a href='$this->upgrade_file$g_php?f_action=upgrade'>Upgrade Now</a> ]</td></tr>"; | ||
} | ||
|
||
function Execute( $p_action ) { | ||
if ( strcmp($p_action, 'print' ) == 0 ) { | ||
$t_message = "PRINTING ONLY"; | ||
} else if ( strcmp ( $p_action, 'upgrade' ) == 0 ) { | ||
$t_message = "PRINTING AND EXECUTING"; | ||
} else if ( strcmp ( $p_action, 'sql' ) == 0) { | ||
# @@@ The generated file is in UNIX format, should it be in Windows format? | ||
$t_filename = $this->upgrade_file . '.sql'; | ||
header( "Content-Type: text/plain; name=$t_filename" ); | ||
header( 'Content-Transfer-Encoding: BASE64;' ); | ||
header( "Content-Disposition: attachment; filename=$t_filename" ); | ||
|
||
for ( $i=0; $i<$this->item_count; $i++ ) { | ||
if ( $this->IsValidComment( $this->query_arr[$i] ) ) { | ||
PRINT $this->query_arr[$i] . "\n"; | ||
} else { | ||
PRINT $this->query_arr[$i] . ";\n"; | ||
} | ||
} | ||
|
||
die; # how to mark the eof with terminating the script. | ||
} else { | ||
PRINT "Unknown action < $p_action >."; | ||
return; | ||
} | ||
|
||
PRINT "<hr><big>$this->upgrade_name - $t_message</big><br><hr><code>"; | ||
|
||
$t_query_number = 0; | ||
for ( $i=0; $i<$this->item_count; $i++ ) { | ||
if ( $this->IsValidComment( $this->query_arr[$i] ) ) { | ||
PRINT '<b>' . $this->query_arr[$i] . '</b><br>'; | ||
} else { | ||
$t_query_number++; | ||
PRINT $t_query_number . ': '.$this->query_arr[$i].'<br>'; | ||
flush(); | ||
if ( strcmp( $p_action, 'upgrade' ) == 0 ) { | ||
$result = db_query( $this->query_arr[$i] ); | ||
} | ||
} | ||
} | ||
|
||
PRINT "</code><hr>"; | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters