Skip to content

Commit

Permalink
1. Fixed a warning where $f_private was used without being defined when
Browse files Browse the repository at this point in the history
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
vboctor committed Jun 6, 2002
1 parent e55e52c commit b178db0
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 8 deletions.
17 changes: 9 additions & 8 deletions admin_upgrade.php
@@ -1,4 +1,5 @@
<?php include( "core_API.php" ) ?>
<?php require_once( "core_API.php" ) ?>
<h1>Mantis Database Upgrade</h1>
<b>WARNING:</b> - Always backup your database data before upgrading. From the command line you can do this with the mysqldump command.
<p>
eg:
Expand All @@ -15,13 +16,13 @@
If you are more than one minor version behind then you will need to run upgrades sequentially. So to jump from 0.15.1 to 0.17.0 you would run 0.15.x to 0.16.x then 0.16.x to 0.17.x
<hr>
<p>
<a href="admin_upgrade_0_17_0<?php echo $g_php ?>">Upgrade from 0.16.x to 0.17.x</a>
<p>
<a href="admin_upgrade_0_16_0<?php echo $g_php ?>">Upgrade from 0.15.x to 0.16.x</a>
<p>
<a href="admin_upgrade_0_15_0<?php echo $g_php ?>">Upgrade from 0.14.x to 0.15.x</a>
<p>
<a href="admin_upgrade_0_14_0<?php echo $g_php ?>">Upgrade to 0.14.x</a>
<table border=0 width=50%>
<?php require_once ( 'admin_upgrade_0_18_0.php' ) ?>
<tr><td>Upgrade from 0.16.x to 0.17.x</td><td>[ <a href="admin_upgrade_0_17_0<?php echo $g_php ?>">Upgrade Now</a> ]</td></tr>
<tr><td>Upgrade from 0.15.x to 0.16.x</td><td>[ <a href="admin_upgrade_0_16_0<?php echo $g_php ?>">Upgrade Now</a> ]</td></tr>
<tr><td>Upgrade from 0.14.x to 0.15.x</td><td>[ <a href="admin_upgrade_0_15_0<?php echo $g_php ?>">Upgrade Now</a> ]</td></tr>
<tr><td>Upgrade to 0.14.x</td><td>[ <a href="admin_upgrade_0_14_0<?php echo $g_php ?>">Upgrade Now</a> ]</td></tr>
</table>
<p>
<hr>
<p>
Expand Down
24 changes: 24 additions & 0 deletions admin_upgrade_0_18_0.php
@@ -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 );
}
?>
107 changes: 107 additions & 0 deletions admin_upgrade_inc.php
@@ -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>";
}
}
?>
2 changes: 2 additions & 0 deletions bugnote_add.php
Expand Up @@ -16,6 +16,8 @@
check_bug_exists( $f_id );
$c_id = (integer)$f_id;

check_varset( $f_private, '0' );

# get user information
$u_id = get_current_user_field( 'id' );

Expand Down

0 comments on commit b178db0

Please sign in to comment.