From c8504404947f59267d749c56adbb9ffee341fa74 Mon Sep 17 00:00:00 2001 From: Paul Richards Date: Sat, 30 Jul 2011 13:43:37 +0100 Subject: [PATCH] Remove use of error_parameters --- adm_config_set.php | 9 ++---- bug_actiongroup_add_note_inc.php | 3 +- bug_relationship_add.php | 3 +- bug_relationship_delete.php | 3 +- bug_reminder.php | 3 +- bug_reminder_page.php | 3 +- bug_report.php | 3 +- bug_report_page.php | 3 +- bug_update.php | 12 +++----- bug_update_advanced_page.php | 3 +- bugnote_add.php | 6 ++-- bugnote_edit_page.php | 3 +- bugnote_set_view_state.php | 3 +- bugnote_update.php | 3 +- changelog_page.php | 3 +- core/bug_api.php | 24 +++++---------- core/bugnote_api.php | 6 ++-- core/category_api.php | 7 ++--- core/classes/MantisDatabase/PDO/PDO.class.php | 4 +-- core/classes/MantisError.class.php | 21 +++++++++++-- core/classes/MantisUser.class.php | 3 +- core/custom_field_api.php | 12 +++----- core/database_api.php | 15 ---------- core/email_queue_api.php | 9 ++---- core/error_api.php | 23 -------------- core/filter_api.php | 3 +- core/gpc_api.php | 30 +++++++------------ core/helper_api.php | 9 ++---- core/html_api.php | 2 +- core/news_api.php | 12 +++----- core/profile_api.php | 18 ++++------- core/sponsorship_api.php | 6 ++-- core/summary_api.php | 3 +- core/tag_api.php | 3 +- core/user_api.php | 3 +- core/version_api.php | 6 ++-- manage_proj_cat_add.php | 3 +- manage_user_edit_page.php | 3 +- proj_doc_add.php | 3 +- return_dynamic_filters.php | 3 +- roadmap_page.php | 3 +- 41 files changed, 98 insertions(+), 199 deletions(-) diff --git a/adm_config_set.php b/adm_config_set.php index ce523f47f0..889a82965e 100644 --- a/adm_config_set.php +++ b/adm_config_set.php @@ -57,8 +57,7 @@ $f_value = gpc_get_string( 'value' ); if ( is_blank( $f_config_option ) ) { - error_parameters( 'config_option' ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( 'config_option' ); } access_ensure_global_level( config_get( 'set_configuration_threshold' ) ); @@ -70,14 +69,12 @@ # make sure that configuration option specified is a valid one. $t_not_found_value = '***CONFIG OPTION NOT FOUND***'; if ( config_get_global( $f_config_option, $t_not_found_value ) === $t_not_found_value ) { - error_parameters( $f_config_option ); - throw new MantisBT\Exception\Config_Opt_Not_Found(); + throw new MantisBT\Exception\Config_Opt_Not_Found( $f_config_option ); } # make sure that configuration option specified can be stored in the database if ( !config_can_set_in_database( $f_config_option ) ) { - error_parameters( $f_config_option ); - throw new MantisBT\Exception\Config_Opt_Cant_Be_Set_In_Db(); + throw new MantisBT\Exception\Config_Opt_Cant_Be_Set_In_Db( $f_config_option ); } if ( $f_type === 'default' ) { diff --git a/bug_actiongroup_add_note_inc.php b/bug_actiongroup_add_note_inc.php index ce45e909ba..b4ed2c0776 100644 --- a/bug_actiongroup_add_note_inc.php +++ b/bug_actiongroup_add_note_inc.php @@ -99,8 +99,7 @@ function action_add_note_validate( $p_bug_id ) { $f_bugnote_text = gpc_get_string( 'bugnote_text' ); if ( is_blank( $f_bugnote_text ) ) { - error_parameters( lang_get( 'bugnote' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'bugnote' ) ); } $t_add_bugnote_threshold = config_get( 'add_bugnote_threshold' ); diff --git a/bug_relationship_add.php b/bug_relationship_add.php index 10cd308811..128aa9ec3b 100644 --- a/bug_relationship_add.php +++ b/bug_relationship_add.php @@ -81,8 +81,7 @@ # bug is not read-only... if ( bug_is_readonly( $f_src_bug_id ) ) { - error_parameters( $f_src_bug_id ); - throw new MantisBT\Exception\Bug_Read_Only_Action_Denied(); + throw new MantisBT\Exception\Bug_Read_Only_Action_Denied( $f_src_bug_id ); } # user can access to the related bug at least as viewer... diff --git a/bug_relationship_delete.php b/bug_relationship_delete.php index c98579f6e0..59c2ec3d9b 100644 --- a/bug_relationship_delete.php +++ b/bug_relationship_delete.php @@ -78,8 +78,7 @@ # bug is not read-only... if ( bug_is_readonly( $f_bug_id ) ) { - error_parameters( $f_bug_id ); - throw new MantisBT\Exception\Bug_Read_Only_Action_Denied(); + throw new MantisBT\Exception\Bug_Read_Only_Action_Denied( $f_bug_id ); } # retrieve the destination bug of the relationship diff --git a/bug_reminder.php b/bug_reminder.php index c5a9e7b0fa..3492ad4550 100644 --- a/bug_reminder.php +++ b/bug_reminder.php @@ -72,8 +72,7 @@ } if ( bug_is_readonly( $f_bug_id ) ) { - error_parameters( $f_bug_id ); - throw new MantisBT\Exception\Bug_Read_Only_Action_Denied(); + throw new MantisBT\Exception\Bug_Read_Only_Action_Denied( $f_bug_id ); } access_ensure_bug_level( config_get( 'bug_reminder_threshold' ), $f_bug_id ); diff --git a/bug_reminder_page.php b/bug_reminder_page.php index d843b41b82..6f3b0cdd66 100644 --- a/bug_reminder_page.php +++ b/bug_reminder_page.php @@ -60,8 +60,7 @@ } if ( bug_is_readonly( $f_bug_id ) ) { - error_parameters( $f_bug_id ); - throw new MantisBT\Exception\Bug_Read_Only_Action_Denied(); + throw new MantisBT\Exception\Bug_Read_Only_Action_Denied( $f_bug_id ); } access_ensure_bug_level( config_get( 'bug_reminder_threshold' ), $f_bug_id ); diff --git a/bug_report.php b/bug_report.php index da491405eb..f6389be89c 100644 --- a/bug_report.php +++ b/bug_report.php @@ -156,8 +156,7 @@ $t_def['type'] == CUSTOM_FIELD_TYPE_LIST || $t_def['type'] == CUSTOM_FIELD_TYPE_MULTILIST || $t_def['type'] == CUSTOM_FIELD_TYPE_RADIO ) ) { - error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); } if ( !custom_field_validate( $t_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], NULL ) ) ) { throw new MantisBT\Exception\Custom_Field_Invalid_Value( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) )); diff --git a/bug_report_page.php b/bug_report_page.php index 6481785cb1..bfa402f643 100644 --- a/bug_report_page.php +++ b/bug_report_page.php @@ -93,8 +93,7 @@ # master bug is not read-only... if ( bug_is_readonly( $f_master_bug_id ) ) { - error_parameters( $f_master_bug_id ); - throw new MantisBT\Exception\Bug_Read_Only_Action_Denied(); + throw new MantisBT\Exception\Bug_Read_Only_Action_Denied( $f_master_bug_id ); } $t_bug = bug_get( $f_master_bug_id, true ); diff --git a/bug_update.php b/bug_update.php index ec7c4c1a83..73b9a9989e 100644 --- a/bug_update.php +++ b/bug_update.php @@ -83,8 +83,7 @@ # Check if the bug is in a read-only state and whether the current user has # permission to update read-only bugs. if ( bug_is_readonly( $f_bug_id ) ) { - error_parameters( $f_bug_id ); - throw new MantisBT\Exception\Bug_Read_Only_Action_Denied(); + throw new MantisBT\Exception\Bug_Read_Only_Action_Denied( $f_bug_id ); } $t_updated_bug = clone $t_existing_bug; @@ -203,8 +202,7 @@ if ( $t_existing_bug->category_id !== $t_updated_bug->category_id ) { if ( $t_updated_bug->category_id === 0 && !config_get( 'allow_no_category' ) ) { - error_parameters( lang_get( 'category' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'category' ) ); } } @@ -245,8 +243,7 @@ if ( $t_cf_def[$t_cf_require_check] ) { # A value for the custom field was expected however # no value was given by the user. - error_parameters( lang_get_defaulted( custom_field_get_field( $t_cf_id, 'name' ) ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get_defaulted( custom_field_get_field( $t_cf_id, 'name' ) ) ); } else { # The custom field isn't compulsory and the user did # not supply a value. Therefore we can just ignore this @@ -298,8 +295,7 @@ access_ensure_bug_level( config_get( 'add_bugnote_threshold' ), $f_bug_id ); if ( !$t_bug_note->note && !config_get( 'time_tracking_without_note' ) ) { - error_parameters( lang_get( 'bugnote' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'bugnote' ) ); } if ( $t_bug_note->view_state !== config_get( 'default_bugnote_view_status' ) ) { access_ensure_bug_level( config_get( 'set_view_status_threshold' ), $f_bug_id ); diff --git a/bug_update_advanced_page.php b/bug_update_advanced_page.php index 852ab52b4c..fddd1345ed 100644 --- a/bug_update_advanced_page.php +++ b/bug_update_advanced_page.php @@ -87,8 +87,7 @@ } if ( bug_is_readonly( $f_bug_id ) ) { - error_parameters( $f_bug_id ); - throw new MantisBT\Exception\Bug_Read_Only_Action_Denied(); + throw new MantisBT\Exception\Bug_Read_Only_Action_Denied( $f_bug_id ); } access_ensure_bug_level( config_get( 'update_bug_threshold' ), $f_bug_id ); diff --git a/bugnote_add.php b/bugnote_add.php index 7c9815abea..9d5860d702 100644 --- a/bugnote_add.php +++ b/bugnote_add.php @@ -67,8 +67,7 @@ } if ( bug_is_readonly( $t_bug->id ) ) { - error_parameters( $t_bug->id ); - throw new MantisBT\Exception\Bug_Read_Only_Action_Denied(); + throw new MantisBT\Exception\Bug_Read_Only_Action_Denied( $t_bug->id ); } access_ensure_bug_level( config_get( 'add_bugnote_threshold' ), $t_bug->id ); @@ -81,8 +80,7 @@ // if $f_time_tracking is not 0 and the time tracking feature is enabled. $t_bugnote_id = bugnote_add( $t_bug->id, $f_bugnote_text, $f_time_tracking, $f_private, BUGNOTE ); if ( !$t_bugnote_id ) { - error_parameters( lang_get( 'bugnote' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'bugnote' ) ); } # Handle the reassign on feedback feature. Note that this feature generally diff --git a/bugnote_edit_page.php b/bugnote_edit_page.php index 6865833582..1ab0865c2a 100644 --- a/bugnote_edit_page.php +++ b/bugnote_edit_page.php @@ -93,8 +93,7 @@ # Check if the bug is readonly if ( bug_is_readonly( $t_bug_id ) ) { - error_parameters( $t_bug_id ); - throw new MantisBT\Exception\Bug_Read_Only_Action_Denied(); + throw new MantisBT\Exception\Bug_Read_Only_Action_Denied( $t_bug_id ); } $t_bugnote_text = string_textarea( bugnote_get_text( $f_bugnote_id ) ); diff --git a/bugnote_set_view_state.php b/bugnote_set_view_state.php index 6dce7e5302..1abb2d404c 100644 --- a/bugnote_set_view_state.php +++ b/bugnote_set_view_state.php @@ -71,8 +71,7 @@ # Check if the bug is readonly $t_bug_id = bugnote_get_field( $f_bugnote_id, 'bug_id' ); if ( bug_is_readonly( $t_bug_id ) ) { - error_parameters( $t_bug_id ); - throw new MantisBT\Exception\Bug_Read_Only_Action_Denied(); + throw new MantisBT\Exception\Bug_Read_Only_Action_Denied( $t_bug_id ); } # Check if the current user is allowed to change the view state of this bugnote diff --git a/bugnote_update.php b/bugnote_update.php index 4ed2d3eb58..6ef707eb6d 100644 --- a/bugnote_update.php +++ b/bugnote_update.php @@ -73,8 +73,7 @@ # Check if the bug is readonly $t_bug_id = bugnote_get_field( $f_bugnote_id, 'bug_id' ); if ( bug_is_readonly( $t_bug_id ) ) { - error_parameters( $t_bug_id ); - throw new MantisBT\Exception\Bug_Read_Only_Action_Denied(); + throw new MantisBT\Exception\Bug_Read_Only_Action_Denied( $t_bug_id ); } $f_bugnote_text = trim( $f_bugnote_text ) . "\n\n"; diff --git a/changelog_page.php b/changelog_page.php index fc1f20012e..edb3090c12 100644 --- a/changelog_page.php +++ b/changelog_page.php @@ -147,8 +147,7 @@ function print_project_header_changelog ( $p_project_name ) { $f_version_id = version_get_id( $f_version, $t_project_id ); if ( $f_version_id === false ) { - error_parameters( $f_version ); - throw new MantisBT\Exception\Version_Not_Found(); + throw new MantisBT\Exception\Version_Not_Found( $f_version ); } } diff --git a/core/bug_api.php b/core/bug_api.php index 91cdb73922..20524217d4 100644 --- a/core/bug_api.php +++ b/core/bug_api.php @@ -219,8 +219,7 @@ function bug_cache_row( $p_bug_id, $p_trigger_errors = false ) { $g_cache_bug[$c_bug_id] = false; if( $p_trigger_errors ) { - error_parameters( $p_bug_id ); - throw new MantisBT\Exception\Bug_Not_Found(); + throw new MantisBT\Exception\Bug_Not_Found( $p_bug_id ); } else { return false; } @@ -377,22 +376,19 @@ private function bug_get_bugnote_count() { function validate( $p_update_extended = true) { # Summary cannot be blank if( is_blank( $this->summary ) ) { - error_parameters( lang_get( 'summary' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'summary' ) ); } if( $p_update_extended ) { # Description field cannot be empty if( is_blank( $this->description ) ) { - error_parameters( lang_get( 'description' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'description' ) ); } } # Make sure a category is set if( 0 == $this->category_id && !config_get( 'allow_no_category' ) ) { - error_parameters( lang_get( 'category' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'category' ) ); } if( !is_blank( $this->duplicate_id ) && ( $this->duplicate_id != 0 ) && ( $this->id == $this->duplicate_id ) ) { @@ -781,8 +777,7 @@ function bug_text_cache_row( $p_bug_id, $p_trigger_errors = true ) { $g_cache_bug_text[$c_bug_id] = false; if( $p_trigger_errors ) { - error_parameters( $p_bug_id ); - throw new MantisBT\Exception\Bug_Not_Found(); + throw new MantisBT\Exception\Bug_Not_Found( $p_bug_id ); } else { return false; } @@ -834,8 +829,7 @@ function bug_exists( $p_bug_id ) { */ function bug_ensure_exists( $p_bug_id ) { if( !bug_exists( $p_bug_id ) ) { - error_parameters( $p_bug_id ); - throw new MantisBT\Exception\Bug_Not_Found(); + throw new MantisBT\Exception\Bug_Not_Found( $p_bug_id ); } } @@ -1257,8 +1251,7 @@ function bug_get_field( $p_bug_id, $p_field_name ) { if( isset( $t_bug_data->{$p_field_name} ) ) { return $t_bug_data->{$p_field_name}; } else { - error_parameters( $p_field_name ); - throw new MantisBT\Exception\DB_Field_Not_Found(); + throw new MantisBT\Exception\DB_Field_Not_Found( $p_field_name ); return ''; } } @@ -1277,8 +1270,7 @@ function bug_get_text_field( $p_bug_id, $p_field_name ) { if( isset( $row[$p_field_name] ) ) { return $row[$p_field_name]; } else { - error_parameters( $p_field_name ); - throw new MantisBT\Exception\DB_Field_Not_Found(); + throw new MantisBT\Exception\DB_Field_Not_Found( $p_field_name ); return ''; } } diff --git a/core/bugnote_api.php b/core/bugnote_api.php index ece1bfbf19..67003800b6 100644 --- a/core/bugnote_api.php +++ b/core/bugnote_api.php @@ -152,8 +152,7 @@ function bugnote_add( $p_bug_id, $p_bugnote_text, $p_time_tracking = '0:00', $p_ if( ON == $t_time_tracking_enabled && $c_time_tracking > 0 ) { if( is_blank( $p_bugnote_text ) && OFF == $t_time_tracking_without_note ) { - error_parameters( lang_get( 'bugnote' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'bugnote' ) ); } $c_type = TIME_TRACKING; } else if( is_blank( $p_bugnote_text ) ) { @@ -606,8 +605,7 @@ function bugnote_stats_get_project_array( $p_project_id, $p_from, $p_to, $p_cost $c_from = strtotime( $p_from ); if ( $c_to === false || $c_from === false ) { - error_parameters( array( $p_form, $p_to ) ); - throw new MantisBT\Exception\Generic(); + throw new MantisBT\Exception\Generic( array( $p_form, $p_to ) ); } if( !is_blank( $c_from ) ) { diff --git a/core/category_api.php b/core/category_api.php index d1cf84918d..75cffedb4b 100644 --- a/core/category_api.php +++ b/core/category_api.php @@ -126,8 +126,7 @@ function category_add( $p_project_id, $p_name ) { $c_project_id = db_prepare_int( $p_project_id ); if( is_blank( $p_name ) ) { - error_parameters( lang_get( 'category' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'category' ) ); } category_ensure_unique( $p_project_id, $p_name ); @@ -149,8 +148,8 @@ function category_add( $p_project_id, $p_name ) { */ function category_update( $p_category_id, $p_name, $p_assigned_to ) { if( is_blank( $p_name ) ) { - error_parameters( lang_get( 'category' ) ); - throw new MantisBT\Exception\Empty_Field(); + error_parameters( ); + throw new MantisBT\Exception\Empty_Field( lang_get( 'category' ) ); } $t_old_category = category_get_row( $p_category_id ); diff --git a/core/classes/MantisDatabase/PDO/PDO.class.php b/core/classes/MantisDatabase/PDO/PDO.class.php index d493218a1f..ec7f1baa37 100644 --- a/core/classes/MantisDatabase/PDO/PDO.class.php +++ b/core/classes/MantisDatabase/PDO/PDO.class.php @@ -37,9 +37,7 @@ public function connect($dsn, $dbhost, $dbuser, $dbpass, $dbname, array $dboptio $driverstatus = $this->driver_installed(); if ($driverstatus !== true) { - error_parameters( 0, 'PHP Support for database is not enabled' ); - throw new MantisBT\Exception\DB_Connect_Failed(); - + throw new MantisBT\Exception\DB_Connect_Failed( 'PHP Support for database is not enabled' ); //throw new MantisDatabaseException('DatabaseDriverProblem', $driverstatus); } diff --git a/core/classes/MantisError.class.php b/core/classes/MantisError.class.php index 2ee66ff153..e9a0046b12 100644 --- a/core/classes/MantisError.class.php +++ b/core/classes/MantisError.class.php @@ -109,7 +109,7 @@ public static function display_errors( $p_no_header = false ) { } $t_oblen = ob_get_length(); - if( error_handled() && $t_oblen > 0 ) { + if( self::error_handled() && $t_oblen > 0 ) { $t_old_contents = ob_get_contents(); } @@ -368,7 +368,17 @@ public static function error_alternate_class() { return 'class="row-2"'; } } - + + /** + * Set additional info parameters to be used when displaying the next error + * This function takes a variable number of parameters + * + * When writing internationalized error strings, note that you can change the + * order of parameters in the string. See the PHP manual page for the + * sprintf() function for more details. + * @access public + * @return null + */ public static function error_parameters( $p_args ) { self::$_parameters = $p_args; } @@ -376,7 +386,12 @@ public static function error_parameters( $p_args ) { public static function error_proceed_url( $p_url ) { self::$_proceed_url = $p_url(); } - + + /** + * Check if we have handled an error during this page + * Return true if an error has been handled, false otherwise + * @return bool + */ public static function error_handled() { return self::$_handled; } diff --git a/core/classes/MantisUser.class.php b/core/classes/MantisUser.class.php index ed69e407db..c16d1e5f71 100644 --- a/core/classes/MantisUser.class.php +++ b/core/classes/MantisUser.class.php @@ -70,8 +70,7 @@ function user_cache_row( $p_user_id, $p_trigger_errors = true ) { return $row; } else { if( $p_trigger_errors ) { - error_parameters( (integer)$p_user_id ); - throw new MantisBT\Exception\User_By_ID_Not_Found(); + throw new MantisBT\Exception\User_By_ID_Not_Found( $p_user_id ); } return false; diff --git a/core/custom_field_api.php b/core/custom_field_api.php index 37f03db615..7cabab668c 100644 --- a/core/custom_field_api.php +++ b/core/custom_field_api.php @@ -118,8 +118,7 @@ function custom_field_cache_row( $p_field_id, $p_trigger_errors = true ) { if( !$row ) { if( $p_trigger_errors ) { - error_parameters( 'Custom ' . $p_field_id ); - throw new MantisBT\Exception\Custom_Field_Not_Found(); + throw new MantisBT\Exception\Custom_Field_Not_Found( 'Custom ' . $p_field_id ); } else { return false; } @@ -253,8 +252,7 @@ function custom_field_ensure_exists( $p_field_id ) { if( custom_field_exists( $p_field_id ) ) { return true; } else { - error_parameters( 'Custom ' . $p_field_id ); - throw new MantisBT\Exception\Custom_Field_Not_Found(); + throw new MantisBT\Exception\Custom_Field_Not_Found( 'Custom ' . $p_field_id ); } } @@ -391,8 +389,7 @@ function custom_field_create( $p_name ) { $c_name = trim( $p_name ); if( is_blank( $c_name ) ) { - error_parameters( 'name' ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( 'name' ); } custom_field_ensure_name_unique( $c_name ); @@ -434,8 +431,7 @@ function custom_field_update( $p_field_id, $p_def_array ) { $c_require_closed = db_prepare_bool( $p_def_array['require_closed'] ); if( is_blank( $c_name ) ) { - error_parameters( 'name' ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( 'name' ); } if(( $c_access_level_rw < $c_access_level_r ) || ( $c_length_min < 0 ) || (( $c_length_max != 0 ) && ( $c_length_min > $c_length_max ) ) ) { diff --git a/core/database_api.php b/core/database_api.php index 7e55636813..70a1cb9720 100644 --- a/core/database_api.php +++ b/core/database_api.php @@ -73,7 +73,6 @@ function db_connect( $p_dsn, $p_hostname = null, $p_username = null, $p_password $t_result = $g_db->connect( $p_dsn, $p_hostname, $p_username, $p_password, $p_database_name, $p_db_options ); if( !$t_result ) { - db_error(); throw new MantisBT\Exception\DB_Connect_Failed(); return false; } @@ -204,7 +203,6 @@ function db_query_bound( $p_query, $arr_parms = null, $p_limit = -1, $p_offset = } if( !$t_result ) { - db_error( $p_query ); throw new MantisBT\Exception\DB_Query_Failed(); return false; } else { @@ -328,19 +326,6 @@ function db_field_names( $p_table_name ) { return is_array( $columns ) ? $columns : array(); } -/** - * send both the error number and error message and query (optional) as paramaters for a triggered error - * @todo Use/Behaviour of this function should be reviewed before 1.2.0 final - */ -function db_error( $p_query = null ) { - global $g_db; - if( null !== $p_query ) { - error_parameters( /* $g_db->ErrorNo(), */ $g_db->get_last_error(), $p_query ); - } else { - error_parameters( /* $g_db->ErrorNo(), */ $g_db->get_last_error() ); - } -} - /** * close the connection. * Not really necessary most of the time since a connection is automatically closed when a page finishes loading. diff --git a/core/email_queue_api.php b/core/email_queue_api.php index 2f1b12f201..d4c982a28b 100644 --- a/core/email_queue_api.php +++ b/core/email_queue_api.php @@ -76,20 +76,17 @@ function email_queue_add( $p_email_data ) { # email cannot be blank if( is_blank( $t_email_data->email ) ) { - error_parameters( lang_get( 'email' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'email' ) ); } # subject cannot be blank if( is_blank( $t_email_data->subject ) ) { - error_parameters( lang_get( 'subject' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'subject' ) ); } # body cannot be blank if( is_blank( $t_email_data->body ) ) { - error_parameters( lang_get( 'body' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'body' ) ); } $c_email = $t_email_data->email; diff --git a/core/error_api.php b/core/error_api.php index af2988701e..3cfebf625d 100644 --- a/core/error_api.php +++ b/core/error_api.php @@ -28,29 +28,6 @@ set_error_handler(array('MantisError', 'error_handler')); register_shutdown_function(array('MantisError', 'shutdown_error_handler')); -/** - * Check if we have handled an error during this page - * Return true if an error has been handled, false otherwise - * @return bool - */ -function error_handled() { - return MantisError::error_handled(); -} - -/** - * Set additional info parameters to be used when displaying the next error - * This function takes a variable number of parameters - * - * When writing internationalized error strings, note that you can change the - * order of parameters in the string. See the PHP manual page for the - * sprintf() function for more details. - * @access public - * @return null - */ -function error_parameters() { - MantisError::error_parameters( func_get_args() ); -} - /** * Set a url to give to the user to proceed after viewing the error * @access public diff --git a/core/filter_api.php b/core/filter_api.php index 9b7d4587ee..cf35bca88b 100644 --- a/core/filter_api.php +++ b/core/filter_api.php @@ -4297,8 +4297,7 @@ function filter_cache_row( $p_filter_id, $p_trigger_errors = true ) { if( !$row ) { if( $p_trigger_errors ) { - error_parameters( $p_filter_id ); - throw new MantisBT\Exception\Filter_Not_Found(); + throw new MantisBT\Exception\Filter_Not_Found( $p_filter_id ); } else { return false; } diff --git a/core/gpc_api.php b/core/gpc_api.php index c968374d42..ffad159266 100644 --- a/core/gpc_api.php +++ b/core/gpc_api.php @@ -75,8 +75,7 @@ function gpc_get( $p_var_name, $p_default = null ) { # check for a default passed in (allowing null) $t_result = $p_default; } else { - error_parameters( $p_var_name ); - throw new MantisBT\Exception\GPC_Var_Not_Found(); + throw new MantisBT\Exception\GPC_Var_Not_Found( $p_var_name ); $t_result = null; } @@ -115,8 +114,7 @@ function gpc_get_string( $p_var_name, $p_default = null ) { $t_result = call_user_func_array( 'gpc_get', $args ); if( is_array( $t_result ) ) { - error_parameters( $p_var_name ); - throw new MantisBT\Exception\GPC_Array_Unexpected(); + throw new MantisBT\Exception\GPC_Array_Unexpected( $p_var_name ); } return $t_result; @@ -137,13 +135,11 @@ function gpc_get_int( $p_var_name, $p_default = null ) { $t_result = call_user_func_array( 'gpc_get', $args ); if( is_array( $t_result ) ) { - error_parameters( $p_var_name ); - throw new MantisBT\Exception\GPC_Array_Unexpected(); + throw new MantisBT\Exception\GPC_Array_Unexpected( $p_var_name ); } $t_val = str_replace( ' ', '', trim( $t_result ) ); if( !preg_match( "/^-?([0-9])*$/", $t_val ) ) { - error_parameters( $p_var_name ); - throw new MantisBT\Exception\GPC_Not_Number(); + throw new MantisBT\Exception\GPC_Not_Number( $p_var_name ); } return (int) $t_val; @@ -163,8 +159,7 @@ function gpc_get_bool( $p_var_name, $p_default = false ) { return $p_default; } else { if( is_array( $t_result ) ) { - error_parameters( $p_var_name ); - throw new MantisBT\Exception\GPC_Array_Unexpected(); + throw new MantisBT\Exception\GPC_Array_Unexpected( $p_var_name ); } return gpc_string_to_bool( $t_result ); @@ -260,8 +255,7 @@ function gpc_get_string_array( $p_var_name, $p_default = null ) { # If we the result isn't the default we were given or an array, error if( !((( 1 < func_num_args() ) && ( $t_result === $p_default ) ) || is_array( $t_result ) ) ) { - error_parameters( $p_var_name ); - throw new MantisBT\Exception\GPC_Array_Expected(); + throw new MantisBT\Exception\GPC_Array_Expected( $p_var_name ); } return $t_result; @@ -283,8 +277,7 @@ function gpc_get_int_array( $p_var_name, $p_default = null ) { # If we the result isn't the default we were given or an array, error if( !((( 1 < func_num_args() ) && ( $t_result === $p_default ) ) || is_array( $t_result ) ) ) { - error_parameters( $p_var_name ); - throw new MantisBT\Exception\GPC_Array_Expected(); + throw new MantisBT\Exception\GPC_Array_Expected( $p_var_name ); } $t_count = count( $t_result ); @@ -310,8 +303,7 @@ function gpc_get_bool_array( $p_var_name, $p_default = null ) { # If we the result isn't the default we were given or an array, error if( !((( 1 < func_num_args() ) && ( $t_result === $p_default ) ) || is_array( $t_result ) ) ) { - error_parameters( $p_var_name ); - throw new MantisBT\Exception\GPC_Array_Expected(); + throw new MantisBT\Exception\GPC_Array_Expected( $p_var_name ); } $t_count = count( $t_result ); @@ -338,8 +330,7 @@ function gpc_get_cookie( $p_var_name, $p_default = null ) { # check for a default passed in (allowing null) $t_result = $p_default; } else { - error_parameters( $p_var_name ); - throw new MantisBT\Exception\GPC_Var_Not_Found(); + throw new MantisBT\Exception\GPC_Var_Not_Found( $p_var_name ); } return $t_result; @@ -435,8 +426,7 @@ function gpc_get_file( $p_var_name, $p_default = null ) { # check for a default passed in (allowing null) $t_result = $p_default; } else { - error_parameters( $p_var_name ); - throw new MantisBT\Exception\GPC_Var_Not_Found(); + throw new MantisBT\Exception\GPC_Var_Not_Found( $p_var_name ); } return $t_result; diff --git a/core/helper_api.php b/core/helper_api.php index b0ca45ae53..0c26c116d4 100644 --- a/core/helper_api.php +++ b/core/helper_api.php @@ -595,22 +595,19 @@ function helper_duration_to_minutes( $p_hhmm ) { // time can be composed of max 3 parts (hh:mm:ss) if( count( $t_a ) > 3 ) { - error_parameters( 'p_hhmm', $p_hhmm ); - throw new MantisBT\Exception\Config_Opt_Invalid(); + throw new MantisBT\Exception\Config_Opt_Invalid( 'p_hhmm', $p_hhmm ); } $t_count = count( $t_a ); for( $i = 0;$i < $t_count;$i++ ) { // all time parts should be integers and non-negative. if( !is_numeric( $t_a[$i] ) || ( (integer) $t_a[$i] < 0 ) ) { - error_parameters( 'p_hhmm', $p_hhmm ); - throw new MantisBT\Exception\Config_Opt_Invalid(); + throw new MantisBT\Exception\Config_Opt_Invalid( 'p_hhmm', $p_hhmm ); } // minutes and seconds are not allowed to exceed 59. if(( $i > 0 ) && ( $t_a[$i] > 59 ) ) { - error_parameters( 'p_hhmm', $p_hhmm ); - throw new MantisBT\Exception\Config_Opt_Invalid(); + throw new MantisBT\Exception\Config_Opt_Invalid( 'p_hhmm', $p_hhmm ); } } diff --git a/core/html_api.php b/core/html_api.php index afd83ac177..bc5e08635d 100644 --- a/core/html_api.php +++ b/core/html_api.php @@ -386,7 +386,7 @@ function html_css_link( $p_filename ) { * @return boolean */ function html_meta_redirect( $p_url, $p_time = null, $p_sanitize = true ) { - if( error_handled() ) { + if( MantisError::error_handled() ) { return false; } diff --git a/core/news_api.php b/core/news_api.php index f570cdd906..9c41157ec1 100644 --- a/core/news_api.php +++ b/core/news_api.php @@ -53,13 +53,11 @@ function news_create( $p_project_id, $p_poster_id, $p_view_state, $p_announcemen $c_announcement = db_prepare_bool( $p_announcement ); if( is_blank( $p_headline ) ) { - error_parameters( lang_get( 'headline' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'headline' ) ); } if( is_blank( $p_body ) ) { - error_parameters( lang_get( 'body' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'body' ) ); } # Add item @@ -105,13 +103,11 @@ function news_update( $p_news_id, $p_project_id, $p_view_state, $p_announcement, $c_announcement = db_prepare_bool( $p_announcement ); if( is_blank( $p_headline ) ) { - error_parameters( lang_get( 'headline' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'headline' ) ); } if( is_blank( $p_body ) ) { - error_parameters( lang_get( 'body' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'body' ) ); } # Update entry diff --git a/core/profile_api.php b/core/profile_api.php index 0e066750ef..77b53d13f4 100644 --- a/core/profile_api.php +++ b/core/profile_api.php @@ -60,20 +60,17 @@ function profile_create( $p_user_id, $p_platform, $p_os, $p_os_build, $p_descrip # platform cannot be blank if( is_blank( $p_platform ) ) { - error_parameters( lang_get( 'platform' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'platform' ) ); } # os cannot be blank if( is_blank( $p_os ) ) { - error_parameters( lang_get( 'operating_system' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'operating_system' ) ); } # os_build cannot be blank if( is_blank( $p_os_build ) ) { - error_parameters( lang_get( 'version' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'version' ) ); } # Add profile @@ -126,20 +123,17 @@ function profile_update( $p_user_id, $p_profile_id, $p_platform, $p_os, $p_os_bu # platform cannot be blank if( is_blank( $p_platform ) ) { - error_parameters( lang_get( 'platform' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'platform' ) ); } # os cannot be blank if( is_blank( $p_os ) ) { - error_parameters( lang_get( 'operating_system' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'operating_system' ) ); } # os_build cannot be blank if( is_blank( $p_os_build ) ) { - error_parameters( lang_get( 'version' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'version' ) ); } # Add item diff --git a/core/sponsorship_api.php b/core/sponsorship_api.php index 507dbdd400..c363269ac6 100644 --- a/core/sponsorship_api.php +++ b/core/sponsorship_api.php @@ -93,8 +93,7 @@ function sponsorship_cache_row( $p_sponsorship_id, $p_trigger_errors = true ) { $g_cache_sponsorships[$c_sponsorship_id] = false; if( $p_trigger_errors ) { - error_parameters( $p_sponsorship_id ); - throw new MantisBT\Exception\Sponsorship_Not_Found(); + throw new MantisBT\Exception\Sponsorship_Not_Found( $p_sponsorship_id ); } else { return false; } @@ -274,8 +273,7 @@ function sponsorship_update_bug( $p_bug_id ) { function sponsorship_set( $p_sponsorship ) { $t_min_sponsorship = config_get( 'minimum_sponsorship_amount' ); if( $p_sponsorship->amount < $t_min_sponsorship ) { - error_parameters( $p_sponsorship->amount, $t_min_sponsorship ); - throw new MantisBT\Exception\Sponsorship_Amount_Too_Low(); + throw new MantisBT\Exception\Sponsorship_Amount_Too_Low( $p_sponsorship->amount, $t_min_sponsorship ); } # if id == 0, check if the specified user is already sponsoring the bug, if so, overwrite diff --git a/core/summary_api.php b/core/summary_api.php index 92c82a9046..2856917236 100644 --- a/core/summary_api.php +++ b/core/summary_api.php @@ -76,8 +76,7 @@ function summary_print_by_enum( $p_enum ) { $t_vars = getClassProperties( 'BugData', 'protected'); if( !array_key_exists( $p_enum, $t_vars ) ) { - error_parameters($p_enum); - throw new MantisBT\Exception\DB_Field_Not_Found(); + throw new MantisBT\Exception\DB_Field_Not_Found( $p_enum ); } $t_filter_prefix = config_get( 'bug_count_hyperlink_prefix' ); diff --git a/core/tag_api.php b/core/tag_api.php index 7b5b652c1e..4afce36d61 100644 --- a/core/tag_api.php +++ b/core/tag_api.php @@ -71,8 +71,7 @@ function tag_exists( $p_tag_id ) { */ function tag_ensure_exists( $p_tag_id ) { if( !tag_exists( $p_tag_id ) ) { - error_parameters( $p_tag_id ); - throw new MantisBT\Exception\Tag_Not_Found(); + throw new MantisBT\Exception\Tag_Not_Found( $p_tag_id ); } } diff --git a/core/user_api.php b/core/user_api.php index 7c478e84cb..7517391cc9 100644 --- a/core/user_api.php +++ b/core/user_api.php @@ -138,8 +138,7 @@ function user_exists( $p_user_id ) { */ function user_ensure_exists( $p_user_id ) { if ( !user_exists( $p_user_id ) ) { - error_parameters( $p_user_id ); - throw new MantisBT\Exception\User_By_ID_Not_Found(); + throw new MantisBT\Exception\User_By_ID_Not_Found( $p_user_id ); } } diff --git a/core/version_api.php b/core/version_api.php index 9dc8a20658..fc799f7b59 100644 --- a/core/version_api.php +++ b/core/version_api.php @@ -117,8 +117,7 @@ function version_cache_row( $p_version_id, $p_trigger_errors = true ) { $g_cache_versions[$c_version_id] = false; if( $p_trigger_errors ) { - error_parameters( $p_version_id ); - throw new MantisBT\Exception\Version_Not_Found(); + throw new MantisBT\Exception\Version_Not_Found( $p_version_id ); } else { return false; } @@ -158,8 +157,7 @@ function version_is_unique( $p_version, $p_project_id = null ) { */ function version_ensure_exists( $p_version_id ) { if( !version_exists( $p_version_id ) ) { - error_parameters( $p_version_id ); - throw new MantisBT\Exception\Version_Not_Found(); + throw new MantisBT\Exception\Version_Not_Found( $p_version_id ); } } diff --git a/manage_proj_cat_add.php b/manage_proj_cat_add.php index 8e25c95db6..92bffc8833 100644 --- a/manage_proj_cat_add.php +++ b/manage_proj_cat_add.php @@ -60,8 +60,7 @@ access_ensure_project_level( config_get( 'manage_project_threshold' ), $f_project_id ); if ( is_blank( $f_name ) ) { - error_parameters( lang_get( 'category' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'category' ) ); } $t_names = explode( '|', $f_name ); diff --git a/manage_user_edit_page.php b/manage_user_edit_page.php index 89853ef563..0ccef567a1 100644 --- a/manage_user_edit_page.php +++ b/manage_user_edit_page.php @@ -67,8 +67,7 @@ } else { $t_user_id = user_get_id_by_name( $f_username ); if ( $t_user_id === false ) { - error_parameters( $f_username ); - throw new MantisBT\Exception\User_By_Name_Not_Found(); + throw new MantisBT\Exception\User_By_Name_Not_Found( $f_username ); } } diff --git a/proj_doc_add.php b/proj_doc_add.php index 599b229193..cd1872c189 100644 --- a/proj_doc_add.php +++ b/proj_doc_add.php @@ -64,8 +64,7 @@ $f_file = gpc_get_file( 'file' ); if ( is_blank( $f_title ) ) { - error_parameters( lang_get( 'title' ) ); - throw new MantisBT\Exception\Empty_Field(); + throw new MantisBT\Exception\Empty_Field( lang_get( 'title' ) ); } file_add( 0, $f_file, 'project', $f_title, $f_description ); diff --git a/return_dynamic_filters.php b/return_dynamic_filters.php index 7da42329ae..6aea653496 100644 --- a/return_dynamic_filters.php +++ b/return_dynamic_filters.php @@ -151,7 +151,6 @@ function return_dynamic_filters_prepend_headers() { if ( !$t_found ) { # error - no function to populate the target (e.g., print_filter_foo) - error_parameters( $f_filter_target ); - throw new MantisBT\Exception\Filter_Not_Found(); + throw new MantisBT\Exception\Filter_Not_Found( $f_filter_target ); } } diff --git a/roadmap_page.php b/roadmap_page.php index 8e82142d63..6ceca38ecc 100644 --- a/roadmap_page.php +++ b/roadmap_page.php @@ -135,8 +135,7 @@ function print_project_header_roadmap( $p_project_name ) { $f_version_id = version_get_id( $f_version, $t_project_id ); if ( $f_version_id === false ) { - error_parameters( $f_version ); - throw new MantisBT\Exception\Version_Not_Found(); + throw new MantisBT\Exception\Version_Not_Found( $f_version ); } }