View Issue Details

IDProjectCategoryView StatusLast Update
0011124mantisbtfilterspublic2014-09-23 18:05
Reporterbrianstv Assigned Todhx  
PriorityurgentSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version1.2.0rc2 
Target Version1.2.9Fixed in Version1.2.9 
Summary0011124: The 'sticky_issues' value stored in the mantis_filter_table is not always stored correctly.
Description

The 'sticky_issues' value stored in the saved filter in the mantis_filter_table should be stored as
s:13:"sticky_issues";s:2:"on";
OR
s:13:"sticky_issues";s:2:"off";

Have discovered that it can default to the following, which is incorrect
s:13:"sticky_issues";i:1

Steps To Reproduce

Symptom is that sticky issues are not displayed with the gray bar after them in the view_issues page when the "sticky_issues" value is not stored in the filter correctly. This can happen when in the view_issues page and changing the Current Project dropdown to a project that the user does not have a saved filter for.

Additional Information

This seems to happen when the default for filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] is taken from config_get('show_sticky_issues') and is not saved as 'on' or 'off'.

Problem found in core/filter_api.php, view_all_set.php and search.php doesn't even set a default if a value is not already present.

Tagspatch
Attached Files
11124.patch (2,161 bytes)   
From a039351ac2857424e4a890192d5ce96b48709ec2 Mon Sep 17 00:00:00 2001
From: Victor Boctor <vboctor@gmail.com>
Date: Wed, 4 Nov 2009 19:33:20 -0800
Subject: [PATCH] Fixes #11124: The 'sticky_issues' value stored in the mantis_filter_table is not always stored correctly.

---
 core/filter_api.php |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/core/filter_api.php b/core/filter_api.php
index 503643c..0194aa9 100644
--- a/core/filter_api.php
+++ b/core/filter_api.php
@@ -459,7 +459,7 @@ function filter_ensure_valid_filter( $p_filter_arr ) {
 		$p_filter_arr[FILTER_PROPERTY_HIGHLIGHT_CHANGED] = config_get( 'default_show_changed' );
 	}
 	if( !isset( $p_filter_arr[FILTER_PROPERTY_SHOW_STICKY_ISSUES] ) ) {
-		$p_filter_arr[FILTER_PROPERTY_SHOW_STICKY_ISSUES] = config_get( 'show_sticky_issues' );
+		$p_filter_arr[FILTER_PROPERTY_SHOW_STICKY_ISSUES] = gpc_string_to_bool( config_get( 'show_sticky_issues' ) );
 	}
 	if( !isset( $p_filter_arr[FILTER_PROPERTY_SORT_FIELD_NAME] ) ) {
 		$p_filter_arr[FILTER_PROPERTY_SORT_FIELD_NAME] = "last_updated";
@@ -899,7 +899,7 @@ function filter_get_query_sort_data( &$p_filter, $p_show_sticky, $p_query_clause
 	$t_sort_fields = explode( ',', $p_filter[FILTER_PROPERTY_SORT_FIELD_NAME] );
 	$t_dir_fields = explode( ',', $p_filter[FILTER_PROPERTY_SORT_DIRECTION] );
 
-	if(( 'on' == $p_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] ) && ( NULL !== $p_show_sticky ) ) {
+	if ( gpc_string_to_bool( $p_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] ) && ( NULL !== $p_show_sticky ) ) {
 		$p_query_clauses['order'][] = "sticky DESC";
 	}
 
@@ -3722,7 +3722,7 @@ function print_filter_view_state() {
 function print_filter_sticky_issues() {
 	global $t_filter;
 	?><!-- Show or hide sticky bugs -->
-			<input type="checkbox" name="<?php echo FILTER_PROPERTY_SHOW_STICKY_ISSUES;?>" <?php check_checked( gpc_string_to_bool( $t_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] ), 'on' );?> />
+			<input type="checkbox" name="<?php echo FILTER_PROPERTY_SHOW_STICKY_ISSUES;?>" <?php check_checked( gpc_string_to_bool( $t_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] ), true );?> />
 		<?php
 }
 
-- 
1.6.4.2

11124.patch (2,161 bytes)   

Relationships

related to 0013937 closeddregad Versions and Categories from existing filter not preselected when editing it 
related to 0015721 closedgrangeway Functionality to consider porting to master-2.0.x 

Activities

vboctor

vboctor

2009-11-04 22:35

manager   ~0023577

@brianstv, please verify the attached patch.

dhx

dhx

2009-11-05 02:22

reporter   ~0023580

Thanks brianstv and Victor! I've been experiencing this problem for quite some time and haven't had a chance to properly look at the cause (or work out how filters work in Mantis).

I can confirm that the patch works, so I committed it.

@brianstv, if you were expecting something else, please reopen this bug. Thanks again for your help in fixing this!

brianstv

brianstv

2009-11-05 17:25

reporter   ~0023604

Patch didn't fully work for me.
It keeps the i:1 from getting saved in the filter_table, but it never picks up the default setting from config( 'show_sticky_issues' )

Making the following changes fixed it for me.

In core/filter_api.php
@@ -459,7 +459,7 @@ function filter_ensure_valid_filter( $p_filter_arr ) {
$p_filter_arr[FILTER_PROPERTY_HIGHLIGHT_CHANGED] = config_get( 'default_show_changed' );
}
if( !isset( $p_filter_arr[FILTER_PROPERTY_SHOW_STICKY_ISSUES] ) ) {

  • $p_filter_arr[FILTER_PROPERTY_SHOW_STICKY_ISSUES] = gpc_string_to_bool( config_get( 'show_sticky_issues' ) );
  • $p_filter_arr[FILTER_PROPERTY_SHOW_STICKY_ISSUES] = (gpc_string_to_bool( config_get( 'show_sticky_issues' )) ? 'on' : 'off' );
    }
    if( !isset( $p_filter_arr[FILTER_PROPERTY_SORT_FIELD_NAME] ) ) {
    $p_filter_arr[FILTER_PROPERTY_SORT_FIELD_NAME] = "last_updated";

In search.php
@@ -89,7 +89,7 @@
$my_filter[FILTER_PROPERTY_RELATIONSHIP_BUG] = gpc_get_int( FILTER_SEARCH_RELATIONSHIP_BUG, 0 );

    $my_filter[FILTER_PROPERTY_HIDE_STATUS_ID] = gpc_get_int( FILTER_SEARCH_HIDE_STATUS_ID, config_get( 'hide_status_default' ) );
  • $my_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] = gpc_get_bool( FILTER_SEARCH_SHOW_STICKY_ISSUES, config_get( 'show_sticky_issues' ) );
  • $my_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] = gpc_get_string( FILTER_SEARCH_SHOW_STICKY_ISSUES, (gpc_string_to_bool( config_get( 'show_sticky_issues' )) ? 'on' : 'off' ) );

    $my_filter[FILTER_PROPERTY_SORT_FIELD_NAME] = gpc_get_string( FILTER_SEARCH_SORT_FIELD_NAME, '' );
    $my_filter[FILTER_PROPERTY_SORT_DIRECTION] = gpc_get_string( FILTER_SEARCH_SORT_DIRECTION, '' );

In view_all_set.php
@@ -205,7 +205,7 @@

these are only single values, even when doing advanced filtering

    $f_per_page                             = gpc_get_int( FILTER_PROPERTY_ISSUES_PER_PAGE, -1 );
    $f_highlight_changed    = gpc_get_int( FILTER_PROPERTY_HIGHLIGHT_CHANGED, config_get( 'default_show_changed' ) );
  • $f_sticky_issues = gpc_get_bool( FILTER_PROPERTY_SHOW_STICKY_ISSUES );
  • $f_sticky_issues = gpc_string_to_bool( FILTER_PROPERTY_SHOW_STICKY_ISSUES );

    sort direction

    $f_sort_d                               = gpc_get_string( FILTER_PROPERTY_SORT_FIELD_NAME, '' );
    $f_dir_d                                = gpc_get_string( FILTER_PROPERTY_SORT_DIRECTION, '' );
brianstv

brianstv

2009-11-06 13:04

reporter   ~0023609

I still have something messed up, as now I can't set Show Sticky Issues to 'no' in the view_issues page.

brianstv

brianstv

2009-11-06 15:59

reporter   ~0023611

Found my problem: Disregard the change to view_all_set.php

dhx

dhx

2009-11-23 21:36

reporter   ~0023794

So what you're saying is that your diff above (disregarding the changes to view_all_set.php) is required to properly fix this issue? Or is everything OK as-is?

brianstv

brianstv

2009-12-09 20:05

reporter   ~0023890

The changes to core/filter_api.php and search.php are needed to pick up the default from the config_get when the user doesn't have a current filter in the mantis_filters_table.
Worked in my testing.

In core/filter_api.php
@@ -459,7 +459,7 @@ function filter_ensure_valid_filter( $p_filter_arr ) {
$p_filter_arr[FILTER_PROPERTY_HIGHLIGHT_CHANGED] = config_get( 'default_show_changed' );
}
if( !isset( $p_filter_arr[FILTER_PROPERTY_SHOW_STICKY_ISSUES] ) ) {

  • $p_filter_arr[FILTER_PROPERTY_SHOW_STICKY_ISSUES] = gpc_string_to_bool( config_get( 'show_sticky_issues' ) );
  • $p_filter_arr[FILTER_PROPERTY_SHOW_STICKY_ISSUES] = (gpc_string_to_bool( config_get( 'show_sticky_issues' )) ? 'on' : 'off' );
    }
    if( !isset( $p_filter_arr[FILTER_PROPERTY_SORT_FIELD_NAME] ) ) {
    $p_filter_arr[FILTER_PROPERTY_SORT_FIELD_NAME] = "last_updated";

And in search.php
@@ -89,7 +89,7 @@
$my_filter[FILTER_PROPERTY_RELATIONSHIP_BUG] = gpc_get_int( FILTER_SEARCH_RELATIONSHIP_BUG, 0 );

    $my_filter[FILTER_PROPERTY_HIDE_STATUS_ID] = gpc_get_int( FILTER_SEARCH_HIDE_STATUS_ID, config_get( 'hide_status_default' ) );
  • $my_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] = gpc_get_bool( FILTER_SEARCH_SHOW_STICKY_ISSUES, config_get( 'show_sticky_issues' ) );
  • $my_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] = gpc_get_string( FILTER_SEARCH_SHOW_STICKY_ISSUES, (gpc_string_to_bool( config_get( 'show_sticky_issues' )) ? 'on' : 'off' ) );

    $my_filter[FILTER_PROPERTY_SORT_FIELD_NAME] = gpc_get_string( FILTER_SEARCH_SORT_FIELD_NAME, '' );
    $my_filter[FILTER_PROPERTY_SORT_DIRECTION] = gpc_get_string( FILTER_SEARCH_SORT_DIRECTION, '' );
dhx

dhx

2009-12-09 23:33

reporter   ~0023891

gpc_string_to_bool( config_get( 'show_sticky_issues' )) is redundant because config_get will return a boolean (either ON = 1 or OFF = 0) that can be directly evaluated.

Also can someone (this is not directed to anyone in particular) explain why we're using strings 'on' and 'off' internally within Mantis? I can understand using them to make permalinks look pretty, but everywhere else it seems to just be unwanted extra complexity.

siebrand

siebrand

2009-12-21 12:19

developer   ~0023940

Update meta data. Showstopper 1.2.0

vboctor

vboctor

2010-01-02 00:40

manager   ~0024018

We shouldn't be using 'on' and 'off' in the database. The patch I checked in removed these and replaced them with true / false.

I've targeted for 1.3.x, unless someone fixes it earlier.

dhx

dhx

2012-03-01 18:02

reporter   ~0031362

This should now be fixed (hopefully) as part of changes made in 0013937.

You'll need to reset the filter for your current user to see any effect.

'on' and 'off' have been completely replaced with true/false. Type checking has also been performed.

grangeway

grangeway

2013-04-05 17:57

reporter   ~0036380

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

Related Changesets

MantisBT: master-1.2.x 9025cc67

2009-11-04 22:33

vboctor

Committer: dhx


Details Diff
Fixes 0011124: The 'sticky_issues' value stored in the mantis_filter_table is not always stored correctly.

Signed-off-by: David Hicks <hickseydr@optusnet.com.au>
Affected Issues
0011124
mod - core/filter_api.php Diff File

MantisBT: master 9d2ebf2f

2009-11-04 22:33

vboctor

Committer: dhx


Details Diff
Fixes 0011124: The 'sticky_issues' value stored in the mantis_filter_table is not always stored correctly.

Signed-off-by: David Hicks <hickseydr@optusnet.com.au>
Affected Issues
0011124
mod - core/filter_api.php Diff File