Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ef3759c

Browse files
committedOct 6, 2011
Fixes moving of bugs without category
Prior to this, attempting to move an issue with no category set (allowed with $g_allow_no_category = ON) to another project generated error 1502. Now, Mantis will successfully move the issue, and also set the category to the default value if it is mandatory in the target project. Fixes #13341
1 parent 55c53f1 commit ef3759c

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed
 

‎core/bug_api.php

+34-23
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ public function __get($name) {
186186
$this->fetch_extended_info();
187187
return $this->{$name};
188188
}
189-
189+
190190
/**
191191
* @private
192192
*/
193-
public function __isset($name) {
193+
public function __isset($name) {
194194
return isset( $this->{$name} );
195195
}
196196

@@ -206,13 +206,13 @@ public function loadrow( $p_row ) {
206206
}
207207
$this->loading = false;
208208
}
209-
209+
210210
/**
211211
* Retrieves extended information for bug (e.g. bug description)
212212
* @return null
213213
*/
214214
private function fetch_extended_info() {
215-
if ( $this->description == '' ) {
215+
if ( $this->description == '' ) {
216216
$t_text = bug_text_cache_row($this->id);
217217

218218
$this->description = $t_text['description'];
@@ -1054,21 +1054,32 @@ function bug_move( $p_bug_id, $p_target_project_id ) {
10541054
// Move the issue to the new project.
10551055
bug_set_field( $p_bug_id, 'project_id', $p_target_project_id );
10561056

1057-
// Check if the category for the issue is global or not.
1057+
// Update the category if needed
10581058
$t_category_id = bug_get_field( $p_bug_id, 'category_id' );
1059-
$t_category_project_id = category_get_field( $t_category_id, 'project_id' );
1060-
1061-
// If not global, then attempt mapping it to the new project.
1062-
if ( $t_category_project_id != ALL_PROJECTS && !project_hierarchy_inherit_parent( $p_target_project_id, $t_category_project_id ) ) {
1063-
// Map by name
1064-
$t_category_name = category_get_field( $t_category_id, 'name' );
1065-
$t_target_project_category_id = category_get_id_by_name( $t_category_name, $p_target_project_id, /* triggerErrors */ false );
1066-
if ( $t_target_project_category_id === false ) {
1067-
// Use default category after moves, since there is no match by name.
1068-
$t_target_project_category_id = config_get( 'default_category_for_moves' );
1069-
}
10701059

1071-
bug_set_field( $p_bug_id, 'category_id', $t_target_project_category_id );
1060+
// Bug has no category
1061+
if( $t_category_id == 0 ) {
1062+
// Category is required in target project, set it to default
1063+
if( ON != config_get( 'allow_no_category', null, null, $p_target_project_id ) ) {
1064+
bug_set_field( $p_bug_id, 'category_id', config_get( 'default_category_for_moves' ) );
1065+
}
1066+
}
1067+
// Check if the category is global, and if not attempt mapping it to the new project
1068+
else {
1069+
$t_category_project_id = category_get_field( $t_category_id, 'project_id' );
1070+
1071+
if ( $t_category_project_id != ALL_PROJECTS
1072+
&& !project_hierarchy_inherit_parent( $p_target_project_id, $t_category_project_id )
1073+
) {
1074+
// Map by name
1075+
$t_category_name = category_get_field( $t_category_id, 'name' );
1076+
$t_target_project_category_id = category_get_id_by_name( $t_category_name, $p_target_project_id, /* triggerErrors */ false );
1077+
if ( $t_target_project_category_id === false ) {
1078+
// Use default category after moves, since there is no match by name.
1079+
$t_target_project_category_id = config_get( 'default_category_for_moves' );
1080+
}
1081+
bug_set_field( $p_bug_id, 'category_id', $t_target_project_category_id );
1082+
}
10721083
}
10731084
}
10741085

@@ -1735,16 +1746,16 @@ function bug_monitor( $p_bug_id, $p_user_id ) {
17351746

17361747
/**
17371748
* Returns the list of users monitoring the specified bug
1738-
*
1749+
*
17391750
* @param int $p_bug_id
17401751
*/
17411752
function bug_get_monitors( $p_bug_id ) {
1742-
1753+
17431754
if ( ! access_has_bug_level( config_get( 'show_monitor_list_threshold' ), $p_bug_id ) ) {
17441755
return Array();
17451756
}
1746-
1747-
1757+
1758+
17481759
$c_bug_id = db_prepare_int( $p_bug_id );
17491760
$t_bug_monitor_table = db_get_table( 'mantis_bug_monitor_table' );
17501761
$t_user_table = db_get_table( 'mantis_user_table' );
@@ -1762,9 +1773,9 @@ function bug_get_monitors( $p_bug_id ) {
17621773
$row = db_fetch_array( $result );
17631774
$t_users[$i] = $row['user_id'];
17641775
}
1765-
1776+
17661777
user_cache_array_rows( $t_users );
1767-
1778+
17681779
return $t_users;
17691780
}
17701781

0 commit comments

Comments
 (0)
Please sign in to comment.