Skip to content

Commit

Permalink
Fixes moving of bugs without category
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dregad committed Oct 6, 2011
1 parent 55c53f1 commit ef3759c
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions core/bug_api.php
Expand Up @@ -186,11 +186,11 @@ public function __get($name) {
$this->fetch_extended_info();
return $this->{$name};
}

/**
* @private
*/
public function __isset($name) {
public function __isset($name) {
return isset( $this->{$name} );
}

Expand All @@ -206,13 +206,13 @@ public function loadrow( $p_row ) {
}
$this->loading = false;
}

/**
* Retrieves extended information for bug (e.g. bug description)
* @return null
*/
private function fetch_extended_info() {
if ( $this->description == '' ) {
if ( $this->description == '' ) {
$t_text = bug_text_cache_row($this->id);

$this->description = $t_text['description'];
Expand Down Expand Up @@ -1054,21 +1054,32 @@ 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.
// Update the category if needed
$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 && !project_hierarchy_inherit_parent( $p_target_project_id, $t_category_project_id ) ) {
// 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 );
// Bug has no category
if( $t_category_id == 0 ) {
// Category is required in target project, set it to default
if( ON != config_get( 'allow_no_category', null, null, $p_target_project_id ) ) {
bug_set_field( $p_bug_id, 'category_id', config_get( 'default_category_for_moves' ) );
}
}
// Check if the category is global, and if not attempt mapping it to the new project
else {
$t_category_project_id = category_get_field( $t_category_id, 'project_id' );

if ( $t_category_project_id != ALL_PROJECTS
&& !project_hierarchy_inherit_parent( $p_target_project_id, $t_category_project_id )
) {
// 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 );
}
}
}

Expand Down Expand Up @@ -1735,16 +1746,16 @@ function bug_monitor( $p_bug_id, $p_user_id ) {

/**
* Returns the list of users monitoring the specified bug
*
*
* @param int $p_bug_id
*/
function bug_get_monitors( $p_bug_id ) {

if ( ! access_has_bug_level( config_get( 'show_monitor_list_threshold' ), $p_bug_id ) ) {
return Array();
}


$c_bug_id = db_prepare_int( $p_bug_id );
$t_bug_monitor_table = db_get_table( 'mantis_bug_monitor_table' );
$t_user_table = db_get_table( 'mantis_user_table' );
Expand All @@ -1762,9 +1773,9 @@ function bug_get_monitors( $p_bug_id ) {
$row = db_fetch_array( $result );
$t_users[$i] = $row['user_id'];
}

user_cache_array_rows( $t_users );

return $t_users;
}

Expand Down

0 comments on commit ef3759c

Please sign in to comment.