View Issue Details

IDProjectCategoryView StatusLast Update
0011916mantisbtbugtrackerpublic2014-09-23 18:05
Reporterjaperez Assigned Todregad  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version1.2.1 
Target Version1.2.9Fixed in Version1.2.9 
Summary0011916: List of user profiles not sorted alphabetically
Description

There is another similar issue: 0010234 (http://www.mantisbt.org/bugs/view.php?id=10234)

The issue was closed (0010234) work properly with global profiles, but when it comes to user profiles does not alphabetically.

When is a comprehensive profile order is implemented by the sql statement, but when a user profile, the result is ordered by the PHP "asort ()" to merge the global profiles and user profiles. If we consider that the result is given by "select * from ..." the order applies depends on the first columns of the table (id, user_id, platform, ...).

Steps To Reproduce
  • User with profiles
  • View Issues Page -> Filter -> Profiles
  • Report Issue Page -> Select Profile
Additional Information

Proposed solution: change the sql statement incorporating the most significant columns to sort the result at the beginning
Module: profile_api.php
Function: profile_get_all_rows
Text:
$query = "SELECT tb.platform as platform_order, tb.os as os_order, tb.os_build as os_build_order, tb.*
FROM $t_user_profile_table tb
WHERE tb.user_id=" . db_param() . "
ORDER BY tb.platform, tb.os, tb.os_build";

Tagspatch
Attached Files
Fix-11916.patch (2,299 bytes)   
From d28b1f731363df34596dd7ff3587aa88b498f9bd Mon Sep 17 00:00:00 2001
From: Damien Regad <damien.regad@merckgroup.com>
Date: Tue, 31 Jan 2012 16:05:48 +0100
Subject: [PATCH] Fix #11916: List of user profiles not sorted alphabetically

---
 core/profile_api.php |   27 ++++++++++++++-------------
 1 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/core/profile_api.php b/core/profile_api.php
index f03e694..3faa3cb 100644
--- a/core/profile_api.php
+++ b/core/profile_api.php
@@ -68,7 +68,7 @@ function profile_create( $p_user_id, $p_platform, $p_os, $p_os_build, $p_descrip
 	return db_insert_id( $t_user_profile_table );
 }
 
-/** 
+/**
  * Delete a profile for the user
  *
  * Note that although profile IDs are currently globally unique, the existing
@@ -190,18 +190,25 @@ function profile_get_row_direct( $p_profile_id ) {
 /**
  * Return an array containing all rows for a given user
  * @param int $p_user_id
+ * @param bool $p_all_users Include profiles for all users
  * @return array
  */
-function profile_get_all_rows( $p_user_id ) {
-	$c_user_id = db_prepare_int( $p_user_id );
-
+function profile_get_all_rows( $p_user_id, $p_all_users = false ) {
 	$t_user_profile_table = db_get_table( 'mantis_user_profile_table' );
 
+	$query_where = 'user_id = ' . db_param();
+	$param[] = db_prepare_int( $p_user_id );
+
+	if( $p_all_users && ALL_USERS != $p_user_id ) {
+		$query_where .= ' OR user_id = ' . db_param();
+		$param[] = ALL_USERS;
+	}
+
 	$query = "SELECT *
 				  FROM $t_user_profile_table
-				  WHERE user_id=" . db_param() . "
+				  WHERE $query_where
 				  ORDER BY platform, os, os_build";
-	$result = db_query_bound( $query, Array( $c_user_id ) );
+	$result = db_query_bound( $query, $param );
 
 	$t_rows = array();
 	$t_row_count = db_num_rows( $result );
@@ -220,13 +227,7 @@ function profile_get_all_rows( $p_user_id ) {
  * @return array
  */
 function profile_get_all_for_user( $p_user_id ) {
-	if( ALL_USERS == $p_user_id ) {
-		return profile_get_all_rows( ALL_USERS );
-	} else {
-		$t_profiles_array = array_merge( profile_get_all_rows( ALL_USERS ), profile_get_all_rows( $p_user_id ) );
-		asort( $t_profiles_array );
-		return $t_profiles_array;
-	}
+	return profile_get_all_rows( $p_user_id, $p_user_id != ALL_USERS );
 }
 
 /**
-- 
1.7.5.4

Fix-11916.patch (2,299 bytes)   

Relationships

related to 0010234 closedgrangeway List of profiles not sorted alphabetically 
related to 0015721 closedgrangeway Functionality to consider porting to master-2.0.x 

Activities

japerez

japerez

2011-08-08 02:09

reporter   ~0029381

one year later .... no comments ??

Avg00r

Avg00r

2012-01-31 06:28

reporter   ~0031090

japerez, I apply your path. So, when I go to bug_report_page.php I get blank page.

dregad

dregad

2012-01-31 10:16

developer   ~0031092

Please try attached patch

dregad

dregad

2012-02-27 19:56

developer   ~0031338

Without feedback from you, I assume that you are satisfied with the fix.

grangeway

grangeway

2013-04-05 17:57

reporter   ~0036379

Marking as 'acknowledged' not resolved/closed to track that change gets ported to master-2.0.x branch

Related Changesets

MantisBT: master 6e1717a6

2012-01-31 02:05

dregad


Details Diff
Fix 0011916: List of user profiles not sorted alphabetically

A new, optional boolean parameter $p_all_users has been added to the
profile_get_all_rows() function, to indicate whether it should return
the list of profiles for the specified user only, or include also the
profiles for all users.

This allows simplification of profile_get_all_for_user()

Conflicts:

core/profile_api.php
Affected Issues
0011916
mod - core/profile_api.php Diff File

MantisBT: master-1.2.x 7caa1801

2012-01-31 02:05

dregad


Details Diff
Fix 0011916: List of user profiles not sorted alphabetically

A new, optional boolean parameter $p_all_users has been added to the
profile_get_all_rows() function, to indicate whether it should return
the list of profiles for the specified user only, or include also the
profiles for all users.

This allows simplification of profile_get_all_for_user()
Affected Issues
0011916
mod - core/profile_api.php Diff File