View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0007809 | mantisbt | custom fields | public | 2007-03-09 03:08 | 2007-10-04 01:37 |
Reporter | lifo2 | Assigned To | giallu | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Fixed in Version | 1.1.0rc1 | ||||
Summary | 0007809: Filter "none" on custom fields doesn't work | ||||
Description | When filtering on a custom field and choosing the value [none], the result is empty. The reason is that there's no entry in the mantis_custom_field_string_table for empty lines (except if the field was first filled and then updated to empty). | ||||
Steps To Reproduce | Pre-requisites : Reproducing : | ||||
Additional Information | This could be solved by a special query for the [none] value like : SELECT ... FROM mantis_bug_table WHERE bug_id NOT IN (SELECT DISTINCT(bug_id) FROM mantis_custom_field_string_table WHERE field_id="...") | ||||
Tags | No tags attached. | ||||
Attached Files | custom_field_filter_none.patch (1,129 bytes)
Index: core/filter_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/filter_api.php,v retrieving revision 1.147 diff -u -r1.147 filter_api.php --- core/filter_api.php 19 Dec 2006 09:15:54 -0000 1.147 +++ core/filter_api.php 9 Mar 2007 10:46:21 -0000 @@ -784,8 +784,17 @@ array_push( $t_join_clauses, $t_cf_join_clause ); foreach( $t_filter['custom_fields'][$t_cfid] as $t_filter_member ) { $t_filter_member = stripslashes( $t_filter_member ); - if ( META_FILTER_NONE === $t_filter_member ) { # coerce filter value if selecting META_FILTER_NONE + if ( META_FILTER_NONE == $t_filter_member ) { # coerce filter value if selecting META_FILTER_NONE $t_filter_member = ''; + + if( $t_first_time ) { + $t_first_time = false; + $t_custom_where_clause = '('; + } else { + $t_custom_where_clause .= ' OR '; + } + + $t_custom_where_clause .= "$t_bug_table.id NOT IN (SELECT bug_id FROM $t_table_name WHERE field_id=$t_cfid)"; } if( $t_first_time ) { custom_field_filter_none_2.patch (1,144 bytes)
Index: core/filter_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/filter_api.php,v retrieving revision 1.147 diff -u -r1.147 filter_api.php --- core/filter_api.php 19 Dec 2006 09:15:54 -0000 1.147 +++ core/filter_api.php 9 Mar 2007 11:23:37 -0000 @@ -784,8 +784,17 @@ array_push( $t_join_clauses, $t_cf_join_clause ); foreach( $t_filter['custom_fields'][$t_cfid] as $t_filter_member ) { $t_filter_member = stripslashes( $t_filter_member ); - if ( META_FILTER_NONE === $t_filter_member ) { # coerce filter value if selecting META_FILTER_NONE + if ( META_FILTER_NONE == $t_filter_member ) { # coerce filter value if selecting META_FILTER_NONE $t_filter_member = ''; + + if( $t_first_time ) { + $t_first_time = false; + $t_custom_where_clause = '('; + } else { + $t_custom_where_clause .= ' OR '; + } + + $t_custom_where_clause .= "$t_bug_table.id NOT IN (SELECT bug_id FROM $t_custom_field_string_table WHERE field_id=$t_cfid)"; } if( $t_first_time ) { bug7809.patch (2,563 bytes)
Index: core/filter_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/filter_api.php,v retrieving revision 1.155 diff -u -r1.155 filter_api.php --- core/filter_api.php 27 May 2007 22:31:59 -0000 1.155 +++ core/filter_api.php 16 Jul 2007 22:42:57 -0000 @@ -1067,7 +1067,6 @@ $t_custom_fields = custom_field_get_linked_ids( $t_project_id ); foreach( $t_custom_fields as $t_cfid ) { - $t_first_time = true; $t_custom_where_clause = ''; # Ignore all custom filters that are not set, or that are set to '' or "any" $t_any_found = false; @@ -1112,27 +1111,27 @@ } else { array_push( $t_join_clauses, $t_cf_join_clause ); + + $t_filter_array = array(); foreach( $t_filter['custom_fields'][$t_cfid] as $t_filter_member ) { $t_filter_member = stripslashes( $t_filter_member ); - if ( META_FILTER_NONE === $t_filter_member ) { # coerce filter value if selecting META_FILTER_NONE + if ( META_FILTER_NONE == $t_filter_member ) { + # coerce filter value if selecting META_FILTER_NONE so it will match empty fields $t_filter_member = ''; + # but also add those _not_ present in the custom field string table + array_push( $t_filter_array , "$t_bug_table.id NOT IN (SELECT bug_id FROM $t_custom_field_string_table WHERE field_id=$t_cfid)" ); } - if( $t_first_time ) { - $t_first_time = false; - $t_custom_where_clause = '('; - } else { - $t_custom_where_clause .= ' OR '; - } switch( $t_def['type'] ) { - case CUSTOM_FIELD_TYPE_MULTILIST: - case CUSTOM_FIELD_TYPE_CHECKBOX: - $t_custom_where_clause .= db_helper_like( "$t_table_name.value", '%|' . db_prepare_string( $t_filter_member ) . '|%' ); - break; - default: - $t_custom_where_clause .= "$t_table_name.value = '" . db_prepare_string( $t_filter_member ) . "'"; + case CUSTOM_FIELD_TYPE_MULTILIST: + case CUSTOM_FIELD_TYPE_CHECKBOX: + array_push( $t_filter_array , db_helper_like( "$t_table_name.value", '%|' . db_prepare_string( $t_filter_member ) . '|%' ) ); + break; + default: + array_push( $t_filter_array, "$t_table_name.value = '" . db_prepare_string( $t_filter_member ) . "'" ); } } + $t_custom_where_clause .= '(' . implode( ' OR ', $t_filter_array ); } if ( !is_blank( $t_custom_where_clause ) ) { array_push( $t_where_clauses, $t_custom_where_clause . ')' ); | ||||
Here is a patch that correct this problem. In fact, there were two problems :
|
|
Sorry, I made a mistake in the first patch. The second one is the good one. |
|
I finally had a chance at reviewing your patch. One question; the query you proposed in "Additional Information" had a DISTINCT clause: is there a reason why you dropped it in the proposed patch? |
|
It seems fine to me (and yes, the use of an array and implode is more elegant ;) ). I think I dropped the DISTINCT clause because there can be only one row for a given couple of bug_id and field_id, so it was useless. |
|
In the meanwhile, I become aware thart the nested query syntax could be problematic for the cross DB goal of mantis (and even in MySQL was introduced in v4.1, while we are going to require 4.0) Do you think that doing 2 separate queries would be detrimental to performances and/or RAM usage? |
|
@giallu: I thought we were going to be requiring MySQL 4.1 specifically for the reason of subquery support? |
|
I will ask again on -devel |
|
Shouldn't / doesn't ADODB handle subquery support? |
|
I wish I knew... anyway, Victor gave me the OK to use subqueries, so 1.1 will have a dependency on MySQL 4.1 and I can commit the fix as is. |
|
MantisBT: master bd7cad4f 2007-09-15 17:48 Details Diff |
Fix 7809: Filter "none" on custom fields doesn't work git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@4574 <a class="text" href="/?p=mantisbt.git;a=object;h=f5dc347c">f5dc347c</a>-c33d-0410-90a0-b07cc1902cb9 |
Affected Issues 0007809 |
|
mod - core/filter_api.php | Diff File |