From a25d69fcabebd0d196770e0a3af8d030212f076e Mon Sep 17 00:00:00 2001 From: Victor Boctor Date: Fri, 7 Jan 2011 12:55:31 -0800 Subject: [PATCH] Fix #12667: Moving issues between projects doesn't update the category 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"). --- bug_actiongroup.php | 2 +- config_defaults_inc.php | 7 ++++++ core/bug_api.php | 30 ++++++++++++++++++++++++ docbook/adminguide/en/configuration.sgml | 10 ++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/bug_actiongroup.php b/bug_actiongroup.php index 26e8edfa19..078ebf018e 100644 --- a/bug_actiongroup.php +++ b/bug_actiongroup.php @@ -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' ); diff --git a/config_defaults_inc.php b/config_defaults_inc.php index ec3b9637a5..8406f9e73f 100644 --- a/config_defaults_inc.php +++ b/config_defaults_inc.php @@ -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 diff --git a/core/bug_api.php b/core/bug_api.php index 279fa202c8..e92921b9c7 100644 --- a/core/bug_api.php +++ b/core/bug_api.php @@ -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 diff --git a/docbook/adminguide/en/configuration.sgml b/docbook/adminguide/en/configuration.sgml index 72b509badc..2777950cff 100644 --- a/docbook/adminguide/en/configuration.sgml +++ b/docbook/adminguide/en/configuration.sgml @@ -1086,6 +1086,16 @@ + + $g_default_category_for_moves + + + 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_limit_view