From fead6728936af690a0e6309227c221c88171b92c Mon Sep 17 00:00:00 2001 From: Paul Richards Date: Fri, 27 Jul 2007 23:23:20 +0000 Subject: [PATCH] 0008130: Custom relationships Include this patch mainly as I believe it does tidy up the existing API for future use. If someone feels that the customisation part of this could cause support issues, i'd be inclined to remove the 3 lines relating to this part, as per my comment in bug 8130 git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@4498 f5dc347c-c33d-0410-90a0-b07cc1902cb9 --- core/email_api.php | 53 +++-------- core/relationship_api.php | 160 ++++++++++++++------------------ core/relationship_graph_api.php | 34 ++----- 3 files changed, 89 insertions(+), 158 deletions(-) diff --git a/core/email_api.php b/core/email_api.php index 2381c20bba..0958e710f5 100644 --- a/core/email_api.php +++ b/core/email_api.php @@ -6,7 +6,7 @@ # See the README and LICENSE files for details # -------------------------------------------------------- - # $Id: email_api.php,v 1.136 2007-07-25 08:30:59 vboctor Exp $ + # $Id: email_api.php,v 1.137 2007-07-27 23:23:20 prichards Exp $ # -------------------------------------------------------- $t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR; @@ -19,6 +19,7 @@ require_once( $t_core_dir . 'string_api.php' ); require_once( $t_core_dir . 'history_api.php' ); require_once( $t_core_dir . 'email_queue_api.php' ); + require_once( $t_core_dir . 'relationship_api.php' ); require_once( 'disposable' . DIRECTORY_SEPARATOR . 'disposable.php' ); require_once( PHPMAILER_PATH . 'class.phpmailer.php' ); @@ -499,26 +500,11 @@ function email_generic( $p_bug_id, $p_notify_type, $p_message_id = null, $p_head function email_relationship_added( $p_bug_id, $p_related_bug_id, $p_rel_type ) { $t_opt = array(); $t_opt[] = bug_format_id( $p_related_bug_id ); - switch ( $p_rel_type ) { - case BUG_BLOCKS: - email_generic( $p_bug_id, 'relation', 'email_notification_title_for_action_blocks_relationship_added', $t_opt ); - break; - case BUG_DEPENDANT: - email_generic( $p_bug_id, 'relation', 'email_notification_title_for_action_dependant_on_relationship_added', $t_opt ); - break; - case BUG_HAS_DUPLICATE: - email_generic( $p_bug_id, 'relation', 'email_notification_title_for_action_has_duplicate_relationship_added', $t_opt ); - break; - case BUG_DUPLICATE: - email_generic( $p_bug_id, 'relation', 'email_notification_title_for_action_duplicate_of_relationship_added', $t_opt ); - break; - case BUG_RELATED: - email_generic( $p_bug_id, 'relation', 'email_notification_title_for_action_related_to_relationship_added', $t_opt ); - break; - default: - trigger_error( ERROR_RELATIONSHIP_NOT_FOUND, ERROR ); - break; - } + global $g_relationships; + if ( !isset( $g_relationships[ $p_rel_type ] ) ) { + trigger_error( ERROR_RELATIONSHIP_NOT_FOUND, ERROR ); + } + email_generic( $p_bug_id, 'relation', $g_relationships[ $p_rel_type ][ '#notify_added' ], $t_opt ); } # -------------------- @@ -527,26 +513,11 @@ function email_relationship_added( $p_bug_id, $p_related_bug_id, $p_rel_type ) { function email_relationship_deleted( $p_bug_id, $p_related_bug_id, $p_rel_type ) { $t_opt = array(); $t_opt[] = bug_format_id( $p_related_bug_id ); - switch ( $p_rel_type ) { - case BUG_BLOCKS: - email_generic( $p_bug_id, 'relation', 'email_notification_title_for_action_blocks_relationship_deleted', $t_opt ); - break; - case BUG_DEPENDANT: - email_generic( $p_bug_id, 'relation', 'email_notification_title_for_action_dependant_on_relationship_deleted', $t_opt ); - break; - case BUG_HAS_DUPLICATE: - email_generic( $p_bug_id, 'relation', 'email_notification_title_for_action_has_duplicate_relationship_deleted', $t_opt ); - break; - case BUG_DUPLICATE: - email_generic( $p_bug_id, 'relation', 'email_notification_title_for_action_duplicate_of_relationship_deleted', $t_opt ); - break; - case BUG_RELATED: - email_generic( $p_bug_id, 'relation', 'email_notification_title_for_action_related_to_relationship_deleted', $t_opt ); - break; - default: - trigger_error( ERROR_RELATIONSHIP_NOT_FOUND, ERROR ); - break; - } + global $g_relationships; + if ( !isset( $g_relationships[ $p_rel_type ] ) ) { + trigger_error( ERROR_RELATIONSHIP_NOT_FOUND, ERROR ); + } + email_generic( $p_bug_id, 'relation', $g_relationships[ $p_rel_type ][ '#notify_deleted' ], $t_opt ); } # -------------------- diff --git a/core/relationship_api.php b/core/relationship_api.php index 4193007d47..656091a13b 100644 --- a/core/relationship_api.php +++ b/core/relationship_api.php @@ -6,7 +6,7 @@ # See the README and LICENSE files for details # -------------------------------------------------------- - # $Id: relationship_api.php,v 1.43 2007-07-18 22:55:24 giallu Exp $ + # $Id: relationship_api.php,v 1.44 2007-07-27 23:23:20 prichards Exp $ # -------------------------------------------------------- ### Relationship API ### @@ -67,43 +67,72 @@ class BugRelationshipData { var $dest_project_id; var $type; } + + $g_relationships = array(); + $g_relationships[ BUG_DEPENDANT ] = array( + '#forward' => TRUE, + '#complementary' => BUG_BLOCKS, + '#description' => 'dependant_on', + '#notify_added' => 'email_notification_title_for_action_dependant_on_relationship_added', + '#notify_deleted' => 'email_notification_title_for_action_dependant_on_relationship_deleted', + '#edge_style' => array ('color' => '#C00000','dir' => 'back'), + ); + $g_relationships[ BUG_BLOCKS ] = array( + '#forward' => FALSE, + '#complementary' => BUG_DEPENDANT, + '#description' => 'blocks', + '#notify_added' => 'email_notification_title_for_action_blocks_relationship_added', + '#notify_deleted' => 'email_notification_title_for_action_blocks_relationship_deleted', + '#edge_style' => array ('color' => '#C00000','dir' => 'forward'), + ); + $g_relationships[ BUG_DUPLICATE ] = array( + '#forward' => TRUE, + '#complementary' => BUG_HAS_DUPLICATE, + '#description' => 'duplicate_of', + '#notify_added' => 'email_notification_title_for_action_duplicate_of_relationship_added', + '#notify_deleted' => 'email_notification_title_for_action_duplicate_of_relationship_deleted', + '#edge_style' => array ('style' => 'dashed','color' => '#808080'), + ); + $g_relationships[ BUG_HAS_DUPLICATE ] = array( + '#forward' => FALSE, + '#complementary' => BUG_DUPLICATE, + '#description' => 'has_duplicate', + '#notify_added' => 'email_notification_title_for_action_has_duplicate_relationship_added', + '#notify_deleted' => 'email_notification_title_for_action_has_duplicate_relationship_deleted', + ); + $g_relationships[ BUG_RELATED ] = array( + '#forward' => TRUE, + '#complementary' => BUG_RELATED, + '#description' => 'related_to', + '#notify_added' => 'email_notification_title_for_action_related_to_relationship_added', + '#notify_deleted' => 'email_notification_title_for_action_related_to_relationship_deleted', + ); + + if ( file_exists( dirname( dirname( __FILE__ ) ).DIRECTORY_SEPARATOR.'custom_relationships_inc.php' ) ) { + require_once( dirname( dirname( __FILE__ ) ).DIRECTORY_SEPARATOR.'custom_relationships_inc.php' ); + } + # -------------------- # Return the complementary type of the provided relationship function relationship_get_complementary_type( $p_relationship_type ) { - switch ( $p_relationship_type ) { - case BUG_BLOCKS: - return BUG_DEPENDANT; - break; - case BUG_DEPENDANT: - return BUG_BLOCKS; - break; - case BUG_HAS_DUPLICATE: - return BUG_DUPLICATE; - break; - case BUG_DUPLICATE: - return BUG_HAS_DUPLICATE; - break; - case BUG_RELATED: - return BUG_RELATED; - break; - default: - trigger_error( ERROR_GENERIC, ERROR ); - break; + global $g_relationships; + if ( !isset( $g_relationships[ $p_relationship_type ] ) ) { + trigger_error( ERROR_GENERIC, ERROR ); } + return $g_relationships[ $p_relationship_type ][ '#complementary' ]; } # -------------------- function relationship_add( $p_src_bug_id, $p_dest_bug_id, $p_relationship_type ) { $t_mantis_bug_relationship_table = config_get( 'mantis_bug_relationship_table' ); - if( $p_relationship_type == BUG_BLOCKS || $p_relationship_type == BUG_HAS_DUPLICATE ) { - # BUG_BLOCKS or BUG_HAS_DUPLICATE -> swap src and dest + global $g_relationships; + if ( $g_relationships[ $p_relationship_type ][ '#forward' ] === FALSE ) { $c_src_bug_id = db_prepare_int( $p_dest_bug_id ); $c_dest_bug_id = db_prepare_int( $p_src_bug_id ); $c_relationship_type = db_prepare_int( relationship_get_complementary_type( $p_relationship_type ) ); - } - else { + } else { $c_src_bug_id = db_prepare_int( $p_src_bug_id ); $c_dest_bug_id = db_prepare_int( $p_dest_bug_id ); $c_relationship_type = db_prepare_int( $p_relationship_type ); @@ -129,13 +158,12 @@ function relationship_add( $p_src_bug_id, $p_dest_bug_id, $p_relationship_type ) function relationship_update( $p_relationship_id, $p_src_bug_id, $p_dest_bug_id, $p_relationship_type ) { $t_mantis_bug_relationship_table = config_get( 'mantis_bug_relationship_table' ); - if( $p_relationship_type == BUG_BLOCKS || $p_relationship_type == BUG_HAS_DUPLICATE ) { - # BUG_BLOCKS or BUG_HAS_DUPLICATE -> swap src and dest + global $g_relationships; + if ( $g_relationships[ $p_relationship_type ][ '#forward' ] === FALSE ) { $c_src_bug_id = db_prepare_int( $p_dest_bug_id ); $c_dest_bug_id = db_prepare_int( $p_src_bug_id ); $c_relationship_type = db_prepare_int( relationship_get_complementary_type( $p_relationship_type ) ); - } - else { + } else { $c_src_bug_id = db_prepare_int( $p_src_bug_id ); $c_dest_bug_id = db_prepare_int( $p_dest_bug_id ); $c_relationship_type = db_prepare_int( $p_relationship_type ); @@ -412,61 +440,28 @@ function relationship_get_linked_bug_id( $p_relationship_id, $p_bug_id ) { # -------------------- # get class description of a relationship (source side) function relationship_get_description_src_side( $p_relationship_type ) { - switch ( $p_relationship_type ) { - case BUG_DUPLICATE: - return lang_get( 'duplicate_of' ); - break; - case BUG_RELATED: - return lang_get( 'related_to' ) ; - break; - case BUG_DEPENDANT: - return lang_get( 'dependant_on' ) ; - break; - default: - trigger_error( ERROR_RELATIONSHIP_NOT_FOUND, ERROR ); + global $g_relationships; + if ( !isset( $g_relationships[ $p_relationship_type ] ) ) { + trigger_error( ERROR_RELATIONSHIP_NOT_FOUND, ERROR ); } + return lang_get( $g_relationships[ $p_relationship_type ][ '#description' ] ); } # -------------------- # get class description of a relationship (destination side) function relationship_get_description_dest_side( $p_relationship_type ) { - switch ( $p_relationship_type ) { - case BUG_DUPLICATE: - return lang_get( 'has_duplicate' ) ; - break; - case BUG_RELATED: - return lang_get( 'related_to' ) ; - break; - case BUG_DEPENDANT: - return lang_get( 'blocks' ) ; - break; - default: - trigger_error( ERROR_RELATIONSHIP_NOT_FOUND, ERROR ); + global $g_relationships; + if ( !isset( $g_relationships[ $p_relationship_type ] ) || + !isset( $g_relationships[ $g_relationships[ $p_relationship_type ][ '#complementary' ] ] ) ) { + trigger_error( ERROR_RELATIONSHIP_NOT_FOUND, ERROR ); } + return lang_get( $g_relationships[ $g_relationships[ $p_relationship_type ][ '#complementary' ] ][ '#description' ] ); } # -------------------- # get class description of a relationship as it's stored in the history function relationship_get_description_for_history( $p_relationship_code ) { - switch ( $p_relationship_code ) { - case BUG_HAS_DUPLICATE: - return lang_get( 'has_duplicate' ) ; - break; - case BUG_DUPLICATE: - return lang_get( 'duplicate_of' ); - break; - case BUG_BLOCKS: - return lang_get( 'blocks' ) ; - break; - case BUG_DEPENDANT: - return lang_get( 'dependant_on' ) ; - break; - case BUG_RELATED: - return lang_get( 'related_to' ) ; - break; - default: - trigger_error( ERROR_RELATIONSHIP_NOT_FOUND, ERROR ); - } + return relationship_get_description_src_side( $p_relationship_code ); } # -------------------- @@ -683,6 +678,7 @@ function relationship_get_summary_text( $p_bug_id ) { # -------------------- # print HTML relationship listbox function relationship_list_box( $p_default_rel_type = -1, $p_select_name = "rel_type", $p_include_any = false, $p_include_none = false ) { + global $g_relationships; ?> - $relationship ) { ?> - 'dashed', - 'color' => '#808080' - ); - break; - - case BUG_DEPENDANT: - $t_edge_style = array ( - 'color' => '#C00000', - 'dir' => 'back' - ); - break; - - case BUG_BLOCKS: - $t_edge_style = array ( - 'color' => '#C00000', - 'dir' => 'forward' - ); - break; - - default: - $t_edge_style = array ( ); - break; - } + global $g_relationships; + if ( isset( $g_relationships[ $t_relation ] ) && isset( $g_relationships[ $t_relation ][ '#edge_style' ] ) ) { + $t_edge_style = $g_relationships[ $t_relation ][ '#edge_style' ]; + } else { + $t_edge_style = array ( ); + } $t_graph->add_edge( $t_id_string, $t_related_id, $t_edge_style ); }