Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 17298ed

Browse files
committedApr 7, 2013
Add optional user_id/project_id parameters to some functions to fix the filter migration in the installer
1 parent eae2a50 commit 17298ed

6 files changed

+51
-87
lines changed
 

‎core/columns_api.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ function columns_plugin_cache_issue_data( $p_bugs ) {
246246
* @return array array of columns
247247
* @access public
248248
*/
249-
function columns_get_all( $p_project_id = null ) {
249+
function columns_get_all( $p_project_id = null, $p_user_id = null ) {
250250
$t_columns = columns_get_standard();
251251

252252
# add plugin columns
@@ -259,9 +259,15 @@ function columns_get_all( $p_project_id = null ) {
259259
$t_project_id = $p_project_id;
260260
}
261261

262-
$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
262+
if( $p_user_id === null ) {
263+
$t_user_id = auth_get_current_user_id();
264+
} else {
265+
$t_user_id = $p_user_id;
266+
}
267+
268+
$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id, $t_user_id );
263269
foreach( $t_related_custom_field_ids as $t_id ) {
264-
if( !custom_field_has_read_access_by_project_id( $t_id, $t_project_id ) ) {
270+
if( !custom_field_has_read_access_by_project_id( $t_id, $t_project_id, $t_user_id ) ) {
265271
continue;
266272
}
267273

‎core/custom_field_api.php

+8-13
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@
5050
require_api( 'string_api.php' );
5151
require_api( 'utility_api.php' );
5252

53-
# ## Custom Fields API ###
54-
# *******************************************
55-
# TODO
56-
# - add an object to store field data like BugData and UserPrefs ?
57-
# - add caching functions like user, bug, etc
58-
# - make existing api functions use caching functions
59-
# - add functions to return individual db columns for a field definition
60-
# *******************************************
61-
6253
$g_custom_field_types[CUSTOM_FIELD_TYPE_STRING] = 'standard';
6354
$g_custom_field_types[CUSTOM_FIELD_TYPE_NUMERIC] = 'standard';
6455
$g_custom_field_types[CUSTOM_FIELD_TYPE_FLOAT] = 'standard';
@@ -202,8 +193,7 @@ function custom_field_is_linked( $p_field_id, $p_project_id ) {
202193
}
203194

204195
# figure out if this bug_id/field_id combination exists
205-
$t_query = "SELECT COUNT(*) FROM {custom_field_project}
206-
WHERE field_id=%d AND project_id=%d";
196+
$t_query = "SELECT COUNT(*) FROM {custom_field_project} WHERE field_id=%d AND project_id=%d";
207197
$t_result = db_query( $t_query, array( $p_field_id, $p_project_id ) );
208198
$t_count = db_result( $t_result );
209199

@@ -781,18 +771,23 @@ function custom_field_get_id_from_name( $p_field_name, $p_truncated_length = nul
781771
*
782772
* The ids will be sorted based on the sequence number associated with the binding
783773
* @param int $p_project_id project id
774+
* @param int $p_user_id user id
784775
* @return array
785776
* @access public
786777
*/
787-
function custom_field_get_linked_ids( $p_project_id = ALL_PROJECTS ) {
778+
function custom_field_get_linked_ids( $p_project_id = ALL_PROJECTS, $p_user_id = null ) {
788779
global $g_cache_cf_linked;
789780

790781
if( !isset( $g_cache_cf_linked[$p_project_id] ) ) {
791782

792783
$p_project_id = (int) $p_project_id;
793784

794785
if( ALL_PROJECTS == $p_project_id ) {
795-
$t_user_id = auth_get_current_user_id();
786+
if( $p_user_id === null ) {
787+
$t_user_id = auth_get_current_user_id();
788+
} else {
789+
$t_user_id = (int) $p_user_id;
790+
}
796791
$t_pub = VS_PUBLIC;
797792
$t_priv = VS_PRIVATE;
798793

‎core/custom_function_api.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ function custom_function_default_get_columns_to_view( $p_columns_target = COLUMN
287287
$t_columns = config_get( 'print_issues_page_columns', columns_get_default( 'print_issues_page' ), $p_user_id, $t_project_id );
288288
}
289289

290-
$t_columns = columns_remove_invalid( $t_columns, columns_get_all( $t_project_id ) );
290+
$t_columns = columns_remove_invalid( $t_columns, columns_get_all( $t_project_id, $p_user_id ) );
291291

292292
return $t_columns;
293293
}

‎core/filter_api.php

+30-67
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,12 @@ function filter_offset( $p_page_number, $p_per_page ) {
457457
* Make sure that our filters are entirely correct and complete (it is possible that they are not).
458458
* We need to do this to cover cases where we don't have complete control over the filters given.s
459459
* @param array $p_filter_arr
460+
* @param int $p_user_id Optional user id to verify current filter against (normally current user)
461+
* @param int $p_project_id Optional project id to verify current filter against (normally current project)
460462
* @return mixed
461463
* @todo function needs to be abstracted
462464
*/
463-
function filter_ensure_valid_filter( $p_filter_arr ) {
465+
function filter_ensure_valid_filter( $p_filter_arr, $p_user_id = null, $p_project_id = null ) {
464466
# extend current filter to add information passed via POST
465467
if( !isset( $p_filter_arr['_version'] ) ) {
466468
$p_filter_arr['_version'] = config_get_global( 'cookie_version' );
@@ -474,45 +476,32 @@ function filter_ensure_valid_filter( $p_filter_arr ) {
474476
$p_filter_arr['_view_type'] = gpc_get_string( 'view_type', 'simple' );
475477
}
476478
if( !isset( $p_filter_arr[FILTER_PROPERTY_ISSUES_PER_PAGE] ) ) {
477-
$p_filter_arr[FILTER_PROPERTY_ISSUES_PER_PAGE] = gpc_get_int( FILTER_PROPERTY_ISSUES_PER_PAGE, config_get( 'default_limit_view' ) );
479+
$p_filter_arr[FILTER_PROPERTY_ISSUES_PER_PAGE] = gpc_get_int( FILTER_PROPERTY_ISSUES_PER_PAGE, config_get( 'default_limit_view', null, $p_user_id, $p_project_id ) );
478480
}
479481
if( !isset( $p_filter_arr[FILTER_PROPERTY_HIGHLIGHT_CHANGED] ) ) {
480-
$p_filter_arr[FILTER_PROPERTY_HIGHLIGHT_CHANGED] = config_get( 'default_show_changed' );
482+
$p_filter_arr[FILTER_PROPERTY_HIGHLIGHT_CHANGED] = config_get( 'default_show_changed', null, $p_user_id, $p_project_id );
481483
}
482484
if( !isset( $p_filter_arr[FILTER_PROPERTY_STICKY] ) ) {
483-
$p_filter_arr[FILTER_PROPERTY_STICKY] = gpc_string_to_bool( config_get( 'show_sticky_issues' ) );
485+
$p_filter_arr[FILTER_PROPERTY_STICKY] = gpc_string_to_bool( config_get( 'show_sticky_issues', null, $p_user_id, $p_project_id ) );
484486
}
485487
if( !isset( $p_filter_arr[FILTER_PROPERTY_SORT_FIELD_NAME] ) ) {
486488
$p_filter_arr[FILTER_PROPERTY_SORT_FIELD_NAME] = "last_updated";
487489
}
488490
if( !isset( $p_filter_arr[FILTER_PROPERTY_SORT_DIRECTION] ) ) {
489491
$p_filter_arr[FILTER_PROPERTY_SORT_DIRECTION] = "DESC";
490492
}
491-
492493
if( !isset( $p_filter_arr[FILTER_PROPERTY_PLATFORM] ) ) {
493-
$p_filter_arr[FILTER_PROPERTY_PLATFORM] = array(
494-
0 => META_FILTER_ANY,
495-
);
494+
$p_filter_arr[FILTER_PROPERTY_PLATFORM] = array( 0 => META_FILTER_ANY, );
496495
}
497-
498496
if( !isset( $p_filter_arr[FILTER_PROPERTY_OS] ) ) {
499-
$p_filter_arr[FILTER_PROPERTY_OS] = array(
500-
0 => META_FILTER_ANY,
501-
);
497+
$p_filter_arr[FILTER_PROPERTY_OS] = array( 0 => META_FILTER_ANY, );
502498
}
503-
504499
if( !isset( $p_filter_arr[FILTER_PROPERTY_OS_BUILD] ) ) {
505-
$p_filter_arr[FILTER_PROPERTY_OS_BUILD] = array(
506-
0 => META_FILTER_ANY,
507-
);
500+
$p_filter_arr[FILTER_PROPERTY_OS_BUILD] = array( 0 => META_FILTER_ANY, );
508501
}
509-
510502
if( !isset( $p_filter_arr[FILTER_PROPERTY_PROJECT_ID] ) ) {
511-
$p_filter_arr[FILTER_PROPERTY_PROJECT_ID] = array(
512-
0 => META_FILTER_CURRENT,
513-
);
503+
$p_filter_arr[FILTER_PROPERTY_PROJECT_ID] = array( 0 => META_FILTER_CURRENT, );
514504
}
515-
516505
if( !isset( $p_filter_arr[FILTER_PROPERTY_START_MONTH] ) ) {
517506
$p_filter_arr[FILTER_PROPERTY_START_MONTH] = gpc_get_string( FILTER_PROPERTY_START_MONTH, date( 'm' ) );
518507
}
@@ -612,7 +601,7 @@ function filter_ensure_valid_filter( $p_filter_arr ) {
612601
}
613602

614603
# validate sorting
615-
$t_fields = helper_get_columns_to_view();
604+
$t_fields = helper_get_columns_to_view( COLUMNS_TARGET_VIEW_PAGE, true, $p_user_id, $p_project_id);
616605
$t_n_fields = count( $t_fields );
617606
for( $i = 0;$i < $t_n_fields;$i++ ) {
618607
if( isset( $t_fields[$i] ) && in_array( $t_fields[$i], array( 'selection', 'edit', 'attachment' ) ) ) {
@@ -673,23 +662,17 @@ function filter_ensure_valid_filter( $p_filter_arr ) {
673662
if( !isset( $p_filter_arr[$t_multi_field_name] ) ) {
674663
if( FILTER_PROPERTY_HIDE_STATUS == $t_multi_field_name ) {
675664
$p_filter_arr[$t_multi_field_name] = array(
676-
config_get( 'hide_status_default' ),
665+
config_get( 'hide_status_default', null, $p_user_id, $p_project_id ),
677666
);
678667
}
679668
else if( 'custom_fields' == $t_multi_field_name ) {
680-
$p_filter_arr[$t_multi_field_name] = array(
681-
$f_custom_fields_data,
682-
);
669+
$p_filter_arr[$t_multi_field_name] = array( $f_custom_fields_data, );
683670
} else {
684-
$p_filter_arr[$t_multi_field_name] = array(
685-
META_FILTER_ANY,
686-
);
671+
$p_filter_arr[$t_multi_field_name] = array( META_FILTER_ANY, );
687672
}
688673
} else {
689674
if( !is_array( $p_filter_arr[$t_multi_field_name] ) ) {
690-
$p_filter_arr[$t_multi_field_name] = array(
691-
$p_filter_arr[$t_multi_field_name],
692-
);
675+
$p_filter_arr[$t_multi_field_name] = array( $p_filter_arr[$t_multi_field_name], );
693676
}
694677
$t_checked_array = array();
695678
foreach( $p_filter_arr[$t_multi_field_name] as $t_filter_value ) {
@@ -754,40 +737,18 @@ function filter_get_default() {
754737
$t_default_show_changed = config_get( 'default_show_changed' );
755738

756739
$t_filter = array(
757-
FILTER_PROPERTY_CATEGORY_ID => array(
758-
'0' => META_FILTER_ANY,
759-
),
760-
FILTER_PROPERTY_SEVERITY => array(
761-
'0' => META_FILTER_ANY,
762-
),
763-
FILTER_PROPERTY_STATUS => array(
764-
'0' => META_FILTER_ANY,
765-
),
740+
FILTER_PROPERTY_CATEGORY_ID => array( '0' => META_FILTER_ANY, ),
741+
FILTER_PROPERTY_SEVERITY => array( '0' => META_FILTER_ANY, ),
742+
FILTER_PROPERTY_STATUS => array( '0' => META_FILTER_ANY, ),
766743
FILTER_PROPERTY_HIGHLIGHT_CHANGED => $t_default_show_changed,
767-
FILTER_PROPERTY_REPORTER_ID => array(
768-
'0' => META_FILTER_ANY,
769-
),
770-
FILTER_PROPERTY_HANDLER_ID => array(
771-
'0' => META_FILTER_ANY,
772-
),
773-
FILTER_PROPERTY_PROJECT_ID => array(
774-
'0' => META_FILTER_CURRENT,
775-
),
776-
FILTER_PROPERTY_RESOLUTION => array(
777-
'0' => META_FILTER_ANY,
778-
),
779-
FILTER_PROPERTY_BUILD => array(
780-
'0' => META_FILTER_ANY,
781-
),
782-
FILTER_PROPERTY_VERSION => array(
783-
'0' => META_FILTER_ANY,
784-
),
785-
FILTER_PROPERTY_HIDE_STATUS => array(
786-
'0' => $t_hide_status_default,
787-
),
788-
FILTER_PROPERTY_MONITOR_USER_ID => array(
789-
'0' => META_FILTER_ANY,
790-
),
744+
FILTER_PROPERTY_REPORTER_ID => array( '0' => META_FILTER_ANY, ),
745+
FILTER_PROPERTY_HANDLER_ID => array( '0' => META_FILTER_ANY, ),
746+
FILTER_PROPERTY_PROJECT_ID => array( '0' => META_FILTER_CURRENT, ),
747+
FILTER_PROPERTY_RESOLUTION => array( '0' => META_FILTER_ANY, ),
748+
FILTER_PROPERTY_BUILD => array( '0' => META_FILTER_ANY, ),
749+
FILTER_PROPERTY_VERSION => array( '0' => META_FILTER_ANY, ),
750+
FILTER_PROPERTY_HIDE_STATUS => array( '0' => $t_hide_status_default, ),
751+
FILTER_PROPERTY_MONITOR_USER_ID => array( '0' => META_FILTER_ANY, ),
791752
FILTER_PROPERTY_SORT_FIELD_NAME => 'last_updated',
792753
FILTER_PROPERTY_SORT_DIRECTION => 'DESC',
793754
FILTER_PROPERTY_ISSUES_PER_PAGE => config_get( 'default_limit_view' ),
@@ -799,10 +760,12 @@ function filter_get_default() {
799760
/**
800761
* De-serialize filter string
801762
* @param string $p_serialized_filter serialized filter
763+
* @param int $p_user_id user id
764+
* @param int $p_project_id project id
802765
* @return mixed filter array
803766
* @see filter_ensure_valid_filter
804767
*/
805-
function filter_deserialize( $p_serialized_filter ) {
768+
function filter_deserialize( $p_serialized_filter, $p_user_id = null, $p_project_id = null ) {
806769
if( is_blank( $p_serialized_filter ) ) {
807770
return false;
808771
}
@@ -826,7 +789,7 @@ function filter_deserialize( $p_serialized_filter ) {
826789
if( $t_filter_array['_version'] != config_get_global( 'cookie_version' ) ) {
827790

828791
# if the version is not new enough, update it using defaults
829-
return filter_ensure_valid_filter( $t_filter_array );
792+
return filter_ensure_valid_filter( $t_filter_array, $p_user_id, $p_project_id );
830793
}
831794

832795
return $t_filter_array;

‎core/helper_api.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,11 @@ function helper_get_columns_to_view( $p_columns_target = COLUMNS_TARGET_VIEW_PAG
459459
$t_keys_to_remove[] = 'attachment';
460460
}
461461

462-
if( $t_current_project_id != ALL_PROJECTS && !access_has_project_level( config_get( 'view_handler_threshold', null, $p_user_id, $t_current_project_id ), $t_current_project_id ) ) {
462+
if( $t_current_project_id != ALL_PROJECTS && !access_has_project_level( config_get( 'view_handler_threshold', null, $p_user_id, $t_current_project_id ), $t_current_project_id, $p_user_id ) ) {
463463
$t_keys_to_remove[] = 'handler_id';
464464
}
465465

466-
if( $t_current_project_id != ALL_PROJECTS && !access_has_project_level( config_get( 'roadmap_view_threshold', null, $p_user_id, $t_current_project_id ), $t_current_project_id ) ) {
466+
if( $t_current_project_id != ALL_PROJECTS && !access_has_project_level( config_get( 'roadmap_view_threshold', null, $p_user_id, $t_current_project_id ), $t_current_project_id, $p_user_id ) ) {
467467
$t_keys_to_remove[] = 'target_version';
468468
}
469469

‎core/install_helper_functions_api.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ function install_stored_filter_migrate() {
321321
$t_query = "SELECT * FROM {filters}";
322322
$t_result = db_query( $t_query );
323323
while( $t_row = db_fetch_array( $t_result ) ) {
324-
$t_filter_arr = filter_deserialize( $t_row['filter_string'] );
324+
$t_filter_arr = filter_deserialize( $t_row['filter_string'], $t_row['user_id'], $t_row['project_id'] );
325325
foreach( $t_filter_fields AS $t_old=>$t_new ) {
326326
if ( isset( $t_filter_arr[$t_old] ) ) {
327327
$t_value = $t_filter_arr[$t_old];

1 commit comments

Comments
 (1)

atrol commented on Apr 8, 2013

@atrol
Member

For a better performance you might consider calling the changed functions with parameters whenever the needed values are already available.

e.g. instead of calling columns_get_all() in config_columns_set.php call columns_get_all( $t_project_id, $t_user_id );
This will avoid double calls of helper_get_current_project() and auth_get_current_user_id().

If there remain only calls with all parameters, the === null stuff can be removed.

Please sign in to comment.