From 0ee4621e7828a205189368aa9b8a515574d9c030 Mon Sep 17 00:00:00 2001 From: "wurblzap%gmail.com" <> Date: Sun, 20 Aug 2006 00:20:23 +0000 Subject: Bug 224577: Bugzilla could use a web services interface. Patch by Marc Schumann ; r=mkanat; a=myk --- Bugzilla.pm | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 8 deletions(-) (limited to 'Bugzilla.pm') diff --git a/Bugzilla.pm b/Bugzilla.pm index 21a741e59..19c52ee2f 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -20,6 +20,7 @@ # Contributor(s): Bradley Baetz # Erik Stambaugh # A. Karl Kornel +# Marc Schumann package Bugzilla; @@ -263,13 +264,37 @@ sub dbh { return request_cache()->{dbh}; } -sub batch { +sub error_mode { my $class = shift; my $newval = shift; if (defined $newval) { - request_cache()->{batch} = $newval; + request_cache()->{error_mode} = $newval; } - return request_cache()->{batch} || 0; + return request_cache()->{error_mode} + || Bugzilla::Constants::ERROR_MODE_WEBPAGE; +} + +sub usage_mode { + my $class = shift; + my $newval = shift; + if (defined $newval) { + if ($newval == USAGE_MODE_BROWSER) { + $class->error_mode(ERROR_MODE_WEBPAGE); + } + elsif ($newval == USAGE_MODE_CMDLINE) { + $class->error_mode(ERROR_MODE_DIE); + } + elsif ($newval == USAGE_MODE_WEBSERVICE) { + $class->error_mode(ERROR_MODE_DIE_SOAP_FAULT); + } + else { + ThrowCodeError('usage_mode_invalid', + {'invalid_usage_mode', $newval}); + } + request_cache()->{usage_mode} = $newval; + } + return request_cache()->{usage_mode} + || Bugzilla::Constants::USAGE_MODE_BROWSER; } sub switch_to_shadow_db { @@ -477,12 +502,35 @@ Essentially, causes calls to Cuser> to return C. This has effect of logging out a user for the current request only; cookies and database sessions are left intact. -=item C +=item C + +Call either Cerror_mode(Bugzilla::Constants::ERROR_MODE_DIE)> +or Cerror_mode(Bugzilla::Constants::ERROR_MODE_DIE_SOAP_FAULT)> to +change this flag's default of C and to +indicate that errors should be passed to error mode specific error handlers +rather than being sent to a browser and finished with an exit(). + +This is useful, for example, to keep C blocks from producing wild HTML +on errors, making it easier for you to catch them. +(Remember to reset the error mode to its previous value afterwards, though.) + +Cerror_mode> will return the current state of this flag. + +Note that Cerror_mode> is being called by Cusage_mode> on +usage mode changes. + +=item C + +Call either Cusage_mode(Bugzilla::Constants::USAGE_MODE_CMDLINE)> +or Cusage_mode(Bugzilla::Constants::USAGE_MODE_WEBSERVICE)> near the +beginning of your script to change this flag's default of +C and to indicate that Bugzilla is +being called in a non-interactive manner. +This influences error handling because on usage mode changes, C +calls Cerror_mode> to set an error mode which makes sense for the +usage mode. -Set to true, by calling Bugzilla->batch(1), to indicate that Bugzilla is -being called in a non-interactive manner and errors should be passed to -die() rather than being sent to a browser and finished with an exit(). -Bugzilla->batch will return the current state of this flag. +Cusage_mode> will return the current state of this flag. =item C -- cgit v1.2.3-24-g4f1b