Skip to content

Commit

Permalink
First phase of bug #8435: Implement Global and Inheriting Categories …
Browse files Browse the repository at this point in the history
…Structure.

Implemented category ID behaviors to replicate all existing functionality.


git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@4770 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
amyreese committed Nov 20, 2007
1 parent 375360c commit 829889d
Show file tree
Hide file tree
Showing 30 changed files with 417 additions and 286 deletions.
1 change: 1 addition & 0 deletions admin/install.php
Expand Up @@ -28,6 +28,7 @@
$g_skip_open_db = true; # don't open the database in database_api.php
define( 'PLUGINS_DISABLED', true );
@require_once( dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'core.php' );
@require_once( 'install_functions.php' );
$g_error_send_page_header = false; # bypass page headers in error handler

define( 'BAD', 0 );
Expand Down
64 changes: 64 additions & 0 deletions admin/install_functions.php
@@ -0,0 +1,64 @@
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the README and LICENSE files for details

# --------------------------------------------------------
# $Id: $
# --------------------------------------------------------

/**
* Update functions for the installation schema's 'UpdateFunction' option.
* All functions must be name install_<function_name> and referenced as just <function_name>.
*/

/**
* Migrate the legacy category data to the new category_id-based schema.
*/
function install_category_migrate() {
$t_bug_table = db_get_table( 'mantis_bug_table' );
$t_category_table = db_get_table( 'mantis_category_table' );
$t_project_category_table = db_get_table( 'mantis_project_category_table' );

$query = "SELECT project_id, category FROM $t_project_category_table ORDER BY project_id, category";
$t_category_result = db_query( $query );

$query = "SELECT project_id, category FROM $t_bug_table ORDER BY project_id, category";
$t_bug_result = db_query( $query );

$t_data = Array();

# Find categories specified by project
while ( $row = db_fetch_array( $t_category_result ) ) {
$t_project_id = $row['project_id'];
$t_name = $row['category'];
$t_data[$t_project_id][$t_name] = true;
}

# Find orphaned categories from bugs
while ( $row = db_fetch_array( $t_bug_result ) ) {
$t_project_id = $row['project_id'];
$t_name = $row['category'];

$t_data[$t_project_id][$t_name] = true;
}

# In every project, go through all the categories found, and create them and update the bug
foreach ( $t_data as $t_project_id => $t_categories ) {
foreach ( $t_categories as $t_name => $t_true ) {
$query = "INSERT INTO $t_category_table ( name, project_id ) VALUES ( " . db_param(0) . ', ' . db_param(1) . ' )';
db_query_bound( $query, array( $t_name, $t_project_id ) );
$t_category_id = db_insert_id( $t_category_table );

$query = "UPDATE $t_bug_table SET category_id=" . db_param(0) . '
WHERE project_id=' . db_param(1) . ' AND category=' . db_param(2);
db_query_bound( $query, array( $t_category_id, $t_project_id, $t_name ) );
}
}

# return 2 because that's what ADOdb/DataDict does when things happen properly
return 2;
}

18 changes: 18 additions & 0 deletions admin/schema.php
Expand Up @@ -371,4 +371,22 @@

$upgrade[] = Array('AlterColumnSQL', Array( db_get_table( 'mantis_user_pref_table' ), "redirect_delay I NOTNULL DEFAULT 0" ) );
$upgrade[] = Array('AlterColumnSQL', Array( db_get_table( 'mantis_custom_field_table' ), "possible_values X NOTNULL DEFAULT \" '' \"" ) );

$upgrade[] = Array( 'CreateTableSQL', Array( db_get_table( 'mantis_category_table' ), "
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' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS' ) ) );
$upgrade[] = Array( 'CreateIndexSQL', Array( 'idx_project_name', db_get_table( 'mantis_category_table' ), 'project_id, name', array( 'UNIQUE' ) ) );
$upgrade[] = Array( 'InsertData', Array( db_get_table( 'mantis_category_table' ), "
( project_id, user_id, name, status ) VALUES
( '0', '0', 'None', '0' ) " ) );
$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "category_id I UNSIGNED NOTNULL DEFAULT '1'" ) );
$upgrade[] = Array( 'UpdateFunction', "category_migrate" );
$upgrade[] = Array( 'DropColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "category" ) );
$upgrade[] = Array( 'DropTableSQL', Array( db_get_table( 'mantis_project_category_table' ) ) );
$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_table' ), "category_id I UNSIGNED NOTNULL DEFAULT '1'" ) );

?>
4 changes: 2 additions & 2 deletions bug_report.php
Expand Up @@ -44,7 +44,7 @@
$t_bug_data->handler_id = gpc_get_int( 'handler_id', 0 );
$t_bug_data->view_state = gpc_get_int( 'view_state', config_get( 'default_bug_view_status' ) );

$t_bug_data->category = gpc_get_string( 'category', config_get( 'default_bug_category' ) );
$t_bug_data->category_id = gpc_get_int( 'category_id', 0 );
$t_bug_data->reproducibility = gpc_get_int( 'reproducibility', config_get( 'default_bug_reproducibility' ) );
$t_bug_data->severity = gpc_get_int( 'severity', config_get( 'default_bug_severity' ) );
$t_bug_data->priority = gpc_get_int( 'priority', config_get( 'default_bug_priority' ) );
Expand Down Expand Up @@ -171,7 +171,7 @@
?>
<p>
<form method="post" action="<?php echo string_get_bug_report_url() ?>">
<input type="hidden" name="category" value="<?php echo $t_bug_data->category ?>" />
<input type="hidden" name="category_id" value="<?php echo $t_bug_data->category_id ?>" />
<input type="hidden" name="severity" value="<?php echo $t_bug_data->severity ?>" />
<input type="hidden" name="reproducibility" value="<?php echo $t_bug_data->reproducibility ?>" />
<input type="hidden" name="profile_id" value="<?php echo $t_bug_data->profile_id ?>" />
Expand Down
12 changes: 6 additions & 6 deletions bug_report_advanced_page.php
Expand Up @@ -82,7 +82,7 @@
$f_profile_id = 0;
$f_handler_id = $t_bug->handler_id;

$f_category = $t_bug->category;
$f_category_id = $t_bug->category_id;
$f_reproducibility = $t_bug->reproducibility;
$f_severity = $t_bug->severity;
$f_priority = $t_bug->priority;
Expand All @@ -105,7 +105,7 @@
$f_profile_id = gpc_get_int( 'profile_id', 0 );
$f_handler_id = gpc_get_int( 'handler_id', 0 );

$f_category = gpc_get_string( 'category', config_get( 'default_bug_category' ) );
$f_category_id = gpc_get_int( 'category_id', 0 );
$f_reproducibility = gpc_get_int( 'reproducibility', config_get( 'default_bug_reproducibility' ) );
$f_severity = gpc_get_int( 'severity', config_get( 'default_bug_severity' ) );
$f_priority = gpc_get_int( 'priority', config_get( 'default_bug_priority' ) );
Expand Down Expand Up @@ -161,13 +161,13 @@
<?php if ( $t_changed_project ) {
echo "[" . project_get_field( $t_bug->project_id, 'name' ) . "] ";
} ?>
<select <?php echo helper_get_tab_index() ?> name="category">
<select <?php echo helper_get_tab_index() ?> name="category_id">
<?php
if ( is_blank( $f_category ) ) {
if ( 0 === $f_category_id ) {
echo '<option value="" selected="selected">', string_attribute( lang_get( 'select_option' ) ), '</option>';
}

print_category_option_list( $f_category );
print_category_option_list( $f_category_id );
?>
</select>
</td>
Expand Down Expand Up @@ -555,7 +555,7 @@
<?php if ( ON == config_get( 'use_javascript' ) ) { ?>
<script type="text/javascript" language="JavaScript">
<!--
window.document.report_bug_form.category.focus();
window.document.report_bug_form.category_id.focus();
-->
</script>
<?php } ?>
Expand Down
12 changes: 6 additions & 6 deletions bug_report_page.php
Expand Up @@ -73,7 +73,7 @@
access_ensure_project_level( config_get( 'report_bug_threshold' ) );

$f_product_version = $t_bug->version;
$f_category = $t_bug->category;
$f_category_id = $t_bug->category_id;
$f_reproducibility = $t_bug->reproducibility;
$f_severity = $t_bug->severity;
$f_priority = $t_bug->priority;
Expand All @@ -87,7 +87,7 @@
access_ensure_project_level( config_get( 'report_bug_threshold' ) );

$f_product_version = gpc_get_string( 'product_version', '' );
$f_category = gpc_get_string( 'category', config_get( 'default_bug_category' ) );
$f_category_id = gpc_get_int( 'category_id', 0 );
$f_reproducibility = gpc_get_int( 'reproducibility', config_get( 'default_bug_reproducibility' ) );
$f_severity = gpc_get_int( 'severity', config_get( 'default_bug_severity' ) );
$f_priority = gpc_get_int( 'priority', config_get( 'default_bug_priority' ) );
Expand Down Expand Up @@ -143,13 +143,13 @@
<?php if ( $t_changed_project ) {
echo "[" . project_get_field( $t_bug->project_id, 'name' ) . "] ";
} ?>
<select <?php echo helper_get_tab_index() ?> name="category">
<select <?php echo helper_get_tab_index() ?> name="category_id">
<?php
if ( is_blank( $f_category ) ) {
if ( 0 === $f_category_id ) {
echo '<option value="" selected="selected">', string_attribute( lang_get( 'select_option' ) ), '</option>';
}

print_category_option_list( $f_category );
print_category_option_list( $f_category_id );
?>
</select>
</td>
Expand Down Expand Up @@ -385,7 +385,7 @@
<?php if ( ON == config_get( 'use_javascript' ) ) { ?>
<script type="text/javascript" language="JavaScript">
<!--
window.document.report_bug_form.category.focus();
window.document.report_bug_form.category_id.focus();
-->
</script>
<?php } ?>
Expand Down
2 changes: 1 addition & 1 deletion bug_update.php
Expand Up @@ -67,7 +67,7 @@
$t_bug_data->status = gpc_get_int( 'status', $t_bug_data->status );
$t_bug_data->resolution = gpc_get_int( 'resolution', $t_bug_data->resolution );
$t_bug_data->projection = gpc_get_int( 'projection', $t_bug_data->projection );
$t_bug_data->category = gpc_get_string( 'category', $t_bug_data->category );
$t_bug_data->category_id = gpc_get_int( 'category_id', $t_bug_data->category_id );
$t_bug_data->eta = gpc_get_int( 'eta', $t_bug_data->eta );
$t_bug_data->os = gpc_get_string( 'os', $t_bug_data->os );
$t_bug_data->os_build = gpc_get_string( 'os_build', $t_bug_data->os_build );
Expand Down
4 changes: 2 additions & 2 deletions bug_update_advanced_page.php
Expand Up @@ -118,8 +118,8 @@
<?php if ( $t_changed_project ) {
echo "[" . project_get_field( $t_bug->project_id, 'name' ) . "] ";
} ?>
<select <?php echo helper_get_tab_index() ?> name="category">
<?php print_category_option_list( $t_bug->category, $t_bug->project_id ) ?>
<select <?php echo helper_get_tab_index() ?> name="category_id">
<?php print_category_option_list( $t_bug->category_id, $t_bug->project_id ) ?>
</select>
</td>

Expand Down
4 changes: 2 additions & 2 deletions bug_update_page.php
Expand Up @@ -121,8 +121,8 @@
<?php if ( $t_changed_project ) {
echo "[" . project_get_field( $t_bug->project_id, 'name' ) . "] ";
} ?>
<select <?php echo helper_get_tab_index() ?> name="category">
<?php print_category_option_list( $t_bug->category, $t_bug->project_id ) ?>
<select <?php echo helper_get_tab_index() ?> name="category_id">
<?php print_category_option_list( $t_bug->category_id, $t_bug->project_id ) ?>
</select>
</td>

Expand Down
3 changes: 1 addition & 2 deletions bug_view_advanced_page.php
Expand Up @@ -168,8 +168,7 @@
<!-- Category -->
<td>
<?php
$t_project_name = string_display( project_get_field( $t_bug->project_id, 'name' ) );
echo "[$t_project_name] $t_bug->category";
echo string_display( category_full_name( $t_bug->category_id ) );
?>
</td>

Expand Down
3 changes: 1 addition & 2 deletions bug_view_page.php
Expand Up @@ -171,8 +171,7 @@
<!-- Category -->
<td>
<?php
$t_project_name = string_display( project_get_field( $t_bug->project_id, 'name' ) );
echo "[$t_project_name] $t_bug->category";
echo string_display( category_full_name( $t_bug->category_id ) );
?>
</td>

Expand Down
4 changes: 1 addition & 3 deletions config_defaults_inc.php
Expand Up @@ -684,9 +684,6 @@
# Default bug reproducibility when reporting a new bug
$g_default_bug_reproducibility = REPRODUCIBILITY_HAVENOTTRIED;

# Default bug category when reporting a new bug
$g_default_bug_category = '';

# --- viewing defaults ------------
# site defaults for viewing preferences
$g_default_limit_view = 50;
Expand Down Expand Up @@ -1370,6 +1367,7 @@
$g_db_table['mantis_bug_text_table'] = '%db_table_prefix%_bug_text%db_table_suffix%';
$g_db_table['mantis_bugnote_table'] = '%db_table_prefix%_bugnote%db_table_suffix%';
$g_db_table['mantis_bugnote_text_table'] = '%db_table_prefix%_bugnote_text%db_table_suffix%';
$g_db_table['mantis_category_table'] = '%db_table_prefix%_category%db_table_suffix%';
$g_db_table['mantis_news_table'] = '%db_table_prefix%_news%db_table_suffix%';
$g_db_table['mantis_plugin_table'] = '%db_table_prefix%_plugin%db_table_suffix%';
$g_db_table['mantis_project_category_table'] = '%db_table_prefix%_project_category%db_table_suffix%';
Expand Down
35 changes: 15 additions & 20 deletions core/bug_api.php
Expand Up @@ -52,7 +52,7 @@ class BugData {
var $status = NEW_;
var $resolution = OPEN;
var $projection = 10;
var $category = '';
var $category_id = 1;
var $date_submitted = '';
var $last_updated = '';
var $eta = 10;
Expand Down Expand Up @@ -381,7 +381,7 @@ function bug_create( $p_bug_data ) {
$c_priority = db_prepare_int( $p_bug_data->priority );
$c_severity = db_prepare_int( $p_bug_data->severity );
$c_reproducibility = db_prepare_int( $p_bug_data->reproducibility );
$c_category = db_prepare_string( $p_bug_data->category );
$c_category_id = db_prepare_int( $p_bug_data->category_id );
$c_os = db_prepare_string( $p_bug_data->os );
$c_os_build = db_prepare_string( $p_bug_data->os_build );
$c_platform = db_prepare_string( $p_bug_data->platform );
Expand All @@ -406,11 +406,6 @@ function bug_create( $p_bug_data ) {
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}

if ( is_blank( $c_category ) ) {
error_parameters( lang_get( 'category' ) );
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}

# Only set target_version if user has access to do so
if ( access_has_project_level( config_get( 'roadmap_update_threshold' ) ) ) {
$c_target_version = db_prepare_string( $p_bug_data->target_version );
Expand All @@ -420,7 +415,7 @@ function bug_create( $p_bug_data ) {

$t_bug_table = db_get_table( 'mantis_bug_table' );
$t_bug_text_table = db_get_table( 'mantis_bug_text_table' );
$t_project_category_table = db_get_table( 'mantis_project_category_table' );
$t_category_table = db_get_table( 'mantis_category_table' );

# Insert text information
$query = "INSERT INTO $t_bug_text_table
Expand All @@ -443,9 +438,9 @@ function bug_create( $p_bug_data ) {
# if a default user is associated with the category and we know at this point
# that that the bug was not assigned to somebody, then assign it automatically.
$query = "SELECT user_id
FROM $t_project_category_table
WHERE project_id=" .db_param(0) . " AND category=" . db_param(1);
$result = db_query_bound( $query, Array( $c_project_id, $c_category ) );
FROM $t_category_table
WHERE project_id=" . db_param(0) . ' AND id=' . db_param(1);
$result = db_query_bound( $query, array( $c_project_id, $c_category_id ) );

if ( db_num_rows( $result ) > 0 ) {
$c_handler_id = $p_handler_id = db_result( $result );
Expand All @@ -466,7 +461,7 @@ function bug_create( $p_bug_data ) {
duplicate_id, priority,
severity, reproducibility,
status, resolution,
projection, category,
projection, category_id,
date_submitted, last_updated,
eta, bug_text_id,
os, os_build,
Expand All @@ -481,7 +476,7 @@ function bug_create( $p_bug_data ) {
'0', '$c_priority',
'$c_severity', '$c_reproducibility',
'$t_status', '$t_resolution',
10, '$c_category',
10, '$c_category_id',
" . db_now() . "," . db_now() . ",
10, '$t_text_id',
'$c_os', '$c_os_build',
Expand Down Expand Up @@ -782,8 +777,8 @@ function bug_delete_all( $p_project_id ) {

$query = "SELECT id
FROM $t_bug_table
WHERE project_id='$c_project_id'";
$result = db_query( $query );
WHERE project_id=" . db_param(0);
$result = db_query_bound( $query, array( $c_project_id ) );

$bug_count = db_num_rows( $result );

Expand Down Expand Up @@ -845,7 +840,7 @@ function bug_update( $p_bug_id, $p_bug_data, $p_update_extended = false, $p_bypa
status='$c_bug_data->status',
resolution='$c_bug_data->resolution',
projection='$c_bug_data->projection',
category='$c_bug_data->category',
category_id='$c_bug_data->category_id',
eta='$c_bug_data->eta',
os='$c_bug_data->os',
os_build='$c_bug_data->os_build',
Expand Down Expand Up @@ -882,7 +877,7 @@ function bug_update( $p_bug_id, $p_bug_data, $p_update_extended = false, $p_bypa
history_log_event_direct( $p_bug_id, 'status', $t_old_data->status, $p_bug_data->status );
history_log_event_direct( $p_bug_id, 'resolution', $t_old_data->resolution, $p_bug_data->resolution );
history_log_event_direct( $p_bug_id, 'projection', $t_old_data->projection, $p_bug_data->projection );
history_log_event_direct( $p_bug_id, 'category', $t_old_data->category, $p_bug_data->category );
history_log_event_direct( $p_bug_id, 'category', category_full_name( $t_old_data->category_id, false ), category_full_name( $p_bug_data->category_id, false ) );
history_log_event_direct( $p_bug_id, 'eta', $t_old_data->eta, $p_bug_data->eta );
history_log_event_direct( $p_bug_id, 'os', $t_old_data->os, $p_bug_data->os );
history_log_event_direct( $p_bug_id, 'os_build', $t_old_data->os_build, $p_bug_data->os_build );
Expand Down Expand Up @@ -1457,7 +1452,7 @@ function bug_prepare_db( $p_bug_data ) {
$t_bug_data->status = db_prepare_int( $p_bug_data->status );
$t_bug_data->resolution = db_prepare_int( $p_bug_data->resolution );
$t_bug_data->projection = db_prepare_int( $p_bug_data->projection );
$t_bug_data->category = db_prepare_string( $p_bug_data->category );
$t_bug_data->category_id = db_prepare_int( $p_bug_data->category_id );
$t_bug_data->date_submitted = db_prepare_string( $p_bug_data->date_submitted );
$t_bug_data->last_updated = db_prepare_string( $p_bug_data->last_updated );
$t_bug_data->eta = db_prepare_int( $p_bug_data->eta );
Expand All @@ -1484,7 +1479,7 @@ function bug_prepare_db( $p_bug_data ) {
# Return a copy of the bug structure with all the instvars prepared for editing
# in an HTML form
function bug_prepare_edit( $p_bug_data ) {
$p_bug_data->category = string_attribute( $p_bug_data->category );
$p_bug_data->category_id = string_attribute( $p_bug_data->category_id );
$p_bug_data->date_submitted = string_attribute( $p_bug_data->date_submitted );
$p_bug_data->last_updated = string_attribute( $p_bug_data->last_updated );
$p_bug_data->os = string_attribute( $p_bug_data->os );
Expand All @@ -1508,7 +1503,7 @@ function bug_prepare_edit( $p_bug_data ) {
# Return a copy of the bug structure with all the instvars prepared for editing
# in an HTML form
function bug_prepare_display( $p_bug_data ) {
$p_bug_data->category = string_display_line( $p_bug_data->category );
$p_bug_data->category_id = string_display_line( $p_bug_data->category_id );
$p_bug_data->date_submitted = string_display_line( $p_bug_data->date_submitted );
$p_bug_data->last_updated = string_display_line( $p_bug_data->last_updated );
$p_bug_data->os = string_display_line( $p_bug_data->os );
Expand Down

0 comments on commit 829889d

Please sign in to comment.