View Issue Details

IDProjectCategoryView StatusLast Update
0007657mantisbtrelationshipspublic2014-11-05 01:53
Reporterpolzin Assigned Tovboctor  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionduplicate 
Product Version1.0.6 
Summary0007657: Relationships are not sorted correctly
Description

Currently, relationships should be sorted by "relation_type", "id".

There is one bug and one suggestion:

  1. As dest and src relations are searched seperately and merged aferwards, not all "related to" are sorted together, as some "related to" may have the current bug id as dest, others as src.

  2. I would find it more sensible to sort regarding the bug_id of the relation, not the relation_id.

The attached patch solves both.

TagsNo tags attached.
Attached Files
patch.txt (5,071 bytes)   
Index: core/relationship_api.php
===================================================================
RCS file: /cvs/TPS/mantis/core/relationship_api.php,v
retrieving revision 1.1.1.7
diff -u -r1.1.1.7 relationship_api.php
--- core/relationship_api.php	28 Jun 2005 11:04:06 -0000	1.1.1.7
+++ core/relationship_api.php	14 Dec 2006 11:22:26 -0000
@@ -242,13 +242,13 @@
 		$t_mantis_bug_relationship_table = config_get( 'mantis_bug_relationship_table' );
 		$t_mantis_bug_table = config_get( 'mantis_bug_table' );
 
+		# ording will be done later
 		$query = "SELECT $t_mantis_bug_relationship_table.id, $t_mantis_bug_relationship_table.relationship_type,
 				$t_mantis_bug_relationship_table.source_bug_id, $t_mantis_bug_relationship_table.destination_bug_id,
 				$t_mantis_bug_table.project_id
 				FROM $t_mantis_bug_relationship_table
 				INNER JOIN $t_mantis_bug_table ON $t_mantis_bug_relationship_table.destination_bug_id = $t_mantis_bug_table.id
-				WHERE source_bug_id='$c_src_bug_id'
-				ORDER BY relationship_type, $t_mantis_bug_relationship_table.id";
+				WHERE source_bug_id='$c_src_bug_id'";
 		$result = db_query( $query );
 
 		$t_src_project_id = bug_get_field( $p_src_bug_id, 'project_id' );
@@ -257,14 +257,15 @@
 		$t_relationship_count = db_num_rows( $result );
 		for ( $i = 0 ; $i < $t_relationship_count ; $i++ ) {
 			$row = db_fetch_array( $result );
-			$t_bug_relationship_data[$i]->id = $row['id'];
-			$t_bug_relationship_data[$i]->src_bug_id = $row['source_bug_id'];
-			$t_bug_relationship_data[$i]->src_project_id = $t_src_project_id;
-			$t_bug_relationship_data[$i]->dest_bug_id = $row['destination_bug_id'];
-			$t_bug_relationship_data[$i]->dest_project_id = $row['project_id'];
-			$t_bug_relationship_data[$i]->type = $row['relationship_type'];
+			$key = $row['relationship_type'] * 2000000 +  $row['destination_bug_id'];
+			$t_bug_relationship_data[$key]->id = $row['id'];
+			$t_bug_relationship_data[$key]->src_bug_id = $row['source_bug_id'];
+			$t_bug_relationship_data[$key]->src_project_id = $row['project_id'];
+			$t_bug_relationship_data[$key]->dest_bug_id = $row['destination_bug_id'];
+			$t_bug_relationship_data[$key]->dest_project_id = $t_dest_project_id;
+			$t_bug_relationship_data[$key]->type = $row['relationship_type'];
 		}
-		unset( $t_bug_relationship_data[$t_relationship_count] );
+		unset( $t_bug_relationship_data[0] );
 
 		return $t_bug_relationship_data;
 	}
@@ -276,13 +277,13 @@
 		$t_mantis_bug_relationship_table = config_get( 'mantis_bug_relationship_table' );
 		$t_mantis_bug_table = config_get( 'mantis_bug_table' );
 
+		# ording will be done later
 		$query = "SELECT $t_mantis_bug_relationship_table.id, $t_mantis_bug_relationship_table.relationship_type,
 				$t_mantis_bug_relationship_table.source_bug_id, $t_mantis_bug_relationship_table.destination_bug_id,
 				$t_mantis_bug_table.project_id
 				FROM $t_mantis_bug_relationship_table
 				INNER JOIN $t_mantis_bug_table ON $t_mantis_bug_relationship_table.source_bug_id = $t_mantis_bug_table.id
-				WHERE destination_bug_id='$c_dest_bug_id'
-				ORDER BY relationship_type, $t_mantis_bug_relationship_table.id";
+				WHERE destination_bug_id='$c_dest_bug_id'";
 		$result = db_query( $query );
 
 		$t_dest_project_id = bug_get_field( $p_dest_bug_id, 'project_id' );
@@ -291,14 +292,16 @@
 		$t_relationship_count = db_num_rows( $result );
 		for ( $i = 0 ; $i < $t_relationship_count ; $i++ ) {
 			$row = db_fetch_array( $result );
-			$t_bug_relationship_data[$i]->id = $row['id'];
-			$t_bug_relationship_data[$i]->src_bug_id = $row['source_bug_id'];
-			$t_bug_relationship_data[$i]->src_project_id = $row['project_id'];
-			$t_bug_relationship_data[$i]->dest_bug_id = $row['destination_bug_id'];
-			$t_bug_relationship_data[$i]->dest_project_id = $t_dest_project_id;
-			$t_bug_relationship_data[$i]->type = $row['relationship_type'];
+			$key = $row['relationship_type'] * 2000000 + 
+				   ( $row['relationship_type'] != BUG_RELATED ? 1000000 : 0	 ) +				   $row['source_bug_id'];
+			$t_bug_relationship_data[$key]->id = $row['id'];
+			$t_bug_relationship_data[$key]->src_bug_id = $row['source_bug_id'];
+			$t_bug_relationship_data[$key]->src_project_id = $row['project_id'];
+			$t_bug_relationship_data[$key]->dest_bug_id = $row['destination_bug_id'];
+			$t_bug_relationship_data[$key]->dest_project_id = $t_dest_project_id;
+			$t_bug_relationship_data[$key]->type = $row['relationship_type'];
 		}
-		unset( $t_bug_relationship_data[$t_relationship_count] );
+		unset( $t_bug_relationship_data[0] );
 
 		return $t_bug_relationship_data;
 	}
@@ -307,7 +310,13 @@
 	function relationship_get_all( $p_bug_id, &$p_is_different_projects ) {
 		$t_src = relationship_get_all_src( $p_bug_id );
 		$t_dest = relationship_get_all_dest( $p_bug_id );
-		$t_all = array_merge( $t_src, $t_dest );
+		# merge
+		$t_all = $t_src + $t_dest;
+		# sort keys
+		ksort( $t_all );
+		# throw away keys
+		$t_all = array_merge( $t_all );
+		
 
 		$p_is_different_projects = false;
 		for ( $i = 0 ; $i < count( $t_all ) ; $i++ ) {
patch.txt (5,071 bytes)   

Relationships

duplicate of 0007390 new Make relationships sortable 
related to 0007656 closedvboctor sort or filter the relations list 
related to 0007332 closedvboctor Sorting relationships within an issue 

Activities

polzin

polzin

2006-12-14 06:29

reporter   ~0013826

Related to 0007656