diff --git a/admin/install.php b/admin/install.php index 7a9f21b02e..7565d72182 100644 --- a/admin/install.php +++ b/admin/install.php @@ -185,7 +185,20 @@ function InsertData( $p_table, $p_data ) { if( 0 == $t_install_state ) { print_test( 'Setting Database Type', '' !== $f_db_type, true, 'database type is blank?' ); - print_test( 'Checking Database connection settings exist', ( $f_dsn !== '' || ( $f_database_name !== '' && $f_db_username !== '' && $f_hostname !== '' ) ), true, 'database connection settings do not exist?' ); + + $t_db_conn_exists = ( $f_dsn !== '' || ( $f_database_name !== '' && $f_db_username !== '' && $f_hostname !== '' ) ); + # Oracle supports binding in two ways: + # - hostname, username/password and database name + # - tns name (insert into hostname field) and username/password, database name is still empty + if ( $f_db_type == 'oci8' ) { + $t_db_conn_exists = $t_db_conn_exists || ( $f_database_name == '' && $f_db_username !== '' && $f_hostname !== '' ); + } + print_test( 'Checking Database connection settings exist', + $t_db_conn_exists, + true, + 'database connection settings do not exist?' + ); + print_test( 'Checking PHP support for database type', db_check_database_support( $f_db_type ), true, 'database is not supported by PHP. Check that it has been compiled into your server.' @@ -205,7 +218,7 @@ function InsertData( $p_table, $p_data ) { } $t_cur_version = config_get( 'database_version', -1 ); - + if( $t_cur_version > 1 ) { $g_database_upgrade = true; $f_db_exists = true; @@ -277,7 +290,7 @@ function InsertData( $p_table, $p_data ) { print_test( 'Setting Database Username', '' !== $f_db_username, true, 'database username is blank' ); print_test( 'Setting Database Password', '' !== $f_db_password, false, 'database password is blank' ); - print_test( 'Setting Database Name', '' !== $f_database_name, true, 'database name is blank' ); + print_test( 'Setting Database Name', '' !== $f_database_name || $f_db_type == 'oci8' , true, 'database name is blank' ); if( $f_db_type == 'db2' ) { print_test( 'Setting Database Schema', !is_blank( $f_db_schema ), true, 'must have a schema name for AS400 in the form of DBNAME/SCHEMA' ); @@ -384,7 +397,7 @@ function InsertData( $p_table, $p_data ) { # due to a bug in ADODB, this call prompts warnings, hence the @ # the check only works on mysql if the database is open $t_version_info = @$g_db->ServerInfo(); - echo '
Running ' . $f_db_type . ' version ' . $t_version_info['description']; + echo '
Running ' . $f_db_type . ' version ' . nl2br( $t_version_info['description'] ); ?> Close(); + $g_db = null; ?> @@ -665,7 +686,14 @@ function InsertData( $p_table, $p_data ) { $g_db_connected = false; # fake out database access routines used by config_get - $GLOBALS['g_db_type'] = $f_db_type; + config_set_global( 'db_type', $f_db_type ); + + # Initialize short table prefixes and suffix for Oracle + if ( $f_db_type == 'oci8' ) { + $GLOBALS['g_db_table_prefix'] = $t_db_table_prefix = 'm'; + $GLOBALS['g_db_table_plugin_prefix'] = $t_db_table_plugin_prefix = 'plg'; + $GLOBALS['g_db_table_suffix'] = $t_db_table_suffix = '_t'; + } # database_api references this require_once( dirname( __FILE__ ) . '/schema.php' ); @@ -700,55 +728,83 @@ function InsertData( $p_table, $p_data ) { echo ''; } - $dict = NewDataDictionary( $g_db ); + $dict = @NewDataDictionary( $g_db ); $t_sql = true; $t_target = $upgrade[$i][1][0]; - if( $upgrade[$i][0] == 'InsertData' ) { - $sqlarray = call_user_func_array( $upgrade[$i][0], $upgrade[$i][1] ); - } - else if( $upgrade[$i][0] == 'UpdateSQL' ) { - $sqlarray = array( - $upgrade[$i][1], - ); - $t_target = $upgrade[$i][1]; - } else if( $upgrade[$i][0] == 'UpdateFunction' ) { - $sqlarray = array( - $upgrade[$i][1], - ); - if( isset( $upgrade[$i][2] ) ) { - $sqlarray[] = $upgrade[$i][2]; - } - $t_sql = false; - $t_target = $upgrade[$i][1]; - } else { - /* 0: function to call, 1: function params, 2: function to evaluate before calling upgrade, if false, skip upgrade. */ - if( isset( $upgrade[$i][2] ) ) { - if( call_user_func_array( $upgrade[$i][2][0], $upgrade[$i][2][1] ) ) { + + switch ($upgrade[$i][0]) { + + case 'InsertData': + $sqlarray = call_user_func_array( $upgrade[$i][0], $upgrade[$i][1] ); + break; + + case 'UpdateSQL': + $sqlarray = array( + $upgrade[$i][1], + ); + $t_target = $upgrade[$i][1]; + break; + + case 'UpdateFunction': + $sqlarray = array( + $upgrade[$i][1], + ); + if( isset( $upgrade[$i][2] ) ) { + $sqlarray[] = $upgrade[$i][2]; + } + $t_sql = false; + $t_target = $upgrade[$i][1]; + break; + + case NULL: + // No-op upgrade step - required for oci8 + break; + + default: $sqlarray = call_user_func_array( array( $dict, $upgrade[$i][0] ), $upgrade[$i][1] ); + + /* 0: function to call, 1: function params, 2: function to evaluate before calling upgrade, if false, skip upgrade. */ + if( isset( $upgrade[$i][2] ) ) { + if( call_user_func_array( $upgrade[$i][2][0], $upgrade[$i][2][1] ) ) { + $sqlarray = call_user_func_array( array( $dict, $upgrade[$i][0] ), $upgrade[$i][1] ); + } else { + $sqlarray = array(); + } } else { - $sqlarray = array(); + $sqlarray = call_user_func_array( array( $dict, $upgrade[$i][0] ), $upgrade[$i][1] ); } - } else { - $sqlarray = call_user_func_array( array( $dict, $upgrade[$i][0] ), $upgrade[$i][1] ); - } + break; } if( $f_log_queries ) { if( $t_sql ) { foreach( $sqlarray as $sql ) { - echo htmlentities( $sql ) . ";\n\n"; + # "CREATE OR REPLACE TRIGGER" statements must end with "END;\n/" for Oracle sqlplus + if ( $f_db_type == 'oci8' && stripos( $sql, 'CREATE OR REPLACE TRIGGER' ) === 0 ) { + $t_sql_end = "\n/"; + } else { + $t_sql_end = ";"; + } + echo htmlentities( $sql ) . $t_sql_end . "\n\n"; } } } else { - echo 'Schema ' . $upgrade[$i][0] . ' ( ' . $t_target . ' )'; - if( $t_sql ) { - $ret = $dict->ExecuteSQLArray( $sqlarray, false ); + echo "Schema step $i: "; + if( is_null( $upgrade[$i][0]) ) { + echo 'No operation'; + $ret = 2; } else { - if( isset( $sqlarray[1] ) ) { - $ret = call_user_func( 'install_' . $sqlarray[0], $sqlarray[1] ); + echo $upgrade[$i][0] . " ( $t_target )"; + if( $t_sql ) { + $ret = $dict->ExecuteSQLArray( $sqlarray, false ); } else { - $ret = call_user_func( 'install_' . $sqlarray[0] ); + if( isset( $sqlarray[1] ) ) { + $ret = call_user_func( 'install_' . $sqlarray[0], $sqlarray[1] ); + } else { + $ret = call_user_func( 'install_' . $sqlarray[0] ); + } } } + echo ''; if( $ret == 2 ) { print_test_result( GOOD ); config_set( 'database_version', $i ); @@ -824,17 +880,26 @@ function InsertData( $p_table, $p_data ) { ?> . /** - * Each entry below defines the schema. The upgrade array consists of two elements - * The first is the function to generate SQL statements e.g., CreateTableSQL, DropTableSQL, - * ChangeTableSQL, RenameTableSQL, RenameColumnSQL, DropTableSQL, ChangeTableSQL, RenameTableSQL, - * RenameColumnSQL, AlterColumnSQL, DropColumnSQL + * MantisBT schema definition + * The schema is defined a list of schema updates, stored as an array. * - * A local function "InsertData" has been provided to add data to the db - * The second parameter is an array of the parameters to be passed to the function. - * - * An update identifier is inferred from the ordering of this table. ONLY ADD NEW CHANGES TO THE - * END OF THE TABLE!!! + * Each upgrade step consists of two elements: + * 1. The function to generate SQL statements. Available functions (from ADOdb + * library) are: + * CreateTableSQL, DropTableSQL, ChangeTableSQL, RenameTableSQL, + * RenameColumnSQL, DropTableSQL, ChangeTableSQL, RenameTableSQL, + * RenameColumnSQL, AlterColumnSQL, DropColumnSQL + * A local function "InsertData" has been provided to add data to the db + * + * 2. An array of the parameters to be passed to the function. + * + * The integrity of the schema relies on strict ordering of this array. + * - ONLY ADD NEW CHANGES TO THE END OF THE TABLE!!! + * - NEVER SKIP AN INDEX IN THE SEQUENCE!!! */ if ( !function_exists( 'db_null_date' ) ) { @@ -38,12 +44,32 @@ function db_null_date() { function installer_db_now() { - global $g_db; + global $g_db; - return $g_db->BindTimeStamp( time() ); + return $g_db->BindTimeStamp( time() ); +} + +# Special handling for Oracle (oci8): +# - Field cannot be null with oci because empty string equals NULL +# - Oci uses a different date literal syntax +# - Default BLOBs to empty_blob() function +if( db_is_oracle() ) { + $t_notnull = ""; + $t_timestamp = "timestamp" . installer_db_now(); + $t_blob_default = 'DEFAULT " empty_blob() "'; +} else { + $t_notnull = 'NOTNULL'; + $t_timestamp = "'" . installer_db_now() . "'"; + $t_blob_default = ''; } -/* 00 */ $upgrade[] = array('CreateTableSQL',array(db_get_table( 'config' )," +/** + * Begin schema definition + * + * 'Release markers' are placed right AFTER the last schema step that is + * included in the corresponding release + */ +$upgrade[ 0] = array('CreateTableSQL',array(db_get_table( 'config' )," config_id C(64) NOTNULL PRIMARY, project_id I DEFAULT '0' PRIMARY, user_id I DEFAULT '0' PRIMARY, @@ -51,8 +77,8 @@ function installer_db_now() { type I DEFAULT '90', value XL NOTNULL", array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 01 */ $upgrade[] = array('CreateIndexSQL',array('idx_config',db_get_table( 'config' ),'config_id')); -/* 02 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('bug_file')," +$upgrade[ 1] = array('CreateIndexSQL',array('idx_config',db_get_table( 'config' ),'config_id')); +$upgrade[ 2] = array('CreateTableSQL',array(db_get_table('bug_file')," id I UNSIGNED NOTNULL PRIMARY AUTOINCREMENT, bug_id I UNSIGNED NOTNULL DEFAULT '0', title C(250) NOTNULL DEFAULT \" '' \", @@ -63,34 +89,38 @@ function installer_db_now() { filesize I NOTNULL DEFAULT '0', file_type C(250) NOTNULL DEFAULT \" '' \", date_added T NOTNULL DEFAULT '" . db_null_date() . "', - content B NOTNULL + content B NOTNULL $t_blob_default ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 03 */ $upgrade[] = array('CreateIndexSQL',array('idx_bug_file_bug_id',db_get_table('bug_file'),'bug_id')); -/* 04 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('bug_history')," +$upgrade[ 3] = array('CreateIndexSQL',array('idx_bug_file_bug_id',db_get_table('bug_file'),'bug_id')); +$upgrade[ 4] = array('CreateTableSQL',array(db_get_table('bug_history')," id I UNSIGNED NOTNULL PRIMARY AUTOINCREMENT, user_id I UNSIGNED NOTNULL DEFAULT '0', bug_id I UNSIGNED NOTNULL DEFAULT '0', date_modified T NOTNULL DEFAULT '" . db_null_date() . "', - field_name C(32) NOTNULL DEFAULT \" '' \", - old_value C(128) NOTNULL DEFAULT \" '' \", - new_value C(128) NOTNULL DEFAULT \" '' \", + field_name C(32) $t_notnull DEFAULT \" '' \", + old_value C(128) $t_notnull DEFAULT \" '' \", + new_value C(128) $t_notnull DEFAULT \" '' \", type I2 NOTNULL DEFAULT '0' ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 05 */ $upgrade[] = array('CreateIndexSQL',array('idx_bug_history_bug_id',db_get_table('bug_history'),'bug_id')); -/* 06 */ $upgrade[] = array('CreateIndexSQL',array('idx_history_user_id',db_get_table('bug_history'),'user_id')); -/* 07 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('bug_monitor')," +$upgrade[ 5] = array('CreateIndexSQL',array('idx_bug_history_bug_id',db_get_table('bug_history'),'bug_id')); +$upgrade[ 6] = array('CreateIndexSQL',array('idx_history_user_id',db_get_table('bug_history'),'user_id')); +$upgrade[ 7] = array('CreateTableSQL',array(db_get_table('bug_monitor')," user_id I UNSIGNED NOTNULL PRIMARY DEFAULT '0', bug_id I UNSIGNED NOTNULL PRIMARY DEFAULT '0' ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 08 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('bug_relationship')," +$upgrade[ 8] = array('CreateTableSQL',array(db_get_table('bug_relationship')," id I UNSIGNED NOTNULL AUTOINCREMENT PRIMARY, source_bug_id I UNSIGNED NOTNULL DEFAULT '0', destination_bug_id I UNSIGNED NOTNULL DEFAULT '0', relationship_type I2 NOTNULL DEFAULT '0' ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 09 */ $upgrade[] = array('CreateIndexSQL',array('idx_relationship_source',db_get_table('bug_relationship'),'source_bug_id')); -/* 10 */ $upgrade[] = array('CreateIndexSQL',array('idx_relationship_destination',db_get_table('bug_relationship'),'destination_bug_id')); -/* 11 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('bug')," +$upgrade[ 9] = array('CreateIndexSQL',array('idx_relationship_source',db_get_table('bug_relationship'),'source_bug_id')); + +# ---------------------------------------------------------------------------- +# Schema version: 10 +# +$upgrade[ 10] = array('CreateIndexSQL',array('idx_relationship_destination',db_get_table('bug_relationship'),'destination_bug_id')); +$upgrade[ 11] = array('CreateTableSQL',array(db_get_table('bug')," id I UNSIGNED PRIMARY NOTNULL AUTOINCREMENT, project_id I UNSIGNED NOTNULL DEFAULT '0', reporter_id I UNSIGNED NOTNULL DEFAULT '0', @@ -117,19 +147,19 @@ function installer_db_now() { view_state I2 NOTNULL DEFAULT '10', summary C(128) NOTNULL DEFAULT \" '' \", sponsorship_total I NOTNULL DEFAULT '0', - sticky L NOTNULL DEFAULT \"'0'\" + sticky L $t_notnull DEFAULT \"'0'\" ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 12 */ $upgrade[] = array('CreateIndexSQL',array('idx_bug_sponsorship_total',db_get_table('bug'),'sponsorship_total')); -/* 13 */ $upgrade[] = array('CreateIndexSQL',array('idx_bug_fixed_in_version',db_get_table('bug'),'fixed_in_version')); -/* 14 */ $upgrade[] = array('CreateIndexSQL',array('idx_bug_status',db_get_table('bug'),'status')); -/* 15 */ $upgrade[] = array('CreateIndexSQL',array('idx_project',db_get_table('bug'),'project_id')); -/* 16 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('bug_text')," +$upgrade[ 12] = array('CreateIndexSQL',array('idx_bug_sponsorship_total',db_get_table('bug'),'sponsorship_total')); +$upgrade[ 13] = array('CreateIndexSQL',array('idx_bug_fixed_in_version',db_get_table('bug'),'fixed_in_version')); +$upgrade[ 14] = array('CreateIndexSQL',array('idx_bug_status',db_get_table('bug'),'status')); +$upgrade[ 15] = array('CreateIndexSQL',array('idx_project',db_get_table('bug'),'project_id')); +$upgrade[ 16] = array('CreateTableSQL',array(db_get_table('bug_text')," id I PRIMARY UNSIGNED NOTNULL AUTOINCREMENT, description XL NOTNULL, - steps_to_reproduce XL NOTNULL, - additional_information XL NOTNULL + steps_to_reproduce XL $t_notnull, + additional_information XL $t_notnull ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 17 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('bugnote')," +$upgrade[ 17] = array('CreateTableSQL',array(db_get_table('bugnote')," id I UNSIGNED PRIMARY NOTNULL AUTOINCREMENT, bug_id I UNSIGNED NOTNULL DEFAULT '0', reporter_id I UNSIGNED NOTNULL DEFAULT '0', @@ -140,25 +170,28 @@ function installer_db_now() { note_type I DEFAULT '0', note_attr C(250) DEFAULT \" '' \" ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 18 */ $upgrade[] = array('CreateIndexSQL',array('idx_bug',db_get_table('bugnote'),'bug_id')); -/* 19 */ $upgrade[] = array('CreateIndexSQL',array('idx_last_mod',db_get_table('bugnote'),'last_modified')); -/* 20 */ -/* 21 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('bugnote_text')," +$upgrade[ 18] = array('CreateIndexSQL',array('idx_bug',db_get_table('bugnote'),'bug_id')); +$upgrade[ 19] = array('CreateIndexSQL',array('idx_last_mod',db_get_table('bugnote'),'last_modified')); + +# ---------------------------------------------------------------------------- +# Schema version: 20 +# +$upgrade[ 20] = array('CreateTableSQL',array(db_get_table('bugnote_text')," id I UNSIGNED NOTNULL PRIMARY AUTOINCREMENT, note XL NOTNULL ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 22 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('custom_field_project')," +$upgrade[ 21] = array('CreateTableSQL',array(db_get_table('custom_field_project')," field_id I NOTNULL PRIMARY DEFAULT '0', project_id I UNSIGNED PRIMARY NOTNULL DEFAULT '0', sequence I2 NOTNULL DEFAULT '0' ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 23 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('custom_field_string')," +$upgrade[ 22] = array('CreateTableSQL',array(db_get_table('custom_field_string')," field_id I NOTNULL PRIMARY DEFAULT '0', bug_id I NOTNULL PRIMARY DEFAULT '0', value C(255) NOTNULL DEFAULT \" '' \" ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 24 */ $upgrade[] = array('CreateIndexSQL',array('idx_custom_field_bug',db_get_table('custom_field_string'),'bug_id')); -/* 25 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('custom_field')," +$upgrade[ 23] = array('CreateIndexSQL',array('idx_custom_field_bug',db_get_table('custom_field_string'),'bug_id')); +$upgrade[ 24] = array('CreateTableSQL',array(db_get_table('custom_field')," id I NOTNULL PRIMARY AUTOINCREMENT, name C(64) NOTNULL DEFAULT \" '' \", type I2 NOTNULL DEFAULT '0', @@ -179,8 +212,8 @@ function installer_db_now() { display_closed L NOTNULL DEFAULT \" '0' \", require_closed L NOTNULL DEFAULT \" '0' \" ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 26 */ $upgrade[] = array('CreateIndexSQL',array('idx_custom_field_name',db_get_table('custom_field'),'name')); -/* 27 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('filters')," +$upgrade[ 25] = array('CreateIndexSQL',array('idx_custom_field_name',db_get_table('custom_field'),'name')); +$upgrade[ 26] = array('CreateTableSQL',array(db_get_table('filters')," id I UNSIGNED NOTNULL PRIMARY AUTOINCREMENT, user_id I NOTNULL DEFAULT '0', project_id I NOTNULL DEFAULT '0', @@ -188,7 +221,7 @@ function installer_db_now() { name C(64) NOTNULL DEFAULT \" '' \", filter_string XL NOTNULL ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 28 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('news')," +$upgrade[ 27] = array('CreateTableSQL',array(db_get_table('news')," id I UNSIGNED PRIMARY NOTNULL AUTOINCREMENT, project_id I UNSIGNED NOTNULL DEFAULT '0', poster_id I UNSIGNED NOTNULL DEFAULT '0', @@ -199,12 +232,12 @@ function installer_db_now() { headline C(64) NOTNULL DEFAULT \" '' \", body XL NOTNULL ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 29 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('project_category')," +$upgrade[ 28] = array('CreateTableSQL',array(db_get_table('project_category')," project_id I UNSIGNED NOTNULL PRIMARY DEFAULT '0', category C(64) NOTNULL PRIMARY DEFAULT \" '' \", user_id I UNSIGNED NOTNULL DEFAULT '0' ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 30 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('project_file')," +$upgrade[ 29] = array('CreateTableSQL',array(db_get_table('project_file')," id I UNSIGNED NOTNULL PRIMARY AUTOINCREMENT, project_id I UNSIGNED NOTNULL DEFAULT '0', title C(250) NOTNULL DEFAULT \" '' \", @@ -215,14 +248,17 @@ function installer_db_now() { filesize I NOTNULL DEFAULT '0', file_type C(250) NOTNULL DEFAULT \" '' \", date_added T NOTNULL DEFAULT '" . db_null_date() . "', - content B NOTNULL + content B NOTNULL $t_blob_default ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 31 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('project_hierarchy')," +# ---------------------------------------------------------------------------- +# Schema version: 30 +# +$upgrade[ 30] = array('CreateTableSQL',array(db_get_table('project_hierarchy')," child_id I UNSIGNED NOTNULL, parent_id I UNSIGNED NOTNULL", array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 32 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('project')," +$upgrade[ 31] = array('CreateTableSQL',array(db_get_table('project')," id I UNSIGNED PRIMARY NOTNULL AUTOINCREMENT, name C(128) NOTNULL DEFAULT \" '' \", status I2 NOTNULL DEFAULT '10', @@ -230,27 +266,32 @@ function installer_db_now() { view_state I2 NOTNULL DEFAULT '10', access_min I2 NOTNULL DEFAULT '10', file_path C(250) NOTNULL DEFAULT \" '' \", - description XL NOTNULL + description XL $t_notnull ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 33 */ $upgrade[] = array('CreateIndexSQL',array('idx_project_id',db_get_table('project'),'id')); -/* 34 */ $upgrade[] = array('CreateIndexSQL',array('idx_project_name',db_get_table('project'),'name',array('UNIQUE'))); -/* 35 */ $upgrade[] = array('CreateIndexSQL',array('idx_project_view',db_get_table('project'),'view_state')); -/* 36 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('project_user_list')," + +# Index autocreated when oci used +$upgrade[ 32] = db_is_oracle() + ? NULL # No-op - required to ensure schema version consistency + : array('CreateIndexSQL',array('idx_project_id',db_get_table('project'),'id')); + +$upgrade[ 33] = array('CreateIndexSQL',array('idx_project_name',db_get_table('project'),'name',array('UNIQUE'))); +$upgrade[ 34] = array('CreateIndexSQL',array('idx_project_view',db_get_table('project'),'view_state')); +$upgrade[ 35] = array('CreateTableSQL',array(db_get_table('project_user_list')," project_id I UNSIGNED PRIMARY NOTNULL DEFAULT '0', user_id I UNSIGNED PRIMARY NOTNULL DEFAULT '0', access_level I2 NOTNULL DEFAULT '10' ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 37 */ $upgrade[] = array( 'CreateIndexSQL',array('idx_project_user',db_get_table('project_user_list'),'user_id')); -/* 38 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('project_version')," +$upgrade[ 36] = array( 'CreateIndexSQL',array('idx_project_user',db_get_table('project_user_list'),'user_id')); +$upgrade[ 37] = array('CreateTableSQL',array(db_get_table('project_version')," id I NOTNULL PRIMARY AUTOINCREMENT, project_id I UNSIGNED NOTNULL DEFAULT '0', version C(64) NOTNULL DEFAULT \" '' \", date_order T NOTNULL DEFAULT '" . db_null_date() . "', - description XL NOTNULL, + description XL $t_notnull, released L NOTNULL DEFAULT \" '1' \" ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 39 */ $upgrade[] = array('CreateIndexSQL',array('idx_project_version',db_get_table('project_version'),'project_id,version',array('UNIQUE'))); -/* 40 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('sponsorship')," +$upgrade[ 38] = array('CreateIndexSQL',array('idx_project_version',db_get_table('project_version'),'project_id,version',array('UNIQUE'))); +$upgrade[ 39] = array('CreateTableSQL',array(db_get_table('sponsorship')," id I NOTNULL PRIMARY AUTOINCREMENT, bug_id I NOTNULL DEFAULT '0', user_id I NOTNULL DEFAULT '0', @@ -261,9 +302,13 @@ function installer_db_now() { date_submitted T NOTNULL DEFAULT '" . db_null_date() . "', last_updated T NOTNULL DEFAULT '" . db_null_date() . "' ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 41 */ $upgrade[] = array('CreateIndexSQL',array('idx_sponsorship_bug_id',db_get_table('sponsorship'),'bug_id')); -/* 42 */ $upgrade[] = array('CreateIndexSQL',array('idx_sponsorship_user_id',db_get_table('sponsorship'),'user_id')); -/* 43 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('tokens')," + +# ---------------------------------------------------------------------------- +# Schema version: 40 +# +$upgrade[ 40] = array('CreateIndexSQL',array('idx_sponsorship_bug_id',db_get_table('sponsorship'),'bug_id')); +$upgrade[ 41] = array('CreateIndexSQL',array('idx_sponsorship_user_id',db_get_table('sponsorship'),'user_id')); +$upgrade[ 42] = array('CreateTableSQL',array(db_get_table('tokens')," id I NOTNULL PRIMARY AUTOINCREMENT, owner I NOTNULL, type I NOTNULL, @@ -271,7 +316,7 @@ function installer_db_now() { expiry T, value XL NOTNULL", array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 44 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('user_pref')," +$upgrade[ 43] = array('CreateTableSQL',array(db_get_table('user_pref')," id I UNSIGNED NOTNULL PRIMARY AUTOINCREMENT, user_id I UNSIGNED NOTNULL DEFAULT '0', project_id I UNSIGNED NOTNULL DEFAULT '0', @@ -281,7 +326,7 @@ function installer_db_now() { advanced_view L NOTNULL DEFAULT \" '0' \", advanced_update L NOTNULL DEFAULT \" '0' \", refresh_delay I NOTNULL DEFAULT '0', - redirect_delay L NOTNULL DEFAULT \" '0' \", + redirect_delay L $t_notnull DEFAULT \" '0' \", bugnote_order C(4) NOTNULL DEFAULT 'ASC', email_on_new L NOTNULL DEFAULT \" '0' \", email_on_assigned L NOTNULL DEFAULT \" '0' \", @@ -290,8 +335,8 @@ function installer_db_now() { email_on_closed L NOTNULL DEFAULT \" '0' \", email_on_reopened L NOTNULL DEFAULT \" '0' \", email_on_bugnote L NOTNULL DEFAULT \" '0' \", - email_on_status L NOTNULL DEFAULT \" '0' \", - email_on_priority L NOTNULL DEFAULT \" '0' \", + email_on_status L $t_notnull DEFAULT \" '0' \", + email_on_priority L $t_notnull DEFAULT \" '0' \", email_on_priority_min_severity I2 NOTNULL DEFAULT '10', email_on_status_min_severity I2 NOTNULL DEFAULT '10', email_on_bugnote_min_severity I2 NOTNULL DEFAULT '10', @@ -304,19 +349,19 @@ function installer_db_now() { email_bugnote_limit I2 NOTNULL DEFAULT '0', language C(32) NOTNULL DEFAULT 'english' ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 45 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('user_print_pref')," +$upgrade[ 44] = array('CreateTableSQL',array(db_get_table('user_print_pref')," user_id I UNSIGNED NOTNULL PRIMARY DEFAULT '0', print_pref C(27) NOTNULL DEFAULT \" '' \" ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 46 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('user_profile')," +$upgrade[ 45] = array('CreateTableSQL',array(db_get_table('user_profile')," id I UNSIGNED NOTNULL PRIMARY AUTOINCREMENT, user_id I UNSIGNED NOTNULL DEFAULT '0', platform C(32) NOTNULL DEFAULT \" '' \", os C(32) NOTNULL DEFAULT \" '' \", os_build C(32) NOTNULL DEFAULT \" '' \", - description XL NOTNULL + description XL $t_notnull ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 47 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('user')," +$upgrade[ 46] = array('CreateTableSQL',array(db_get_table('user')," id I UNSIGNED NOTNULL PRIMARY AUTOINCREMENT, username C(32) NOTNULL DEFAULT \" '' \", realname C(64) NOTNULL DEFAULT \" '' \", @@ -332,104 +377,136 @@ function installer_db_now() { failed_login_count I2 NOTNULL DEFAULT '0', cookie_string C(64) NOTNULL DEFAULT \" '' \" ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 48 */ $upgrade[] = array('CreateIndexSQL',array('idx_user_cookie_string',db_get_table('user'),'cookie_string',array('UNIQUE'))); -/* 49 */ $upgrade[] = array('CreateIndexSQL',array('idx_user_username',db_get_table('user'),'username',array('UNIQUE'))); -/* 50 */ $upgrade[] = array('CreateIndexSQL',array('idx_enable',db_get_table('user'),'enabled')); -/* 51 */ $upgrade[] = array('CreateIndexSQL',array('idx_access',db_get_table('user'),'access_level')); -/* 52 */ $upgrade[] = array('InsertData', array( db_get_table('user'), - "(username, realname, email, password, date_created, last_visit, enabled, protected, access_level, login_count, lost_password_request_count, failed_login_count, cookie_string) VALUES - ('administrator', '', 'root@localhost', '63a9f0ea7bb98050796b649e85481845', '" . installer_db_now() . "', '" . installer_db_now() . "', '1', '0', 90, 3, 0, 0, '" . - md5( mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() ) ) . md5( time() ) . "')" ) ); -/* 53 */ $upgrade[] = array('AlterColumnSQL', array( db_get_table( 'bug_history' ), "old_value C(255) NOTNULL" ) ); -/* 54 */ $upgrade[] = array('AlterColumnSQL', array( db_get_table( 'bug_history' ), "new_value C(255) NOTNULL" ) ); -/* 55 */ $upgrade[] = array('CreateTableSQL',array(db_get_table('email')," +$upgrade[ 47] = array('CreateIndexSQL',array('idx_user_cookie_string',db_get_table('user'),'cookie_string',array('UNIQUE'))); +$upgrade[ 48] = array('CreateIndexSQL',array('idx_user_username',db_get_table('user'),'username',array('UNIQUE'))); +$upgrade[ 49] = array('CreateIndexSQL',array('idx_enable',db_get_table('user'),'enabled')); + +# ---------------------------------------------------------------------------- +# Schema version: 50 +# +$upgrade[ 50] = array('CreateIndexSQL',array('idx_access',db_get_table('user'),'access_level')); +$upgrade[ 51] = array('InsertData', array( db_get_table('user'), + "(username, realname, email, password, date_created, last_visit, enabled, protected, access_level, login_count, lost_password_request_count, failed_login_count, cookie_string) VALUES + ('administrator', '', 'root@localhost', '63a9f0ea7bb98050796b649e85481845', " . $t_timestamp . ", " . $t_timestamp . ", '1', '0', 90, 3, 0, 0, '" . + md5( mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() ) ) . md5( time() ) . "')" ) ); + +# Release marker: 1.0.0 - 1.0.7 + +$upgrade[ 52] = array('AlterColumnSQL', array( db_get_table( 'bug_history' ), "old_value C(255) $t_notnull" ) ); +$upgrade[ 53] = array('AlterColumnSQL', array( db_get_table( 'bug_history' ), "new_value C(255) $t_notnull" ) ); + +$upgrade[ 54] = array('CreateTableSQL',array(db_get_table('email')," email_id I UNSIGNED NOTNULL PRIMARY AUTOINCREMENT, email C(64) NOTNULL DEFAULT \" '' \", subject C(250) NOTNULL DEFAULT \" '' \", - submitted T NOTNULL DEFAULT '" . db_null_date() . "', + submitted T NOTNULL DEFAULT '" . db_null_date() . "', metadata XL NOTNULL, body XL NOTNULL ",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS'))); -/* 56 */ $upgrade[] = array('CreateIndexSQL',array('idx_email_id',db_get_table('email'),'email_id')); -/* 57 */ $upgrade[] = array('AddColumnSQL',array(db_get_table('bug'), "target_version C(64) NOTNULL DEFAULT \" '' \"")); -/* 58 */ $upgrade[] = array('AddColumnSQL',array(db_get_table('bugnote'), "time_tracking I UNSIGNED NOTNULL DEFAULT \" 0 \"")); -/* 59 */ $upgrade[] = array('CreateIndexSQL',array('idx_diskfile',db_get_table('bug_file'),'diskfile')); -/* 60 */ $upgrade[] = array('AlterColumnSQL', array( db_get_table( 'user_print_pref' ), "print_pref C(64) NOTNULL" ) ); -/* 61 */ $upgrade[] = array('AlterColumnSQL', array( db_get_table( 'bug_history' ), "field_name C(64) NOTNULL" ) ); + +# Index autocreated when oci used +$upgrade[ 55] = db_is_oracle() + ? NULL # No-op - required to ensure schema version consistency + : array('CreateIndexSQL',array('idx_email_id',db_get_table('email'),'email_id')); + +$upgrade[ 56] = array('AddColumnSQL',array(db_get_table('bug'), "target_version C(64) NOTNULL DEFAULT \" '' \"")); +$upgrade[ 57] = array('AddColumnSQL',array(db_get_table('bugnote'), "time_tracking I UNSIGNED NOTNULL DEFAULT \" 0 \"")); +$upgrade[ 58] = array('CreateIndexSQL',array('idx_diskfile',db_get_table('bug_file'),'diskfile')); +$upgrade[ 59] = array('AlterColumnSQL', array( db_get_table( 'user_print_pref' ), "print_pref C(64) $t_notnull" ) ); + +# ---------------------------------------------------------------------------- +# Schema version: 60 +# +$upgrade[ 60] = array('AlterColumnSQL', array( db_get_table( 'bug_history' ), "field_name C(64) $t_notnull" ) ); # Release marker: 1.1.0a4 -/* 62 */ $upgrade[] = array('CreateTableSQL', array( db_get_table( 'tag' ), " +$upgrade[ 61] = array('CreateTableSQL', array( db_get_table( 'tag' ), " id I UNSIGNED NOTNULL PRIMARY AUTOINCREMENT, user_id I UNSIGNED NOTNULL DEFAULT '0', name C(100) NOTNULL PRIMARY DEFAULT \" '' \", - description XL NOTNULL, + description XL $t_notnull, date_created T NOTNULL DEFAULT '" . db_null_date() . "', date_updated T NOTNULL DEFAULT '" . db_null_date() . "' ", array( 'mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS' ) ) ); -/* 63 */ $upgrade[] = array('CreateTableSQL', array( db_get_table( 'bug_tag' ), " +$upgrade[ 62] = array('CreateTableSQL', array( db_get_table( 'bug_tag' ), " bug_id I UNSIGNED NOTNULL PRIMARY DEFAULT '0', tag_id I UNSIGNED NOTNULL PRIMARY DEFAULT '0', user_id I UNSIGNED NOTNULL DEFAULT '0', date_attached T NOTNULL DEFAULT '" . db_null_date() . "' ", array( 'mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS' ) ) ); -/* 64 */ $upgrade[] = array('CreateIndexSQL', array( 'idx_typeowner', db_get_table( 'tokens' ), 'type, owner' ) ); +$upgrade[ 63] = array('CreateIndexSQL', array( 'idx_typeowner', db_get_table( 'tokens' ), 'type, owner' ) ); +# Release marker: 1.1.0 - 1.1.8 # Release marker: 1.2.0-SVN -/* 65 */ $upgrade[] = array('CreateTableSQL', array( db_get_table( 'plugin' ), " +$upgrade[ 64] = array('CreateTableSQL', array( db_get_table( 'plugin' ), " basename C(40) NOTNULL PRIMARY, enabled L NOTNULL DEFAULT \" '0' \" ", array( 'mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS' ) ) ); -/* 66 */ $upgrade[] = array('AlterColumnSQL', array( db_get_table( 'user_pref' ), "redirect_delay I NOTNULL DEFAULT 0" ) ); +$upgrade[ 65] = array('AlterColumnSQL', array( db_get_table( 'user_pref' ), "redirect_delay I $t_notnull DEFAULT 0" ) ); + +# Apparently mysql now has a STRICT mode, where setting a DEFAULT value on a +# blob/text is now an error, instead of being silently ignored +$upgrade[ 66] = ( isset( $f_db_type ) && ( $f_db_type == 'mysql' || $f_db_type == 'mysqli' ) ) + ? array('AlterColumnSQL', array( db_get_table( 'custom_field' ), "possible_values X NOTNULL" ) ) + : array('AlterColumnSQL', array( db_get_table( 'custom_field' ), "possible_values X NOTNULL DEFAULT \" '' \"" ) ); -/* apparently mysql now has a STRICT mode, where setting a DEFAULT value on a blob/text is now an error, instead of being silently ignored */ -if ( isset( $f_db_type ) && ( $f_db_type == 'mysql' || $f_db_type == 'mysqli' ) ) { - /* 00 */ $upgrade[] = array('AlterColumnSQL', array( db_get_table( 'custom_field' ), "possible_values X NOTNULL" ) ); -} else { - /* 00 */ $upgrade[] = array('AlterColumnSQL', array( db_get_table( 'custom_field' ), "possible_values X NOTNULL DEFAULT \" '' \"" ) ); -} -/* 67 */ $upgrade[] = array( 'CreateTableSQL', array( db_get_table( 'category' ), " +$upgrade[ 67] = array( 'CreateTableSQL', array( db_get_table( 'category' ), " id I UNSIGNED NOTNULL PRIMARY AUTOINCREMENT, project_id I UNSIGNED NOTNULL DEFAULT '0', user_id I UNSIGNED NOTNULL DEFAULT '0', name C(128) NOTNULL DEFAULT \" '' \", status I UNSIGNED NOTNULL DEFAULT '0' ", array( 'mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS' ) ) ); -/* 68 */ $upgrade[] = array( 'CreateIndexSQL', array( 'idx_category_project_name', db_get_table( 'category' ), 'project_id, name', array( 'UNIQUE' ) ) ); -/* 69 */ $upgrade[] = array( 'InsertData', array( db_get_table( 'category' ), " +$upgrade[ 68] = array( 'CreateIndexSQL', array( 'idx_category_project_name', db_get_table( 'category' ), 'project_id, name', array( 'UNIQUE' ) ) ); +$upgrade[ 69] = array( 'InsertData', array( db_get_table( 'category' ), " ( project_id, user_id, name, status ) VALUES ( '0', '0', 'General', '0' ) " ) ); -/* 70 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'bug' ), "category_id I UNSIGNED NOTNULL DEFAULT '1'" ) ); -/* 71 */ $upgrade[] = array( 'UpdateFunction', "category_migrate" ); -/* 72 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'bug' ), "category" ) ); -/* 73 */ $upgrade[] = array( 'DropTableSQL', array( db_get_table( 'project_category' ) ) ); -/* 74 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'project' ), "category_id I UNSIGNED NOTNULL DEFAULT '1'" ) ); -// remove unnecessary indexes -/* 75 */ $upgrade[] = array('CreateIndexSQL',array('idx_project_id',db_get_table('project'),'id', array('DROP')), array( 'db_index_exists', array( db_get_table('project'), 'idx_project_id'))); -/* 76 */ $upgrade[] = array('CreateIndexSQL',array('idx_config',db_get_table( 'config' ),'config_id', array('DROP')), array( 'db_index_exists', array( db_get_table('config'), 'idx_config'))); - -/* 77 */ $upgrade[] = array( 'InsertData', array( db_get_table( 'plugin' ), " + +# ---------------------------------------------------------------------------- +# Schema version: 70 +# +$upgrade[ 70] = array( 'AddColumnSQL', array( db_get_table( 'bug' ), "category_id I UNSIGNED NOTNULL DEFAULT '1'" ) ); +$upgrade[ 71] = array( 'UpdateFunction', "category_migrate" ); +$upgrade[ 72] = array( 'DropColumnSQL', array( db_get_table( 'bug' ), "category" ) ); +$upgrade[ 73] = array( 'DropTableSQL', array( db_get_table( 'project_category' ) ) ); +$upgrade[ 74] = array( 'AddColumnSQL', array( db_get_table( 'project' ), "category_id I UNSIGNED NOTNULL DEFAULT '1'" ) ); + +# remove unnecessary indexes +$upgrade[ 75] = array('CreateIndexSQL',array('idx_project_id',db_get_table('project'),'id', array('DROP')), array( 'db_index_exists', array( db_get_table('project'), 'idx_project_id'))); +$upgrade[ 76] = array('CreateIndexSQL',array('idx_config',db_get_table( 'config' ),'config_id', array('DROP')), array( 'db_index_exists', array( db_get_table('config'), 'idx_config'))); + +$upgrade[ 77] = array( 'InsertData', array( db_get_table( 'plugin' ), " ( basename, enabled ) VALUES ( 'MantisCoreFormatting', '1' )" ) ); -/* 78 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'project' ), "inherit_global I UNSIGNED NOTNULL DEFAULT '0'" ) ); -/* 79 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'project_hierarchy' ), "inherit_parent I UNSIGNED NOTNULL DEFAULT '0'" ) ); -/* 80 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'plugin' ), " +$upgrade[ 78] = array( 'AddColumnSQL', array( db_get_table( 'project' ), "inherit_global I UNSIGNED NOTNULL DEFAULT '0'" ) ); +$upgrade[ 79] = array( 'AddColumnSQL', array( db_get_table( 'project_hierarchy' ), "inherit_parent I UNSIGNED NOTNULL DEFAULT '0'" ) ); + +# ---------------------------------------------------------------------------- +# Schema version: 80 +# +$upgrade[ 80] = array( 'AddColumnSQL', array( db_get_table( 'plugin' ), " protected L NOTNULL DEFAULT \" '0' \", priority I UNSIGNED NOTNULL DEFAULT '3' " ) ); -/* 81 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'project_version' ), " +$upgrade[ 81] = array( 'AddColumnSQL', array( db_get_table( 'project_version' ), " obsolete L NOTNULL DEFAULT \" '0' \"" ) ); -/* 82 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'bug' ), " - due_date T NOTNULL DEFAULT '" . db_null_date() . "' " ) ); +$upgrade[ 82] = array( 'AddColumnSQL', array( db_get_table( 'bug' ), " + due_date T NOTNULL DEFAULT '" . db_null_date() . "' " ) ); + +# Release marker: 1.2.0a1 -/* 83 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'custom_field' ), " +$upgrade[ 83] = array( 'AddColumnSQL', array( db_get_table( 'custom_field' ), " filter_by L NOTNULL DEFAULT \" '1' \"" ) ); -/* 84 */ $upgrade[] = array( 'CreateTableSQL', array( db_get_table( 'bug_revision' ), " + +# Release marker: 1.2.0a2 - 1.2.0a3 + +$upgrade[ 84] = array( 'CreateTableSQL', array( db_get_table( 'bug_revision' ), " id I UNSIGNED NOTNULL PRIMARY AUTOINCREMENT, bug_id I UNSIGNED NOTNULL, bugnote_id I UNSIGNED NOTNULL DEFAULT '0', @@ -438,166 +515,223 @@ function installer_db_now() { type I UNSIGNED NOTNULL, value XL NOTNULL ", array( 'mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS' ) ) ); -/* 85 */ $upgrade[] = array( 'CreateIndexSQL', array( 'idx_bug_rev_id_time', db_get_table( 'bug_revision' ), 'bug_id, timestamp' ) ); -/* 86 */ $upgrade[] = array( 'CreateIndexSQL', array( 'idx_bug_rev_type', db_get_table( 'bug_revision' ), 'type' ) ); - -#date conversion +$upgrade[ 85] = array( 'CreateIndexSQL', array( 'idx_bug_rev_id_time', db_get_table( 'bug_revision' ), 'bug_id, timestamp' ) ); +$upgrade[ 86] = array( 'CreateIndexSQL', array( 'idx_bug_rev_type', db_get_table( 'bug_revision' ), 'type' ) ); -/* 87 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'bug' ), " +# Date conversion +$upgrade[ 87] = array( 'AddColumnSQL', array( db_get_table( 'bug' ), " date_submitted_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 88 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'bug' ), " +$upgrade[ 88] = array( 'AddColumnSQL', array( db_get_table( 'bug' ), " due_date_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 89 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'bug' ), " +$upgrade[ 89] = array( 'AddColumnSQL', array( db_get_table( 'bug' ), " last_updated_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 90 */ $upgrade[] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'bug' ), 'id', array( 'date_submitted', 'due_date', 'last_updated' ), array( 'date_submitted_int', 'due_date_int', 'last_updated_int' ) ) ); -/* 91 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'bug' ), "date_submitted" ) ); -/* 92 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'bug' ), "date_submitted_int", "date_submitted", "date_submitted_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 93 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'bug' ), "due_date" ) ); -/* 94 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'bug' ), "due_date_int", "due_date", "due_date_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 95 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'bug' ), "last_updated" ) ); -/* 96 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'bug' ), "last_updated_int", "last_updated", "last_updated_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +# ---------------------------------------------------------------------------- +# Schema version: 90 +# +$upgrade[ 90] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'bug' ), 'id', array( 'date_submitted', 'due_date', 'last_updated' ), array( 'date_submitted_int', 'due_date_int', 'last_updated_int' ) ) ); + +$upgrade[ 91] = array( 'DropColumnSQL', array( db_get_table( 'bug' ), "date_submitted" ) ); +$upgrade[ 92] = array( 'RenameColumnSQL', array( db_get_table( 'bug' ), "date_submitted_int", "date_submitted", "date_submitted_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[ 93] = array( 'DropColumnSQL', array( db_get_table( 'bug' ), "due_date" ) ); +$upgrade[ 94] = array( 'RenameColumnSQL', array( db_get_table( 'bug' ), "due_date_int", "due_date", "due_date_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[ 95] = array( 'DropColumnSQL', array( db_get_table( 'bug' ), "last_updated" ) ); +$upgrade[ 96] = array( 'RenameColumnSQL', array( db_get_table( 'bug' ), "last_updated_int", "last_updated", "last_updated_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 97 */ $upgrade[] = array('CreateIndexSQL',array('idx_last_mod',db_get_table( 'bugnote' ),'last_modified', array('DROP')), array( 'db_index_exists', array( db_get_table('bugnote'), 'idx_last_mod'))); +$upgrade[ 97] = array('CreateIndexSQL',array('idx_last_mod',db_get_table( 'bugnote' ),'last_modified', array('DROP')), array( 'db_index_exists', array( db_get_table('bugnote'), 'idx_last_mod'))); -/* 98 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'bugnote' ), " +$upgrade[ 98] = array( 'AddColumnSQL', array( db_get_table( 'bugnote' ), " last_modified_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 99 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'bugnote' ), " +$upgrade[ 99] = array( 'AddColumnSQL', array( db_get_table( 'bugnote' ), " date_submitted_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 100 */ $upgrade[] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'bugnote' ), 'id', array( 'last_modified', 'date_submitted' ), array( 'last_modified_int', 'date_submitted_int' ) ) ); -/* 101 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'bugnote' ), "last_modified" ) ); -/* 102 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'bugnote' ), "last_modified_int", "last_modified", "last_modified_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 103 */ $upgrade[] = array('CreateIndexSQL',array('idx_last_mod',db_get_table('bugnote'),'last_modified')); -/* 104 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'bugnote' ), "date_submitted" ) ); -/* 105 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'bugnote' ), "date_submitted_int", "date_submitted", "date_submitted_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); - - -/* 106 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'bug_file' ), " +# ---------------------------------------------------------------------------- +# Schema version: 100 +# +$upgrade[100] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'bugnote' ), 'id', array( 'last_modified', 'date_submitted' ), array( 'last_modified_int', 'date_submitted_int' ) ) ); + +$upgrade[101] = array( 'DropColumnSQL', array( db_get_table( 'bugnote' ), "last_modified" ) ); +$upgrade[102] = array( 'RenameColumnSQL', array( db_get_table( 'bugnote' ), "last_modified_int", "last_modified", "last_modified_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[103] = array('CreateIndexSQL',array('idx_last_mod',db_get_table('bugnote'),'last_modified')); +$upgrade[104] = array( 'DropColumnSQL', array( db_get_table( 'bugnote' ), "date_submitted" ) ); +$upgrade[105] = array( 'RenameColumnSQL', array( db_get_table( 'bugnote' ), "date_submitted_int", "date_submitted", "date_submitted_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[106] = array( 'AddColumnSQL', array( db_get_table( 'bug_file' ), " date_added_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 107 */ $upgrade[] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'bug_file' ), 'id', 'date_added', 'date_added_int' ) ); -/* 108 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'bug_file' ), "date_added" ) ); -/* 109 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'bug_file' ), "date_added_int", "date_added", "date_added_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[107] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'bug_file' ), 'id', 'date_added', 'date_added_int' ) ); +$upgrade[108] = array( 'DropColumnSQL', array( db_get_table( 'bug_file' ), "date_added" ) ); +$upgrade[109] = array( 'RenameColumnSQL', array( db_get_table( 'bug_file' ), "date_added_int", "date_added", "date_added_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); + +# ---------------------------------------------------------------------------- +# Schema version: 110 +# -/* 110 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'project_file' ), " +$upgrade[110] = array( 'AddColumnSQL', array( db_get_table( 'project_file' ), " date_added_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 111 */ $upgrade[] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'project_file' ), 'id', 'date_added', 'date_added_int' ) ); -/* 112 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'project_file' ), "date_added" ) ); -/* 113 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'project_file' ), "date_added_int", "date_added", "date_added_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[111] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'project_file' ), 'id', 'date_added', 'date_added_int' ) ); +$upgrade[112] = array( 'DropColumnSQL', array( db_get_table( 'project_file' ), "date_added" ) ); +$upgrade[113] = array( 'RenameColumnSQL', array( db_get_table( 'project_file' ), "date_added_int", "date_added", "date_added_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 114 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'bug_history' ), " +$upgrade[114] = array( 'AddColumnSQL', array( db_get_table( 'bug_history' ), " date_modified_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 115 */ $upgrade[] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'bug_history' ), 'id', 'date_modified', 'date_modified_int' ) ); -/* 116 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'bug_history' ), "date_modified" ) ); -/* 117 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'bug_history' ), "date_modified_int", "date_modified", "date_modified_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[115] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'bug_history' ), 'id', 'date_modified', 'date_modified_int' ) ); +$upgrade[116] = array( 'DropColumnSQL', array( db_get_table( 'bug_history' ), "date_modified" ) ); +$upgrade[117] = array( 'RenameColumnSQL', array( db_get_table( 'bug_history' ), "date_modified_int", "date_modified", "date_modified_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 118 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'user' ), " +$upgrade[118] = array( 'AddColumnSQL', array( db_get_table( 'user' ), " last_visit_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 119 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'user' ), " +$upgrade[119] = array( 'AddColumnSQL', array( db_get_table( 'user' ), " date_created_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 120 */ $upgrade[] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'user' ), 'id', array( 'last_visit', 'date_created' ), array( 'last_visit_int', 'date_created_int' ) ) ); +# ---------------------------------------------------------------------------- +# Schema version: 120 +# + +$upgrade[120] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'user' ), 'id', array( 'last_visit', 'date_created' ), array( 'last_visit_int', 'date_created_int' ) ) ); -/* 121 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'user' ), "date_created" ) ); -/* 122 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'user' ), "date_created_int", "date_created", "date_created_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 123 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'user' ), "last_visit" ) ); -/* 124 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'user' ), "last_visit_int", "last_visit", "last_visit_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[121] = array( 'DropColumnSQL', array( db_get_table( 'user' ), "date_created" ) ); +$upgrade[122] = array( 'RenameColumnSQL', array( db_get_table( 'user' ), "date_created_int", "date_created", "date_created_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[123] = array( 'DropColumnSQL', array( db_get_table( 'user' ), "last_visit" ) ); +$upgrade[124] = array( 'RenameColumnSQL', array( db_get_table( 'user' ), "last_visit_int", "last_visit", "last_visit_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 125 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'email' ), " +$upgrade[125] = array( 'AddColumnSQL', array( db_get_table( 'email' ), " submitted_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 126 */ $upgrade[] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'email' ), 'email_id', 'submitted', 'submitted_int' ) ); -/* 127 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'email' ), "submitted" ) ); -/* 128 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'email' ), "submitted_int", "submitted", "submitted_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[126] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'email' ), 'email_id', 'submitted', 'submitted_int' ) ); +$upgrade[127] = array( 'DropColumnSQL', array( db_get_table( 'email' ), "submitted" ) ); +$upgrade[128] = array( 'RenameColumnSQL', array( db_get_table( 'email' ), "submitted_int", "submitted", "submitted_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 129 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'tag' ), " +$upgrade[129] = array( 'AddColumnSQL', array( db_get_table( 'tag' ), " date_created_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 130 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'tag' ), " + +# ---------------------------------------------------------------------------- +# Schema version: 130 +# +$upgrade[130] = array( 'AddColumnSQL', array( db_get_table( 'tag' ), " date_updated_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 131 */ $upgrade[] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'tag' ), 'id', array( 'date_created', 'date_updated' ), array( 'date_created_int', 'date_updated_int' ) ) ); +$upgrade[131] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'tag' ), 'id', array( 'date_created', 'date_updated' ), array( 'date_created_int', 'date_updated_int' ) ) ); -/* 132 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'tag' ), "date_created" ) ); -/* 133 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'tag' ), "date_created_int", "date_created", "date_created_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 134 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'tag' ), "date_updated" ) ); -/* 135 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'tag' ), "date_updated_int", "date_updated", "date_updated_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[132] = array( 'DropColumnSQL', array( db_get_table( 'tag' ), "date_created" ) ); +$upgrade[133] = array( 'RenameColumnSQL', array( db_get_table( 'tag' ), "date_created_int", "date_created", "date_created_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[134] = array( 'DropColumnSQL', array( db_get_table( 'tag' ), "date_updated" ) ); +$upgrade[135] = array( 'RenameColumnSQL', array( db_get_table( 'tag' ), "date_updated_int", "date_updated", "date_updated_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 136 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'bug_tag' ), " +$upgrade[136] = array( 'AddColumnSQL', array( db_get_table( 'bug_tag' ), " date_attached_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 137 */ $upgrade[] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'bug_tag' ), 'bug_id', 'date_attached', 'date_attached_int' ) ); -/* 138 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'bug_tag' ), "date_attached" ) ); -/* 139 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'bug_tag' ), "date_attached_int", "date_attached", "date_attached_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[137] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'bug_tag' ), 'bug_id', 'date_attached', 'date_attached_int' ) ); +$upgrade[138] = array( 'DropColumnSQL', array( db_get_table( 'bug_tag' ), "date_attached" ) ); +$upgrade[139] = array( 'RenameColumnSQL', array( db_get_table( 'bug_tag' ), "date_attached_int", "date_attached", "date_attached_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 140 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'tokens' ), " +# ---------------------------------------------------------------------------- +# Schema version: 140 +# + +$upgrade[140] = array( 'AddColumnSQL', array( db_get_table( 'tokens' ), " timestamp_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 141 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'tokens' ), " +$upgrade[141] = array( 'AddColumnSQL', array( db_get_table( 'tokens' ), " expiry_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 142 */ $upgrade[] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'tokens' ), 'id', array( 'timestamp', 'expiry' ), array( 'timestamp_int', 'expiry_int' ) ) ); +$upgrade[142] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'tokens' ), 'id', array( 'timestamp', 'expiry' ), array( 'timestamp_int', 'expiry_int' ) ) ); -/* 143 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'tokens' ), "timestamp" ) ); -/* 144 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'tokens' ), "timestamp_int", "timestamp", "timestamp_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 145 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'tokens' ), "expiry" ) ); -/* 146 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'tokens' ), "expiry_int", "expiry", "expiry_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[143] = array( 'DropColumnSQL', array( db_get_table( 'tokens' ), "timestamp" ) ); +$upgrade[144] = array( 'RenameColumnSQL', array( db_get_table( 'tokens' ), "timestamp_int", "timestamp", "timestamp_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[145] = array( 'DropColumnSQL', array( db_get_table( 'tokens' ), "expiry" ) ); +$upgrade[146] = array( 'RenameColumnSQL', array( db_get_table( 'tokens' ), "expiry_int", "expiry", "expiry_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 147 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'news' ), " +$upgrade[147] = array( 'AddColumnSQL', array( db_get_table( 'news' ), " last_modified_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 148 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'news' ), " +$upgrade[148] = array( 'AddColumnSQL', array( db_get_table( 'news' ), " date_posted_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 149 */ $upgrade[] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'news' ), 'id', array( 'date_posted', 'last_modified' ), array( 'date_posted_int', 'last_modified_int' ) ) ); -/* 150 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'news' ), "last_modified" ) ); -/* 151 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'news' ), "last_modified_int", "last_modified", "last_modified_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 152 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'news' ), "date_posted" ) ); -/* 153 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'news' ), "date_posted_int", "date_posted", "date_posted_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); - -/* 154 */ $upgrade[] = array('CreateIndexSQL',array('idx_bug_rev_id_time',db_get_table( 'bug_revision' ),'bug_id, timestamp', array('DROP')), array( 'db_index_exists', array( db_get_table('bug_revision'), 'idx_bug_rev_id_time'))); -/* 155 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'bug_revision' ), " +$upgrade[149] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'news' ), 'id', array( 'date_posted', 'last_modified' ), array( 'date_posted_int', 'last_modified_int' ) ) ); + +# ---------------------------------------------------------------------------- +# Schema version: 150 +# + +$upgrade[150] = array( 'DropColumnSQL', array( db_get_table( 'news' ), "last_modified" ) ); +$upgrade[151] = array( 'RenameColumnSQL', array( db_get_table( 'news' ), "last_modified_int", "last_modified", "last_modified_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[152] = array( 'DropColumnSQL', array( db_get_table( 'news' ), "date_posted" ) ); +$upgrade[153] = array( 'RenameColumnSQL', array( db_get_table( 'news' ), "date_posted_int", "date_posted", "date_posted_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); + +$upgrade[154] = array('CreateIndexSQL',array('idx_bug_rev_id_time',db_get_table( 'bug_revision' ),'bug_id, timestamp', array('DROP')), array( 'db_index_exists', array( db_get_table('bug_revision'), 'idx_bug_rev_id_time'))); +$upgrade[155] = array( 'AddColumnSQL', array( db_get_table( 'bug_revision' ), " timestamp_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 156 */ $upgrade[] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'bug_revision' ), 'id', 'timestamp', 'timestamp_int' ) ); -/* 157 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'bug_revision' ), "timestamp" ) ); -/* 158 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'bug_revision' ), "timestamp_int", "timestamp", "timestamp_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 159 */ $upgrade[] = array( 'CreateIndexSQL', array( 'idx_bug_rev_id_time', db_get_table( 'bug_revision' ), 'bug_id, timestamp' ) ); +$upgrade[156] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'bug_revision' ), 'id', 'timestamp', 'timestamp_int' ) ); +$upgrade[157] = array( 'DropColumnSQL', array( db_get_table( 'bug_revision' ), "timestamp" ) ); +$upgrade[158] = array( 'RenameColumnSQL', array( db_get_table( 'bug_revision' ), "timestamp_int", "timestamp", "timestamp_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[159] = array( 'CreateIndexSQL', array( 'idx_bug_rev_id_time', db_get_table( 'bug_revision' ), 'bug_id, timestamp' ) ); + +# ---------------------------------------------------------------------------- +# Schema version: 160 +# -/* 160 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'user_pref' ), " +$upgrade[160] = array( 'AddColumnSQL', array( db_get_table( 'user_pref' ), " timezone C(32) NOTNULL DEFAULT '' " ) ); -/* 161 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'project_version' ), " +$upgrade[161] = array( 'AddColumnSQL', array( db_get_table( 'project_version' ), " date_order_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 162 */ $upgrade[] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'project_version' ), 'id', 'date_order', 'date_order_int' ) ); -/* 163 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'project_version' ), "date_order" ) ); -/* 164 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'project_version' ), "date_order_int", "date_order", "date_order_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[162] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'project_version' ), 'id', 'date_order', 'date_order_int' ) ); +$upgrade[163] = array( 'DropColumnSQL', array( db_get_table( 'project_version' ), "date_order" ) ); +$upgrade[164] = array( 'RenameColumnSQL', array( db_get_table( 'project_version' ), "date_order_int", "date_order", "date_order_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 165 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'sponsorship' ), " +$upgrade[165] = array( 'AddColumnSQL', array( db_get_table( 'sponsorship' ), " date_submitted_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 166 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'sponsorship' ), " +$upgrade[166] = array( 'AddColumnSQL', array( db_get_table( 'sponsorship' ), " last_updated_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 167 */ $upgrade[] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'sponsorship' ), 'id', array( 'date_submitted', 'last_updated' ), array( 'date_submitted_int', 'last_updated_int' ) ) ); +$upgrade[167] = array( 'UpdateFunction', "date_migrate", array( db_get_table( 'sponsorship' ), 'id', array( 'date_submitted', 'last_updated' ), array( 'date_submitted_int', 'last_updated_int' ) ) ); -/* 168 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'sponsorship' ), "last_updated" ) ); -/* 169 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'sponsorship' ), "last_updated_int", "last_updated", "last_updated_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +$upgrade[168] = array( 'DropColumnSQL', array( db_get_table( 'sponsorship' ), "last_updated" ) ); +$upgrade[169] = array( 'RenameColumnSQL', array( db_get_table( 'sponsorship' ), "last_updated_int", "last_updated", "last_updated_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 170 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'sponsorship' ), "date_submitted" ) ); -/* 171 */ $upgrade[] = array( 'RenameColumnSQL', array( db_get_table( 'sponsorship' ), "date_submitted_int", "date_submitted", "date_submitted_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); +# ---------------------------------------------------------------------------- +# Schema version: 170 +# +$upgrade[170] = array( 'DropColumnSQL', array( db_get_table( 'sponsorship' ), "date_submitted" ) ); +$upgrade[171] = array( 'RenameColumnSQL', array( db_get_table( 'sponsorship' ), "date_submitted_int", "date_submitted", "date_submitted_int I UNSIGNED NOTNULL DEFAULT '1' " ) ); -/* 172 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'project_file' ), " +$upgrade[172] = array( 'AddColumnSQL', array( db_get_table( 'project_file' ), " user_id I UNSIGNED NOTNULL DEFAULT '0' " ) ); -/* 173 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'bug_file' ), " +$upgrade[173] = array( 'AddColumnSQL', array( db_get_table( 'bug_file' ), " user_id I UNSIGNED NOTNULL DEFAULT '0' " ) ); -/* 174 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'custom_field'), "advanced" ) ); -/* 175 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'user_pref'), "advanced_report" ) ); -/* 176 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'user_pref'), "advanced_view" ) ); -/* 177 */ $upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'user_pref'), "advanced_update" ) ); -/* 178 */ $upgrade[] = array( 'CreateIndexSQL', array( 'idx_project_hierarchy_child_id', db_get_table( 'project_hierarchy' ), 'child_id' ) ); -/* 179 */ $upgrade[] = array( 'CreateIndexSQL', array( 'idx_project_hierarchy_parent_id', db_get_table( 'project_hierarchy' ), 'parent_id' ) ); - -/* 180 */ $upgrade[] = array( 'CreateIndexSQL', array( 'idx_tag_name', db_get_table( 'tag' ), 'name' ) ); -/* 181 */ $upgrade[] = array( 'CreateIndexSQL', array( 'idx_bug_tag_tag_id', db_get_table( 'bug_tag' ), 'tag_id' ) ); -/* 182 */ $upgrade[] = array( 'CreateIndexSQL', array( 'idx_email_id', db_get_table( 'email' ), 'email_id', array( 'DROP' ) ), array( 'db_index_exists', array( db_get_table( 'email' ), 'idx_email_id') ) ); -/* 183 */ $upgrade[] = array( 'UpdateFunction', 'correct_multiselect_custom_fields_db_format' ); -/* 184 */ $upgrade[] = array( 'UpdateFunction', "stored_filter_migrate" ); -/* 185 */ $upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'custom_field_string' ), " + +# Release marker: 1.2.0rc1 + +$upgrade[174] = array( 'DropColumnSQL', array( db_get_table( 'custom_field'), "advanced" ) ); +$upgrade[175] = array( 'DropColumnSQL', array( db_get_table( 'user_pref'), "advanced_report" ) ); +$upgrade[176] = array( 'DropColumnSQL', array( db_get_table( 'user_pref'), "advanced_view" ) ); +$upgrade[177] = array( 'DropColumnSQL', array( db_get_table( 'user_pref'), "advanced_update" ) ); +$upgrade[178] = array( 'CreateIndexSQL', array( 'idx_project_hierarchy_child_id', db_get_table( 'project_hierarchy' ), 'child_id' ) ); + +# Decrease index name length for oci8 (30 chars max) +if( db_is_oracle() ) { + $t_index_name = 'idx_prj_hier_parent_id'; +} else { + $t_index_name = 'idx_project_hierarchy_parent_id'; +} + +# Release marker: 1.2.0rc2 + +$upgrade[179] = array( 'CreateIndexSQL', array( $t_index_name, db_get_table( 'project_hierarchy' ), 'parent_id' ) ); + +# ---------------------------------------------------------------------------- +# Schema version: 180 +# +$upgrade[180] = array( 'CreateIndexSQL', array( 'idx_tag_name', db_get_table( 'tag' ), 'name' ) ); +$upgrade[181] = array( 'CreateIndexSQL', array( 'idx_bug_tag_tag_id', db_get_table( 'bug_tag' ), 'tag_id' ) ); +$upgrade[182] = array( 'CreateIndexSQL', array( 'idx_email_id', db_get_table( 'email' ), 'email_id', array( 'DROP' ) ), array( 'db_index_exists', array( db_get_table( 'email' ), 'idx_email_id') ) ); + +# Release marker: 1.2.0 + +$upgrade[183] = array( 'UpdateFunction', 'correct_multiselect_custom_fields_db_format' ); + +# Release marker: 1.2.1 - 1.2.15 + +$upgrade[184] = array( 'UpdateFunction', "stored_filter_migrate" ); +$upgrade[185] = array( 'AddColumnSQL', array( db_get_table( 'custom_field_string' ), " text XL NULL DEFAULT NULL " ) ); -/* 186 */ $upgrade[] = array( 'UpdateFunction', 'update_history_long_custom_fields' ); -/* 187 */ $upgrade[] = array( 'CreateIndexSQL', array( 'idx_bug_id', db_get_table( 'bug_monitor' ), 'bug_id' ) ); -/* 188 */ $upgrade[] = array( 'AlterColumnSQL', array( db_get_table( 'project' ), "inherit_global L NOTNULL DEFAULT '0'" ) ); -/* 189 */ $upgrade[] = array( 'AlterColumnSQL', array( db_get_table( 'project_hierarchy' ), "inherit_parent L NOTNULL DEFAULT '0'" ) ); +$upgrade[186] = array( 'UpdateFunction', 'update_history_long_custom_fields' ); +$upgrade[187] = array( 'CreateIndexSQL', array( 'idx_bug_id', db_get_table( 'bug_monitor' ), 'bug_id' ) ); +$upgrade[188] = array( 'AlterColumnSQL', array( db_get_table( 'project' ), "inherit_global L NOTNULL DEFAULT '0'" ) ); +$upgrade[189] = array( 'AlterColumnSQL', array( db_get_table( 'project_hierarchy' ), "inherit_parent L NOTNULL DEFAULT '0'" ) ); + +# Release marker: 1.3.0 diff --git a/config_defaults_inc.php b/config_defaults_inc.php index 411be2ef88..1322c91ba5 100644 --- a/config_defaults_inc.php +++ b/config_defaults_inc.php @@ -3207,12 +3207,24 @@ /** * table prefix + * To avoid the 30-char limit on identifiers in Oracle, the prefix + * should be set to blank or kept as short as possible (e.g. 'm') * @global string $g_db_table_prefix */ $g_db_table_prefix = 'mantis'; +/** + * plugin table prefix + * To avoid the 30-char limit on identifiers in Oracle, the prefix + * should be kept as short as possible (e.g. 'plg') + * @global string $g_db_table_prefix + */ +$g_db_table_plugin_prefix = 'plugin'; + /** * table suffix + * To avoid the 30-char limit on identifiers in Oracle, the suffix + * should be set to blank or kept as short as possible * @global string $g_db_table_suffix */ $g_db_table_suffix = '_table'; diff --git a/core/bug_api.php b/core/bug_api.php index d7b060cd08..1f65d078c9 100644 --- a/core/bug_api.php +++ b/core/bug_api.php @@ -2017,7 +2017,7 @@ function bug_unmonitor( $p_bug_id, $p_user_id ) { db_query_bound( $query, $db_query_params ); # log new un-monitor action - history_log_event_special( $p_bug_id, BUG_UNMONITOR, $p_user_id ); + history_log_event_special( $p_bug_id, BUG_UNMONITOR, (int)$p_user_id ); # updated the last_updated date bug_update_date( $p_bug_id ); diff --git a/core/constant_inc.php b/core/constant_inc.php index 0d1351f038..399d6dbb9f 100644 --- a/core/constant_inc.php +++ b/core/constant_inc.php @@ -257,6 +257,7 @@ define( 'ERROR_DB_QUERY_FAILED', 401 ); define( 'ERROR_DB_SELECT_FAILED', 402 ); define( 'ERROR_DB_FIELD_NOT_FOUND', 403 ); +define( 'ERROR_DB_IDENTIFIER_TOO_LONG', 404 ); # ERROR_FILE_* define( 'ERROR_FILE_TOO_BIG', 500 ); diff --git a/core/database_api.php b/core/database_api.php index e3c08b8745..eb0d54db64 100644 --- a/core/database_api.php +++ b/core/database_api.php @@ -62,10 +62,18 @@ * set adodb fetch mode * @global bool $ADODB_FETCH_MODE */ -$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; +if( db_is_oracle() ) { + # Due to oci8 returning column names in uppercase, the MantisBT + # default fetch mode (ADODB_FETCH_ASSOC) does not work properly + # in the current version of ADOdb (5.18) so we override it. + # See #15426 + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; +} else { + $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; +} /** - * Tracks the query parameter count for use with db_aparam(). + * Tracks the query parameter count for use with db_aparam:(). * @global int $g_db_param_count */ $g_db_param_count = 0; @@ -241,6 +249,29 @@ function db_is_db2() { return false; } +/** + * Checks if the database driver is Oracle (oci8) + * @return bool true if oracle + */ +function db_is_oracle() { + $t_db_type = config_get_global( 'db_type' ); + + return ( $t_db_type == 'oci8' ); +} + +/** + * Validates that the given identifier's length is OK for the db platform + * Triggers an error if the identifier is too long + * @param string p_identifier Identifier to check + */ +function db_check_identifier_size( $p_identifier ) { + # Oracle does not support long object names (30 chars max) + if( db_is_oracle() && 30 < strlen( $p_identifier ) ) { + error_parameters( $p_identifier ); + trigger_error( ERROR_DB_IDENTIFIER_TOO_LONG, ERROR ); + } +} + /** * execute query, requires connection to be opened * An error will be triggered if there is a problem executing the query. @@ -258,6 +289,10 @@ function db_query( $p_query, $p_limit = -1, $p_offset = -1 ) { $t_start = microtime(true); + if( db_is_oracle() ) { + $p_query = db_oracle_adapt_query_syntax( $p_query ); + } + if(( $p_limit != -1 ) || ( $p_offset != -1 ) ) { $t_result = $g_db->SelectLimit( $p_query, $p_limit, $p_offset ); } else { @@ -318,6 +353,10 @@ function db_query_bound( $p_query, $arr_parms = null, $p_limit = -1, $p_offset = } } + if( db_is_oracle() ) { + $p_query = db_oracle_adapt_query_syntax( $p_query , $arr_parms ); + } + if(( $p_limit != -1 ) || ( $p_offset != -1 ) ) { $t_result = $g_db->SelectLimit( $p_query, $p_limit, $p_offset, $arr_parms ); } else { @@ -442,6 +481,15 @@ function db_fetch_array( &$p_result ) { static $t_array_result; static $t_array_fields; + # Oci8 returns null values for empty strings + if( db_is_oracle() ) { + foreach( $t_row as &$t_value ) { + if( !isset( $t_value ) ) { + $t_value = ''; + } + } + } + if ($t_array_result != $p_result) { // new query $t_array_result = $p_result; @@ -521,11 +569,18 @@ function db_result( $p_result, $p_index1 = 0, $p_index2 = 0 ) { */ function db_insert_id( $p_table = null, $p_field = "id" ) { global $g_db; + $t_db_type = config_get_global( 'db_type' ); - if( isset( $p_table ) && db_is_pgsql() ) { - $query = "SELECT currval('" . $p_table . "_" . $p_field . "_seq')"; - $result = db_query_bound( $query ); - return db_result( $result ); + if( isset( $p_table ) ) { + if( db_is_oracle() ) { + $query = "SELECT seq_" . $p_table . ".CURRVAL FROM DUAL"; + } elseif( db_is_pgsql() ) { + $query = "SELECT currval('" . $p_table . "_" . $p_field . "_seq')"; + } + if( isset( $query ) ) { + $result = db_query_bound( $query ); + return db_result( $result ); + } } if( db_is_mssql() ) { $query = "SELECT IDENT_CURRENT('$p_table')"; @@ -569,11 +624,13 @@ function db_index_exists( $p_table_name, $p_index_name ) { if( is_blank( $p_index_name ) || is_blank( $p_table_name ) ) { return false; - - // no index found } $t_indexes = $g_db->MetaIndexes( $p_table_name ); + if( $t_indexes === false ) { + // no index found + return false; + } if( !empty( $t_indexes ) ) { # Can't use in_array() since it is case sensitive @@ -697,6 +754,8 @@ function db_prepare_string( $p_string ) { case 'postgres7': case 'pgsql': return pg_escape_string( $p_string ); + case 'oci8': + return $p_string; default: error_parameters( 'db_type', $t_db_type ); trigger_error( ERROR_CONFIG_OPT_INVALID, ERROR ); @@ -728,6 +787,8 @@ function db_prepare_binary_string( $p_string ) { case 'pgsql': return $g_db->BlobEncode( $p_string ); break; + case 'oci8': + # Fall through, oci8 stores raw data in BLOB default: return $p_string; break; @@ -898,12 +959,14 @@ function db_get_table( $p_name ) { $t_prefix = config_get_global( 'db_table_prefix' ); $t_suffix = config_get_global( 'db_table_suffix' ); - if ( $t_prefix ) { + + if( $t_prefix ) { $t_table = $t_prefix . '_' . $t_table; } - if ( $t_suffix ) { - $t_table .= $t_suffix; - } + $t_table .= $t_suffix; + + db_check_identifier_size( $t_table ); + return $t_table; } @@ -923,3 +986,274 @@ function db_get_table_list() { return $t_tables; } +/** + * Updates a BLOB column + * + * This function is only needed for oci8; it will do nothing and return + * false if used with another RDBMS. + * + * @param string $p_table + * @param string $p_column The BLOB column to update + * @param string $p_val Data to store into the BLOB + * @param string $p_where Where clause to identify which record to update + * if null, defaults to the last record inserted in $p_table + * @return bool + */ +function db_update_blob( $p_table, $p_column, $p_val, $p_where = null ) { + global $g_db, $g_db_log_queries, $g_queries_array; + + if( !db_is_oracle() ) { + return false; + } + + if( null == $p_where ) { + $p_where = 'id=' . db_insert_id( $p_table ); + } + + if( ON == $g_db_log_queries ) { + $t_start = microtime(true); + + $t_backtrace = debug_backtrace(); + $t_caller = basename( $t_backtrace[0]['file'] ); + $t_caller .= ":" . $t_backtrace[0]['line']; + + # Is this called from another function? + if( isset( $t_backtrace[1] ) ) { + $t_caller .= ' ' . $t_backtrace[1]['function'] . '()'; + } else { + # or from a script directly? + $t_caller .= ' ' . $_SERVER['SCRIPT_NAME']; + } + } + + $t_result = $g_db->UpdateBlob( $p_table, $p_column, $p_val, $p_where ); + + if( $g_db_log_queries ) { + $t_elapsed = number_format( microtime(true) - $t_start, 4 ); + $t_log_data = array( + "Update BLOB in $p_table.$p_column where $p_where", + $t_elapsed, + $t_caller + ); + log_event( LOG_DATABASE, var_export( $t_log_data, true ) ); + array_push( $g_queries_array, $t_log_data ); + } + + if( !$t_result ) { + db_error(); + trigger_error( ERROR_DB_QUERY_FAILED, ERROR ); + return false; + } + + return $t_result; +} + +/** + * Sorts bind variable numbers and puts them in sequential order + * e.g. input: "... WHERE F1=:12 and F2=:97 ", + * output: "... WHERE F1=:0 and F2=:1 ". + * Used in db_oracle_adapt_query_syntax(). + * @param string $p_query Query string to sort + * @return string Query string with sorted bind variable numbers. + */ +function db_oracle_order_binds_sequentially( $p_query ) { + $t_new_query= ''; + $t_is_odd = true; + $t_after_quote = false; + $t_iter = 0; + + # Divide statement to skip processing string literals + $t_p_query_arr = explode( '\'' , $p_query ); + foreach( $t_p_query_arr as $t_p_query_part ) { + if( $t_new_query != '' ) { + $t_new_query .= '\''; + } + if( $t_is_odd ) { + # Divide to process all bindvars + $t_p_query_subpart_arr = explode( ':' , $t_p_query_part ); + if( count( $t_p_query_subpart_arr ) > 1 ) { + foreach( $t_p_query_subpart_arr as $t_p_query_subpart ) { + if( ( !$t_after_quote ) && ( $t_new_query != '' ) ) { + $t_new_query .= ":" . preg_replace( '/^(\d+?)/U' , strval( $t_iter ) , $t_p_query_subpart ); + $t_iter++; + } else { + $t_new_query .= $t_p_query_subpart; + } + $t_after_quote = false; + } + } else { + $t_new_query .= $t_p_query_part; + } + $t_is_odd = false; + } else { + $t_after_quote = true; + $t_new_query .= $t_p_query_part; + $t_is_odd = true; + } + } + return $t_new_query; +} + +/** + * Adopt input query string and bindvars array to Oracle DB syntax: + * 1. Change bind vars id's to sequence beginnging with 0(calls order_binds_sequentally() ) + * (calls db_oracle_order_binds_sequentially() ) + * 2. Remove "AS" keyword, because it not supported with table aliasing + * 3. Remove null bind variables in insert statements for default values support + * 4. Replace "tab.column=:bind" to "tab.column IS NULL" when :bind is empty string + * 5. Replace "SET tab.column=:bind" to "SET tab.column=DEFAULT" when :bind is empty string + * @param string $p_query Query string to sort + * @param array $arr_parms Array of parameters matching $p_query, function sorts array keys + * @return string Query string with sorted bind variable numbers. + */ +function db_oracle_adapt_query_syntax_ora( $p_query , &$arr_parms = null ) { + # Remove "AS" keyword, because not supported with table aliasing + $t_is_odd = true; + $t_query = ''; + # Divide statement to skip processing string literals + $t_p_query_arr = explode( '\'' , $p_query ); + foreach( $t_p_query_arr as $t_p_query_part ) { + if( $t_query != '' ) + $t_query .= '\''; + if( $t_is_odd ) { + $t_query .= preg_replace( '/ AS /im' , ' ' , $t_p_query_part ); + } else { + $t_query .= $t_p_query_part; + $t_is_odd = true; + } + } + $p_query = $t_query; + + # Remove null bind variables in insert statements for default values support + if( is_array ( $arr_parms ) ) { + preg_match( '/^[\s\n\r]*insert[\s\n\r]+(into){0,1}[\s\n\r]+(?P[a-z0-9_]+)[\s\n\r]*\([\s\n\r]*[\s\n\r]*(?P[a-z0-9_,\s\n\r]+)[\s\n\r]*\)[\s\n\r]*values[\s\n\r]*\([\s\n\r]*(?P[:a-z0-9_,\s\n\r]+)\)/i' , $p_query , $t_matches ); + + if(isset($t_matches['values'])) { #if statement is a INSERT INTO ... (...) VALUES(...) + # iterates non-empty bind variables + $i = 0; + $t_fields_left = $t_matches['fields']; + $t_values_left = $t_matches['values']; + + for( $t_arr_index = 0 ; $t_arr_index < count($arr_parms) ; $t_arr_index++ ) { + # inserting fieldname search + if( preg_match( '/^[\s\n\r]*([a-z0-9_]+)[\s\n\r]*,{0,1}([\d\D]*)\z/i' , $t_fields_left , $t_fieldmatch ) ) { + $t_fields_left = $t_fieldmatch[2]; + $t_fields_arr[$i] = $t_fieldmatch[1]; + } + # inserting bindvar name search + if( preg_match( '/^[\s\n\r]*(:[a-z0-9_]+)[\s\n\r]*,{0,1}([\d\D]*)\z/i' , $t_values_left , $t_valuematch ) ) { + $t_values_left = $t_valuematch[2]; + $t_values_arr[$i] = $t_valuematch[1]; + } + # skip unsetting if bind array value not empty + if( $arr_parms[$t_arr_index] !== '' ) { + $i++; + } else { + $t_arr_index--; + # Shift array and unset bind array element + for( $n = $i + 1 ; $n < count( $arr_parms ) ; $n++ ) { + $arr_parms[$n-1] = $arr_parms[$n]; + } + unset( $t_fields_arr[$i] ); + unset( $t_values_arr[$i] ); + unset( $arr_parms[count( $arr_parms ) - 1] ); + } + } + + # Combine statement from arrays + $p_query = 'INSERT INTO ' . $t_matches['table'] . ' (' . $t_fields_arr[0]; + for( $i = 1 ; $i < count( $arr_parms ) ; $i++ ) { + $p_query = $p_query . ', ' . $t_fields_arr[$i]; + } + $p_query = $p_query . ') values (' . $t_values_arr[0]; + for ( $i = 1 ; $i < count( $arr_parms ) ; $i++ ) { + $p_query = $p_query . ', ' . $t_values_arr[$i]; + } + $p_query = $p_query . ')'; + } else { + # if input statement is NOT a INSERT INTO (...) VALUES(...) + + # "IS NULL" adoptation here + $t_set_where_template_str = substr( md5( uniqid( rand() , true) ), 0, 50 ); + $t_removed_set_where = ''; + + # Need to order parameter array element correctly + $p_query = db_oracle_order_binds_sequentally( $p_query ); + + # Find and remove temporarily "SET var1=:bind1, var2=:bind2 WHERE" part + preg_match( '/^(?P.*)(?P[\s\n\r]*set[\s\n\r]+[\s\n\ra-z0-9_\.=,:\']+)(?Pwhere[\d\D]*)$/i' , $p_query, $t_matches ); + $t_set_where_stmt = isset( $t_matches['after_set_where'] ); + + if( $t_set_where_stmt ) { + $t_removed_set_where = $t_matches['set_where']; + # Now work with statement without "SET ... WHERE" part + $t_templated_query = $t_matches['before_set_where'] . $t_set_where_template_str . $t_matches['after_set_where']; + } else { + $t_templated_query = $p_query; + } + + # Replace "var1=''" by "var1 IS NULL" + while( preg_match( '/^(?P[\d\D]*[\s\n\r(]+([a-z0-9_]*[\s\n\r]*\.){0,1}[\s\n\r]*[a-z0-9_]+)[\s\n\r]*=[\s\n\r]*\'\'(?P[\s\n\r]*[\d\D]*\z)/i' , $t_templated_query , $t_matches ) > 0 ) { + $t_templated_query = $t_matches['before_empty_literal'] . " IS NULL " . $t_matches['after_empty_literal']; + } + # Replace "var1!=''" and "var1<>''" by "var1 IS NOT NULL" + while( preg_match('/^(?P[\d\D]*[\s\n\r(]+([a-z0-9_]*[\s\n\r]*\.){0,1}[\s\n\r]*[a-z0-9_]+)[\s\n\r]*(![\s\n\r]*=|<[\s\n\r]*>)[\s\n\r]*\'\'(?P[\s\n\r]*[\d\D]*\z)/i' , $t_templated_query , $t_matches ) > 0 ) { + $t_templated_query = $t_matches['before_empty_literal'] . " IS NOT NULL " . $t_matches['after_empty_literal']; + } + + $p_query = $t_templated_query; + # Process input bind variable array to replace "WHERE fld=:12" + # by "WHERE fld IS NULL" if :12 is empty + while( preg_match( '/^(?P[\d\D]*[\s\n\r(]+)(?P([a-z0-9_]*[\s\n\r]*\.){0,1}[\s\n\r]*[a-z0-9_]+)(?P[\s\n\r]*=[\s\n\r]*:)(?P[0-9]+)(?P[\s\n\r]*[\d\D]*\z)/i' , $t_templated_query , $t_matches ) > 0 ) { + $t_bind_num = $t_matches['bind_name']; + + $t_search_substr = $t_matches['before_var'] . $t_matches['var_name'] . $t_matches['dividers'] . $t_matches['bind_name'] . $t_matches['after_var']; + $t_replace_substr = $t_matches['before_var'] . $t_matches['var_name'] . "=:" . $t_matches['bind_name']. $t_matches['after_var']; + + if( $arr_parms[$t_bind_num] === '' ) { + for( $n = $t_bind_num + 1 ; $n < count($arr_parms) ; $n++ ) { + $arr_parms[$n - 1] = $arr_parms[$n]; + } + unset( $arr_parms[count( $arr_parms ) - 1] ); + $t_replace_substr = $t_matches['before_var'] . $t_matches['var_name'] . " IS NULL " . $t_matches['after_var']; + } + $p_query = str_replace( $t_search_substr , $t_replace_substr , $p_query ); + + $t_templated_query = $t_matches['before_var'] . $t_matches['after_var']; + } + + if( $t_set_where_stmt ) { + # Put temporarily removed "SET ... WHERE" part back + $p_query = str_replace( $t_set_where_template_str , $t_removed_set_where , $p_query ); + # Need to order parameter array element correctly + $p_query = order_binds_sequentially( $p_query ); + # Find and remove temporary "SET var1=:bind1, var2=:bind2 WHERE" part again + preg_match( '/^(?P.*)(?P[\s\n\r]*set[\s\n\r]+[\s\n\ra-z0-9_\.=,:\']+)(?Pwhere[\d\D]*)$/i' , $p_query , $t_matches ); + $t_removed_set_where = $t_matches['set_where']; + $p_query = $t_matches['before_set_where'] . $t_set_where_template_str . $t_matches['after_set_where']; + + #Replace "SET fld1=:1" to "SET fld1=DEFAULT" if bind array value is empty + $t_removed_set_where_parsing = $t_removed_set_where; + + while( preg_match( '/^(?P[\d\D]*[\s\n\r,]+)(?P([a-z0-9_]*[\s\n\r]*\.){0,1}[\s\n\r]*[a-z0-9_]+)(?P[\s\n\r]*=[\s\n\r]*:)(?P[0-9]+)(?P[,\s\n\r]*[\d\D]*\z)/i' , $t_removed_set_where_parsing , $t_matches ) > 0 ) { + $t_bind_num = $t_matches['bind_name']; + $t_search_substr = $t_matches['before_var'] . $t_matches['var_name'] . $t_matches['dividers'] . $t_matches['bind_name'] ; + $t_replace_substr = $t_matches['before_var'] . $t_matches['var_name'] . $t_matches['dividers'] . $t_matches['bind_name'] ; + + if( $arr_parms[$t_bind_num] === '' ) { + for( $n = $t_bind_num + 1 ; $n < count( $arr_parms ) ; $n++ ) { + $arr_parms[$n - 1] = $arr_parms[ $n ]; + } + unset( $arr_parms[count( $arr_parms ) - 1] ); + $t_replace_substr = $t_matches['before_var'] . $t_matches['var_name'] . "=DEFAULT "; + } + $t_removed_set_where = str_replace( $t_search_substr , $t_replace_substr , $t_removed_set_where ); + $t_removed_set_where_parsing = $t_matches['before_var'] . $t_matches['after_var']; + } + $p_query = str_replace( $t_set_where_template_str , $t_removed_set_where , $p_query ); + } + } + } + $p_query = db_oracle_order_binds_sequentially( $p_query ); + return $p_query; +} diff --git a/core/file_api.php b/core/file_api.php index 9eee9246f1..4d95b1563c 100644 --- a/core/file_api.php +++ b/core/file_api.php @@ -812,7 +812,7 @@ function file_add( $p_bug_id, $p_file, $p_table = 'bug', $p_title = '', $p_desc chmod( $t_disk_file_name, config_get( 'attachments_file_permissions' ) ); - $c_content = "''"; + $c_content = ''; } else { trigger_error( ERROR_FILE_DUPLICATE, ERROR ); } @@ -827,14 +827,10 @@ function file_add( $p_bug_id, $p_file, $p_table = 'bug', $p_title = '', $p_desc $t_file_table = db_get_table( $p_table . '_file' ); $t_id_col = $p_table . "_id"; - $query = "INSERT INTO $t_file_table - ( $t_id_col, title, description, diskfile, filename, folder, filesize, file_type, date_added, content, user_id ) - VALUES - ( " . db_param() . ", " . db_param() . ", " . db_param() . ", " - . db_param() . ", " . db_param() . ", " . db_param() . ", " - . db_param() . ", " . db_param() . ", " . db_param() . ", " - . db_param() . ", " . db_param() . " )"; - db_query_bound( $query, array( + $t_query_fields = " + $t_id_col, title, description, diskfile, filename, folder, + filesize, file_type, date_added, user_id"; + $t_param = array( $t_id, $p_title, $p_desc, @@ -844,9 +840,29 @@ function file_add( $p_bug_id, $p_file, $p_table = 'bug', $p_title = '', $p_desc $t_file_size, $p_file['type'], $p_date_added, - $c_content, (int)$p_user_id, - ) ); + ); + + # oci8 stores contents in a BLOB, which is updated separately + if( !db_is_oracle() ) { + $t_query_fields .= ", content"; + $t_param[] = $c_content; + } + + $t_query_param = db_param(); + for( $i = 1; $i < count( $t_param ); $i++ ){ + $t_query_param .= ", " . db_param(); + } + + $t_query = "INSERT INTO $t_file_table ( $t_query_fields ) + VALUES + ( $t_query_param )"; + + db_query_bound( $t_query, $t_param ); + + if( db_is_oracle() ) { + db_update_blob( $t_file_table, 'content', $c_content, "diskfile='$t_unique_name'" ); + } if( 'bug' == $p_table ) { # update the last_updated date diff --git a/core/helper_api.php b/core/helper_api.php index ccdceae541..54a2a8b1c5 100644 --- a/core/helper_api.php +++ b/core/helper_api.php @@ -133,7 +133,7 @@ function get_percentage_by_status() { # checking if it's a per project statistic or all projects $t_specific_where = helper_project_specific_where( $t_project_id, $t_user_id ); - $query = "SELECT status, COUNT(*) AS number + $query = "SELECT status, COUNT(*) AS num FROM $t_mantis_bug_table WHERE $t_specific_where"; if ( !access_has_project_level( config_get( 'private_bug_threshold' ) ) ) { @@ -146,7 +146,7 @@ function get_percentage_by_status() { $t_status_count_array = array(); while( $row = db_fetch_array( $result ) ) { - $t_status_count_array[$row['status']] = $row['number']; + $t_status_count_array[$row['status']] = $row['num']; } $t_bug_count = array_sum( $t_status_count_array ); foreach( $t_status_count_array AS $t_status=>$t_value ) { diff --git a/core/plugin_api.php b/core/plugin_api.php index 6a576ae79b..c0b31517c6 100644 --- a/core/plugin_api.php +++ b/core/plugin_api.php @@ -194,7 +194,17 @@ function plugin_table( $p_name, $p_basename = null ) { } else { $t_current = $p_basename; } - return db_get_table( 'plugin_' . $t_current . '_' . $p_name ); + + $t_table_name = config_get_global( 'db_table_prefix' ); + if( !empty( $t_table_name ) ) { + $t_table_name .= '_'; + } + $t_table_name .= + config_get_global( 'db_table_plugin_prefix' ) . + $t_current . '_' . $p_name . + config_get_global( 'db_table_suffix' ); + + return $t_table_name; } /** diff --git a/core/sponsorship_api.php b/core/sponsorship_api.php index 7db800b11f..c094c6d206 100644 --- a/core/sponsorship_api.php +++ b/core/sponsorship_api.php @@ -399,7 +399,7 @@ function sponsorship_delete_all( $p_bug_id ) { $query = "DELETE FROM $t_sponsorship_table WHERE bug_id=" . db_param(); - db_query_bound( $query, $c_bug_id ); + db_query_bound( $query, array( $c_bug_id ) ); sponsorship_clear_cache( ); } diff --git a/lang/strings_english.txt b/lang/strings_english.txt index 1e4772c3c6..9708935685 100644 --- a/lang/strings_english.txt +++ b/lang/strings_english.txt @@ -1621,6 +1621,7 @@ $MANTIS_ERROR[ERROR_LDAP_EXTENSION_NOT_LOADED] = 'LDAP Extension Not Loaded.'; $MANTIS_ERROR[ERROR_DB_CONNECT_FAILED] = 'Database connection failed. Error received from database was #%1$d: %2$s.'; $MANTIS_ERROR[ERROR_DB_QUERY_FAILED] = 'Database query failed. Error received from database was #%1$d: %2$s for the query: %3$s.'; $MANTIS_ERROR[ERROR_DB_SELECT_FAILED] = 'Database selection failed. Error received from database was #%1$d: %2$s.'; +$MANTIS_ERROR[ERROR_DB_IDENTIFIER_TOO_LONG] = 'Database identifier "%1$s" is too long. Try reducing the size of g_db_table_prefix/suffix'; $MANTIS_ERROR[ERROR_CATEGORY_DUPLICATE] = 'A category with that name already exists.'; $MANTIS_ERROR[ERROR_CATEGORY_NO_ACTION] = 'No copy action was specified.'; $MANTIS_ERROR[ERROR_CATEGORY_NOT_FOUND] = 'Category not found.';