diff --git a/core/filter_api.php b/core/filter_api.php index c8e8eae304..b1e2d89612 100644 --- a/core/filter_api.php +++ b/core/filter_api.php @@ -1184,7 +1184,13 @@ function filter_get_bug_rows_result( array $p_query_clauses, $p_count = null, $p } /** - * Creates an array of formatted query clauses, based on the supplied filter and parameters + * Creates an array of formatted query clauses, based on the supplied + * filter and parameters. + * Note: this function executes db_param_push(): + * - If the returned query is not executed, db_param_pop() should be executed + * to clean up the parameter stack + * - If the final query adds db_param() outside of this function, + * they must be added after this function is called. * @param array $p_filter Filter array object * @param integer $p_project_id Project id to use in filtering. * @param integer $p_user_id User id to use as current user when filtering. diff --git a/core/history_api.php b/core/history_api.php index ea98fcad17..bc7f776612 100644 --- a/core/history_api.php +++ b/core/history_api.php @@ -178,6 +178,59 @@ function history_count_user_recent_events( $p_duration_in_seconds, $p_user_id = return $t_row['event_count']; } +/** + * Creates and executes a query for the history rows related to bugs matched by the provided filter + * @param array $p_filter Filter array + * @param integer $p_start_time The start time to filter by, or null for all. + * @param integer $p_end_time The end time to filter by, or null for all. + * @param string $p_history_order The sort order. + * @return database result to pass into history_get_event_from_row(). + */ +function history_get_range_result_filter( $p_filter, $p_start_time = null, $p_end_time = null, $p_history_order = null ) { + if ( $p_history_order === null ) { + $t_history_order = config_get( 'history_order' ); + } else { + $t_history_order = $p_history_order; + } + + # Note: filter_get_bug_rows_query_clauses() calls db_param_push(); + $t_query_clauses = filter_get_bug_rows_query_clauses( $p_filter, null, null, null ); + + $t_select_string = 'SELECT DISTINCT {bug}.id '; + $t_from_string = ' FROM ' . implode( ', ', $t_query_clauses['from'] ); + $t_join_string = count( $t_query_clauses['join'] ) > 0 ? implode( ' ', $t_query_clauses['join'] ) : ' '; + $t_where_string = ' WHERE '. implode( ' AND ', $t_query_clauses['project_where'] ); + if( count( $t_query_clauses['where'] ) > 0 ) { + $t_where_string .= ' AND ( '; + $t_where_string .= implode( $t_query_clauses['operator'], $t_query_clauses['where'] ); + $t_where_string .= ' ) '; + } + + $t_query = 'SELECT * FROM {bug_history} JOIN' + . ' ( ' . $t_select_string . $t_from_string . $t_join_string . $t_where_string . ' ) B' + . ' ON {bug_history}.bug_id=B.id'; + + $t_params = $t_query_clauses['where_values']; + $t_where = array(); + if ( $p_start_time !== null ) { + $t_where[] = 'date_modified >= ' . db_param(); + $t_params[] = $p_start_time; + } + + if ( $p_end_time !== null ) { + $t_where[] = 'date_modified < ' . db_param(); + $t_params[] = $p_end_time; + } + + if ( count( $t_where ) > 0 ) { + $t_query .= ' WHERE ' . implode( ' AND ', $t_where ); + } + + $t_query .= ' ORDER BY {bug_history}.date_modified ' . $t_history_order . ', {bug_history}.id ' . $t_history_order; + $t_result = db_query( $t_query, $t_params ); + return $t_result; +} + /** * Creates and executes a query for the history rows matching the specified criteria. * @param integer $p_bug_id The bug id or null for matching any bug. @@ -235,7 +288,6 @@ function history_get_range_result( $p_bug_id = null, $p_start_time = null, $p_en function history_get_event_from_row( $p_result, $p_user_id = null, $p_check_access_to_issue = true ) { static $s_bug_visible = array(); $t_user_id = ( null === $p_user_id ) ? auth_get_current_user_id() : $p_user_id; - $t_project_id = helper_get_current_project(); while ( $t_row = db_fetch_array( $p_result ) ) { extract( $t_row, EXTR_PREFIX_ALL, 'v' ); @@ -245,11 +297,6 @@ function history_get_event_from_row( $p_result, $p_user_id = null, $p_check_acce continue; } - # Make sure the entry belongs to current project. - if ( $t_project_id != ALL_PROJECTS && $t_project_id != bug_get_field( $v_bug_id, 'project_id' ) ) { - continue; - } - if( $p_check_access_to_issue ) { if( !isset( $s_bug_visible[$v_bug_id] ) ) { $s_bug_visible[$v_bug_id] = access_has_bug_level( VIEWER, $v_bug_id ); diff --git a/core/timeline_api.php b/core/timeline_api.php index f79b486960..41724cb653 100644 --- a/core/timeline_api.php +++ b/core/timeline_api.php @@ -37,12 +37,17 @@ * @param integer $p_start_time Timestamp representing start time of the period. * @param integer $p_end_time Timestamp representing end time of the period. * @param integer $p_max_events The maximum number of events to return or 0 for unlimited. + * @param type $p_filter Filter array to use for filtering bugs * @return array */ -function timeline_events( $p_start_time, $p_end_time, $p_max_events ) { +function timeline_events( $p_start_time, $p_end_time, $p_max_events, $p_filter = null ) { $t_timeline_events = array(); - $t_result = history_get_range_result( /* $p_bug_id */ null, $p_start_time, $p_end_time, 'DESC' ); + if( null === $p_filter ) { + # create an empty filter, to match all bugs + $t_filter = filter_ensure_valid_filter( array() ); + } + $t_result = history_get_range_result_filter( $t_filter, $p_start_time, $p_end_time, 'DESC' ); $t_count = 0; while ( $t_history_event = history_get_event_from_row( $t_result, /* $p_user_id */ auth_get_current_user_id(), /* $p_check_access_to_issue */ true ) ) {