From: <gi...@ma...> - 2009-06-04 15:49:50
|
The branch, master has been updated via 845925e4c2c65cd386e56a3fdef70ecb06741645 (commit) via 4fc213a34c5558865ea15fde84846221ebc6c460 (commit) from 7104a343a09d8893331a2cbb7a491bd712356930 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 845925e4c2c65cd386e56a3fdef70ecb06741645 Author: John Reese <jr...@le...> Date: Thu Jun 4 08:28:33 2009 -0400 Added event CORE_READY to signal a point for plugins to begin processing with API's loaded and the system initialized. commit 4fc213a34c5558865ea15fde84846221ebc6c460 Author: John Reese <jr...@le...> Date: Tue Jun 2 15:35:29 2009 -0400 Fix #10544: Fix bugnote order and limit when generating emails. Reworked the original implementation of bugnote_get_all_bugnotes() to not care about order or limits, and just cache all the bugnotes in a simplified format. Updated bugnote_get_visible_bugnotes() to now expect a full list of bugnotes, and correctly handle the display order and limit each time called. ----------------------------------------------------------------------- Summary of changes: core.php | 4 +++ core/bugnote_api.php | 65 ++++++++++++++++++++------------------------------ core/events_inc.php | 3 ++ 3 files changed, 33 insertions(+), 39 deletions(-) ----------------------------------------------------------------------- commit 845925e4c2c65cd386e56a3fdef70ecb06741645 Author: John Reese <jr...@le...> Date: Thu Jun 4 08:28:33 2009 -0400 Added event CORE_READY to signal a point for plugins to begin processing with API's loaded and the system initialized. diff --git a/core.php b/core.php index 83e5c5f..94dcc52 100644 --- a/core.php +++ b/core.php @@ -237,3 +237,7 @@ if ( !is_blank ( config_get_global( 'default_timezone' ) ) ) { if ( !isset( $g_skip_lang_load ) ) { lang_push( lang_get_default() ); } + +# signal plugins that the core system is loaded +event_signal( 'EVENT_CORE_READY' ); + diff --git a/core/events_inc.php b/core/events_inc.php index 24437ae..681b92c 100644 --- a/core/events_inc.php +++ b/core/events_inc.php @@ -23,6 +23,9 @@ event_declare_many( array( # Events specific to plugins 'EVENT_PLUGIN_INIT' => EVENT_TYPE_EXECUTE, + # Events specific to the core system + 'EVENT_CORE_READY' => EVENT_TYPE_EXECUTE, + # MantisBT Layout Events 'EVENT_LAYOUT_RESOURCES' => EVENT_TYPE_OUTPUT, 'EVENT_LAYOUT_BODY_BEGIN' => EVENT_TYPE_OUTPUT, commit 4fc213a34c5558865ea15fde84846221ebc6c460 Author: John Reese <jr...@le...> Date: Tue Jun 2 15:35:29 2009 -0400 Fix #10544: Fix bugnote order and limit when generating emails. Reworked the original implementation of bugnote_get_all_bugnotes() to not care about order or limits, and just cache all the bugnotes in a simplified format. Updated bugnote_get_visible_bugnotes() to now expect a full list of bugnotes, and correctly handle the display order and limit each time called. diff --git a/core/bugnote_api.php b/core/bugnote_api.php index fefb4c1..cc1ec20 100644 --- a/core/bugnote_api.php +++ b/core/bugnote_api.php @@ -341,15 +341,20 @@ function bugnote_get_all_visible_bugnotes( $p_bug_id, $p_user_bugnote_order, $p_ $t_project_id = bug_get_field( $p_bug_id, 'project_id' ); $t_user_access_level = user_get_access_level( $t_user_id, $t_project_id ); - $t_all_bugnotes = bugnote_get_all_bugnotes( $p_bug_id, $p_user_bugnote_order, $p_user_bugnote_limit ); + $t_all_bugnotes = bugnote_get_all_bugnotes( $p_bug_id ); $t_private_bugnote_threshold = config_get( 'private_bugnote_threshold' ); $t_private_bugnote_visible = access_compare_level( $t_user_access_level, config_get( 'private_bugnote_threshold' ) ); $t_time_tracking_visible = access_compare_level( $t_user_access_level, config_get( 'time_tracking_view_threshold' ) ); $t_bugnotes = array(); - $t_note_index = 0; - foreach( $t_all_bugnotes as $t_bugnote ) { + $t_bugnote_count = count( $t_all_bugnotes ); + $t_bugnote_limit = $p_user_bugnote_limit > 0 ? $p_user_bugnote_limit : $t_bugnote_count; + + # build a list of the latest bugnotes that the user can see + for( $i = 0; $i < $t_bugnote_count && $i < $t_bugnote_limit; ) { + $t_bugnote = array_pop( $t_all_bugnotes ); + if( $t_private_bugnote_visible || $t_bugnote->reporter_id == $t_user_id || ( VS_PUBLIC == $t_bugnote->view_state ) ) { # If the access level specified is not enough to see time tracking information @@ -358,26 +363,28 @@ function bugnote_get_all_visible_bugnotes( $p_bug_id, $p_user_bugnote_order, $p_ $t_bugnote->time_tracking = 0; } - $t_bugnotes[$t_note_index++] = $t_bugnote; + $t_bugnotes[$i++] = $t_bugnote; } } + # reverse the list for users with ascending view preferences + if ( 'ASC' == $p_user_bugnote_order ) { + $t_bugnotes = array_reverse( $t_bugnotes ); + } + return $t_bugnotes; } /** - * Build the bugnotes array for the given bug_id. Bugnotes are sorted by date_submitted - * according to 'bugnote_order' configuration setting. + * Build the bugnotes array for the given bug_id. * Return BugnoteData class object with raw values from the tables except the field * last_modified - it is UNIX_TIMESTAMP. * The data is not filtered by VIEW_STATE !! * @param int $p_bug_id bug id - * @param int $p_user_bugnote_order sort order - * @param int $p_user_bugnote_limit number of bugnotes to display to user * @return array array of bugnotes * @access public */ -function bugnote_get_all_bugnotes( $p_bug_id, $p_user_bugnote_order, $p_user_bugnote_limit ) { +function bugnote_get_all_bugnotes( $p_bug_id ) { global $g_cache_bugnotes; if( !isset( $g_cache_bugnotes ) ) { @@ -385,44 +392,23 @@ function bugnote_get_all_bugnotes( $p_bug_id, $p_user_bugnote_order, $p_user_bug } # the cache should be aware of the sorting order - if( !isset( $g_cache_bugnotes[$p_bug_id][$p_user_bugnote_order] ) ) { - $c_bug_id = db_prepare_int( $p_bug_id ); + if( !isset( $g_cache_bugnotes[$p_bug_id] ) ) { $t_bugnote_table = db_get_table( 'mantis_bugnote_table' ); $t_bugnote_text_table = db_get_table( 'mantis_bugnote_text_table' ); - if( 0 == $p_user_bugnote_limit ) { - # # Show all bugnotes - $t_bugnote_limit = -1; - $t_bugnote_offset = -1; - } else { - # # Use offset only if order is ASC to get the last bugnotes - if( 'ASC' == $p_user_bugnote_order ) { - $result = db_query_bound( "SELECT COUNT(*) AS row_count FROM $t_bugnote_table WHERE bug_id= " . db_param(), array( $c_bug_id ) ); - $row = db_fetch_array( $result ); - - $t_bugnote_offset = $row['row_count'] - $p_user_bugnote_limit; - } else { - $t_bugnote_offset = -1; - } - - $t_bugnote_limit = $p_user_bugnote_limit; - } - # sort by bugnote id which should be more accurate than submit date, since two bugnotes # may be submitted at the same time if submitted using a script (eg: MantisConnect). - $query = "SELECT b.*, t.note + $t_query = "SELECT b.*, t.note FROM $t_bugnote_table b LEFT JOIN $t_bugnote_text_table t ON b.bugnote_text_id = t.id - WHERE b.bug_id = '$c_bug_id' - ORDER BY b.id $p_user_bugnote_order"; + WHERE b.bug_id=" . db_param() . ' + ORDER BY b.id ASC'; $t_bugnotes = array(); # BUILD bugnotes array - $result = db_query( $query, $t_bugnote_limit, $t_bugnote_offset ); - $count = db_num_rows( $result ); - for( $i = 0;$i < $count;$i++ ) { - $row = db_fetch_array( $result ); + $t_result = db_query_bound( $t_query, array( $p_bug_id ) ); + while( $row = db_fetch_array( $t_result ) ) { $t_bugnote = new BugnoteData; $t_bugnote->id = $row['id']; @@ -438,10 +424,11 @@ function bugnote_get_all_bugnotes( $p_bug_id, $p_user_bugnote_order, $p_user_bug $t_bugnotes[] = $t_bugnote; } - $g_cache_bugnotes[$p_bug_id][$p_user_bugnote_order] = $t_bugnotes; + + $g_cache_bugnotes[$p_bug_id] = $t_bugnotes; } - return $g_cache_bugnotes[$p_bug_id][$p_user_bugnote_order]; + return $g_cache_bugnotes[$p_bug_id]; } /** @@ -695,4 +682,4 @@ function bugnote_clear_cache( $p_bugnote_id = null ) { } return true; -} \ No newline at end of file +} ----------------------------------------------------------------------- -- Mantis Bug Tracker |