Skip to content

Commit

Permalink
Fix #12667: Moving issues between projects doesn't update the category
Browse files Browse the repository at this point in the history
If an issue with category GUI is moved from Project A to Project B (where both have the category defined as non-global), then the issue will show the category name in the view page as "[Project A] GUI" even though the issue now belongs to project B. Also if the user edits the issue, the first category is selected from the list since "[Project A] GUI" is not a valid entry.

The proposed fix is as follows:

1. If the category is global, then leave as is.
2. If the category has a match by name in the target project, then switch to that.
3. If the category doesn't have a match by name in the target project, then move a configured default global category (by default "General").
  • Loading branch information
vboctor committed Jan 7, 2011
1 parent ffd70d4 commit a25d69f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bug_actiongroup.php
Expand Up @@ -101,7 +101,7 @@
if ( access_has_bug_level( config_get( 'move_bug_threshold' ), $t_bug_id ) ) {
/** @todo we need to issue a helper_call_custom_function( 'issue_update_validate', array( $t_bug_id, $t_bug_data, $f_bugnote_text ) ); */
$f_project_id = gpc_get_int( 'project_id' );
bug_set_field( $t_bug_id, 'project_id', $f_project_id );
bug_move( $t_bug_id, $f_project_id );
helper_call_custom_function( 'issue_update_notify', array( $t_bug_id ) );
} else {
$t_failed_ids[$t_bug_id] = lang_get( 'bug_actiongroup_access' );
Expand Down
7 changes: 7 additions & 0 deletions config_defaults_inc.php
Expand Up @@ -1152,6 +1152,13 @@
*/
$g_default_bug_eta = ETA_NONE;

/**
* Default global category to be used when an issue is moved from a project to another
* that doesn't have a category with a matching name. The default is 1 which is the "General"
* category that is created in the default database.
*/
$g_default_category_for_moves = 1;

/**
*
* @global int $g_default_limit_view
Expand Down
30 changes: 30 additions & 0 deletions core/bug_api.php
Expand Up @@ -1072,6 +1072,36 @@ function bug_copy( $p_bug_id, $p_target_project_id = null, $p_copy_custom_fields
return $t_new_bug_id;
}

/**
* Moves an issue from a project to another.
* @todo Validate with sub-project / category inheritance scenarios.
* @todo Fix #11687: Bugs with attachments that are moved will lose attachments.
* @param int p_bug_id The bug to be moved.
* @param int p_target_project_id The target project to move the bug to.
* @access public
*/
function bug_move( $p_bug_id, $p_target_project_id ) {
// Move the issue to the new project.
bug_set_field( $p_bug_id, 'project_id', $p_target_project_id );

// Check if the category for the issue is global or not.
$t_category_id = bug_get_field( $p_bug_id, 'category_id' );
$t_category_project_id = category_get_field( $t_category_id, 'project_id' );

// If not global, then attempt mapping it to the new project.
if ( $t_category_project_id != ALL_PROJECTS ) {
// Map by name
$t_category_name = category_get_field( $t_category_id, 'name' );
$t_target_project_category_id = category_get_id_by_name( $t_category_name, $p_target_project_id, /* triggerErrors */ false );
if ( $t_target_project_category_id === false ) {
// Use default category after moves, since there is no match by name.
$t_target_project_category_id = config_get( 'default_category_for_moves' );
}

bug_set_field( $p_bug_id, 'category_id', $t_target_project_category_id );
}
}

/**
* allows bug deletion :
* delete the bug, bugtext, bugnote, and bugtexts selected
Expand Down
10 changes: 10 additions & 0 deletions docbook/adminguide/en/configuration.sgml
Expand Up @@ -1086,6 +1086,16 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>$g_default_category_for_moves</term>
<listitem>
<para>
Default global category to be used when an issue is moved from a project to another
that doesn't have a category with a matching name. The default is 1 which is the "General"
category that is created in the default database.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>$g_default_limit_view</term>
<listitem>
Expand Down

0 comments on commit a25d69f

Please sign in to comment.