Skip to content

Commit

Permalink
Use new function filter_get()
Browse files Browse the repository at this point in the history
Remove calls to low level filter loading, and use filter_get() instead.
  • Loading branch information
cproensa authored and atrol committed Mar 4, 2018
1 parent eebfa6d commit 5d9ecf1
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 118 deletions.
8 changes: 2 additions & 6 deletions api/soap/mc_filter_api.php
Expand Up @@ -236,14 +236,10 @@ function mc_filter_get_issue_headers( $p_username, $p_password, $p_project_id, $
$t_orig_page_number = $p_page_number < 1 ? 1 : $p_page_number;
$t_page_count = 0;
$t_bug_count = 0;
$t_filter = filter_db_get_filter( $p_filter_id );
$t_filter_detail = explode( '#', $t_filter, 2 );
if( !isset( $t_filter_detail[1] ) ) {
$t_filter = filter_get( $p_filter_id, null );
if( null === $t_filter ) {
return ApiObjectFactory::faultServerError( 'Invalid Filter' );
}
$t_filter = json_decode( $t_filter_detail[1], true );
$t_filter = filter_ensure_valid_filter( $t_filter );

$t_result = array();
$t_rows = filter_get_bug_rows( $p_page_number, $p_per_page, $t_page_count, $t_bug_count, $t_filter, $p_project_id );

Expand Down
13 changes: 1 addition & 12 deletions core/filter_api.php
Expand Up @@ -2850,18 +2850,7 @@ function filter_db_get_filter( $p_filter_id, $p_user_id = null ) {
*/
function filter_load( $p_filter_id, $p_user_id = null ) {
if( is_numeric( $p_filter_id ) ) {
$p_filter_id = (int)$p_filter_id;
$t_filter = filter_db_get_filter( $p_filter_id );
if( $t_filter === null ) {
return null;
}

$t_filter_detail = explode( '#', $t_filter, 2 );
if( !isset( $t_filter_detail[1] ) ) {
return false;
}

$t_filter = json_decode( $t_filter_detail[1], true );
$t_filter = filter_get( $p_filter_id, null );
} else {
$p_filter_id = strtolower( $p_filter_id );
$t_project_id = helper_get_current_project();
Expand Down
27 changes: 2 additions & 25 deletions core/user_api.php
Expand Up @@ -1457,31 +1457,8 @@ function user_get_bug_filter( $p_user_id, $p_project_id = null ) {
$t_project_id = $p_project_id;
}

$t_view_all_cookie_id = filter_db_get_project_current( $t_project_id, $p_user_id );
$t_view_all_cookie = filter_db_get_filter( $t_view_all_cookie_id, $p_user_id );

$t_filter = filter_deserialize( $t_view_all_cookie );
if( !$t_filter ) {
return filter_get_default();
}

# when the user specific filter references a stored filter id, get that filter instead
if( isset( $t_filter['_source_query_id'] ) && $t_view_all_cookie_id != $t_filter['_source_query_id'] ) {
$t_source_query_id = $t_filter['_source_query_id'];
# check if filter id is a proper stored filter, and is accesible
if( filter_is_named_filter( $t_source_query_id ) && filter_is_accessible( $t_source_query_id ) ){
# the actual stored filter can be retrieved
$t_filter = filter_deserialize( filter_db_get_filter( $t_source_query_id ) );
# update the referenced stored filter id
$t_filter['_source_query_id'] = $t_source_query_id;
} else {
# If the filter id is not valid, clean the referenced filter id
unset( $t_filter['_source_query_id'] );
}
}
$t_filter = filter_ensure_valid_filter( $t_filter );

return $t_filter;
$t_filter_id = filter_db_get_project_current( $t_project_id, $p_user_id );
return filter_get( $t_filter_id );
}

/**
Expand Down
7 changes: 4 additions & 3 deletions issues_rss.php
Expand Up @@ -172,17 +172,18 @@
}
$t_show_sticky = null;

# Override current user
current_user_set( $t_user_id );

if( $f_filter_id == 0 ) {
$t_custom_filter = filter_get_default();
$t_custom_filter['sort'] = $c_sort_field;
} else {
# null will be returned if the user doesn't have access right to access the filter.
$t_custom_filter = filter_db_get_filter( $f_filter_id, $t_user_id );
$t_custom_filter = filter_get( $f_filter_id, null );
if( null === $t_custom_filter ) {
access_denied();
}

$t_custom_filter = filter_deserialize( $t_custom_filter );
}

$t_issues = filter_get_bug_rows( $t_page_number, $t_issues_per_page, $t_page_count, $t_issues_count,
Expand Down
7 changes: 2 additions & 5 deletions manage_filter_edit_page.php
Expand Up @@ -70,12 +70,9 @@
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}

$t_filter_string = filter_db_get_filter( $f_filter_id );
if( !$t_filter_string ) {
$t_filter = filter_get( $f_filter_id, null );
if( null === $t_filter ) {
access_denied();
} else {
$t_filter = filter_deserialize( $t_filter_string );
$t_filter['_source_query_id'] = $f_filter_id;
}

$f_view_type = gpc_get_string( 'view_type', $t_filter['_view_type'] );
Expand Down
6 changes: 2 additions & 4 deletions manage_filter_edit_update.php
Expand Up @@ -40,11 +40,9 @@
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}

$t_filter_string = filter_db_get_filter( $f_filter_id );
if( !$t_filter_string ) {
$t_filter = filter_get( $f_filter_id, null );
if( null === $t_filter ) {
access_denied();
} else {
$t_filter = filter_deserialize( $t_filter_string );
}

$f_filter_name = gpc_get_string( 'filter_name', null );
Expand Down
20 changes: 5 additions & 15 deletions print_all_bug_page.php
Expand Up @@ -72,21 +72,11 @@

# Initialize the filter from the cookie, use default if not set
$t_cookie_value_id = gpc_get_cookie( config_get_global( 'view_all_cookie' ), '' );
$t_cookie_value = filter_db_get_filter( $t_cookie_value_id );
if( is_blank( $t_cookie_value ) ) {
$t_filter_cookie_arr = filter_get_default();
} else {
# check to see if new cookie is needed
if( !filter_is_cookie_valid() ) {
print_header_redirect( 'view_all_set.php?type=0&print=1' );
}
$t_setting_arr = explode( '#', $t_cookie_value, 2 );
$t_filter_cookie_arr = json_decode( $t_setting_arr[1], true );
}
$t_filter = filter_get( $t_cookie_value_id, filter_get_default() );

$f_highlight_changed = $t_filter_cookie_arr[FILTER_PROPERTY_HIGHLIGHT_CHANGED];
$f_sort = $t_filter_cookie_arr[FILTER_PROPERTY_SORT_FIELD_NAME];
$f_dir = $t_filter_cookie_arr[FILTER_PROPERTY_SORT_DIRECTION];
$f_highlight_changed = $t_filter[FILTER_PROPERTY_HIGHLIGHT_CHANGED];
$f_sort = $t_filter[FILTER_PROPERTY_SORT_FIELD_NAME];
$f_dir = $t_filter[FILTER_PROPERTY_SORT_DIRECTION];
$t_project_id = helper_get_current_project();

# This replaces the actual search that used to be here
Expand Down Expand Up @@ -197,7 +187,7 @@
</tr>
<tr class="row-category">
<?php
$t_sort_properties = filter_get_visible_sort_properties_array( $t_filter_cookie_arr, COLUMNS_TARGET_PRINT_PAGE );
$t_sort_properties = filter_get_visible_sort_properties_array( $t_filter, COLUMNS_TARGET_PRINT_PAGE );
foreach( $t_columns as $t_column ) {
helper_call_custom_function( 'print_column_title', array( $t_column, COLUMNS_TARGET_PRINT_PAGE, $t_sort_properties ) );
}
Expand Down
7 changes: 5 additions & 2 deletions query_store.php
Expand Up @@ -89,9 +89,12 @@
$t_project_id = 0;
}

$t_filter_string = filter_db_get_filter( gpc_get_cookie( config_get_global( 'view_all_cookie' ), '' ) );
$t_filter_id = gpc_get_cookie( config_get_global( 'view_all_cookie' ), '' );
$t_filter = filter_get( $t_filter_id, null );
if( null === $t_filter ) {
access_denied();
}
# named filters must not reference source query id
$t_filter = filter_deserialize( $t_filter_string );
if( isset( $t_filter['_source_query_id'] ) ) {
unset( $t_filter['_source_query_id'] );
}
Expand Down
9 changes: 3 additions & 6 deletions return_dynamic_filters.php
Expand Up @@ -64,18 +64,15 @@
if( null === $f_filter_id ) {
$t_filter = current_user_get_bug_filter();
} else {
$c_filter_id = (int)$f_filter_id;
$t_filter_string = filter_db_get_filter( $c_filter_id );
if( !$t_filter_string ) {
$t_filter = filter_get( $f_filter_id, null );
if( null === $t_filter ) {
trigger_error( ERROR_ACCESS_DENIED, ERROR );
} else {
$t_filter = filter_deserialize( $t_filter_string );
$t_filter['_source_query_id'] = $f_filter_id;
}
}

$f_view_type = gpc_get_string( 'view_type', $t_filter['_view_type'] );
$t_filter['_view_type'] = $f_view_type;
# call to filter_ensure_valid_filter to clean up after adding unsafe values from gpc vars
$t_filter = filter_ensure_valid_filter( $t_filter );

/**
Expand Down
51 changes: 17 additions & 34 deletions view_all_set.php
Expand Up @@ -106,31 +106,20 @@
# 26: $f_show_profile

# Set new filter values. These are stored in a cookie
$t_view_all_cookie_id = gpc_get_cookie( config_get_global( 'view_all_cookie' ), '' );
$t_view_all_cookie = filter_db_get_filter( $t_view_all_cookie_id );

# process the cookie if it exists, it may be blank in a new install
if( !is_blank( $t_view_all_cookie ) ) {
$t_setting_arr = filter_deserialize( $t_view_all_cookie );
if( false === $t_setting_arr ) {
# couldn't deserialize, if we were trying to use the filter, clear it and reload
# for ftype = 0, 1, or 3, we are going to re-write the filter anyways
if( !in_array( $f_type, array( 0, 1, 3 ) ) ) {
gpc_clear_cookie( 'view_all_cookie' );
error_proceed_url( 'view_all_set.php?type=0' );
trigger_error( ERROR_FILTER_TOO_OLD, ERROR );
exit; # stop here
}
} else {
$t_setting_arr = filter_ensure_valid_filter( $t_setting_arr );
}
} else {
$t_cookie_name = config_get_global( 'view_all_cookie' );
$t_cookie_filter_id = gpc_get_cookie( $t_cookie_name, null );
if( null === $t_cookie_filter_id ) {
# no cookie found, set it
$f_type = 1;
} else {
$t_setting_arr = filter_get( $t_cookie_filter_id, filter_get_default() );
}

# Clear the source query id. Since we have entered new filter criteria.
$t_setting_arr['_source_query_id'] = '';
if( isset( $t_setting_arr['_source_query_id'] ) ) {
unset( $t_setting_arr['_source_query_id'] );
}

switch( $f_type ) {
# New cookie
case '0':
Expand All @@ -152,22 +141,16 @@
case '3':
log_event( LOG_FILTERING, 'view_all_set.php: Copy another query from database' );

$t_filter_string = filter_db_get_filter( $f_source_query_id );
# If we can use the query that we've requested,
# grab it. We will overwrite the current one at the
# bottom of this page
$t_setting_arr = filter_deserialize( $t_filter_string );
if( false === $t_setting_arr ) {
# couldn't deserialize, if we were trying to use the filter, clear it and reload
gpc_clear_cookie( 'view_all_cookie' );
$t_setting_arr = filter_get( $f_source_query_id, null );
if( null === $t_setting_arr ) {
# couldn't get the filter, if we were trying to use the filter, clear it and reload
gpc_clear_cookie( $t_cookie_name );
error_proceed_url( 'view_all_set.php?type=0' );
trigger_error( ERROR_FILTER_TOO_OLD, ERROR );
exit; # stop here
trigger_error( ERROR_FILTER_NOT_FOUND, ERROR );
exit;
} else {
$t_setting_arr = filter_ensure_valid_filter( $t_setting_arr );
$t_setting_arr['_source_query_id'] = $f_source_query_id;
}
# Store the source query id to select the correct filter in the drop down.
$t_setting_arr['_source_query_id'] = $f_source_query_id;
break;
case '4':
# Generalise the filter
Expand Down Expand Up @@ -225,7 +208,7 @@
$t_row_id = filter_db_set_for_current_user( $t_project_id, false, '', $t_settings_string );

# set cookie values
gpc_set_cookie( config_get_global( 'view_all_cookie' ), $t_row_id, time()+config_get_global( 'cookie_time_length' ), config_get_global( 'cookie_path' ) );
gpc_set_cookie( $t_cookie_name, $t_row_id, time()+config_get_global( 'cookie_time_length' ), config_get_global( 'cookie_path' ) );
}

# redirect to print_all or view_all page
Expand Down
9 changes: 3 additions & 6 deletions view_filters_page.php
Expand Up @@ -72,14 +72,11 @@
$t_filter = current_user_get_bug_filter();
$t_named_filter = false;
} else {
$c_filter_id = (int)$f_filter_id;
$t_filter_string = filter_db_get_filter( $c_filter_id );
if( !$t_filter_string ) {
$t_filter = filter_get( $f_filter_id, null );
if( null === $t_filter ) {
access_denied();
} else {
$t_filter = filter_deserialize( $t_filter_string );
$t_named_filter = true;
}
$t_named_filter = true;
}

$f_for_screen = gpc_get_bool( 'for_screen', true );
Expand Down

0 comments on commit 5d9ecf1

Please sign in to comment.