Bugzilla.pm 22.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Bugzilla Bug Tracking System.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Bradley Baetz <bbaetz@student.usyd.edu.au>
21
#                 Erik Stambaugh <erik@dasbistro.com>
22
#                 A. Karl Kornel <karl@kornel.name>
23
#                 Marc Schumann <wurblzap@gmail.com>
24 25 26 27 28

package Bugzilla;

use strict;

29 30 31 32 33 34 35 36 37
# We want any compile errors to get to the browser, if possible.
BEGIN {
    # This makes sure we're in a CGI.
    if ($ENV{SERVER_SOFTWARE} && !$ENV{MOD_PERL}) {
        require CGI::Carp;
        CGI::Carp->import('fatalsToBrowser');
    }
}

38
use Bugzilla::Config;
39
use Bugzilla::Constants;
40
use Bugzilla::Auth;
41
use Bugzilla::Auth::Persist::Cookie;
42
use Bugzilla::CGI;
43
use Bugzilla::DB;
44
use Bugzilla::Install::Localconfig qw(read_localconfig);
45
use Bugzilla::Template;
46
use Bugzilla::User;
47 48
use Bugzilla::Error;
use Bugzilla::Util;
49
use Bugzilla::Field;
50
use Bugzilla::Flag;
51 52

use File::Basename;
53
use File::Spec::Functions;
54
use Safe;
55

56 57 58
# This creates the request cache for non-mod_perl installations.
our $_request_cache = {};

59 60 61 62 63 64 65 66
#####################################################################
# Constants
#####################################################################

# Scripts that are not stopped by shutdownhtml being in effect.
use constant SHUTDOWNHTML_EXEMPT => [
    'editparams.cgi',
    'checksetup.pl',
67
    'recode.pl',
68 69
];

70 71 72 73 74
# Non-cgi scripts that should silently exit.
use constant SHUTDOWNHTML_EXIT_SILENTLY => [
    'whine.pl'
];

75 76 77 78
#####################################################################
# Global Code
#####################################################################

79 80 81 82 83 84 85 86 87 88 89 90 91
# The following subroutine is for debugging purposes only.
# Uncommenting this sub and the $::SIG{__DIE__} trap underneath it will
# cause any fatal errors to result in a call stack trace to help track
# down weird errors.
#
#sub die_with_dignity {
#    use Carp ();
#    my ($err_msg) = @_;
#    print $err_msg;
#    Carp::confess($err_msg);
#}
#$::SIG{__DIE__} = \&Bugzilla::die_with_dignity;

92
# Note that this is a raw subroutine, not a method, so $class isn't available.
93
sub init_page {
94
    (binmode STDOUT, ':utf8') if Bugzilla->params->{'utf8'};
95 96 97

    # Some environment variables are not taint safe
    delete @::ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
98 99 100
    # Some modules throw undefined errors (notably File::Spec::Win32) if
    # PATH is undefined.
    $ENV{'PATH'} = '';
101

102 103 104 105 106 107 108 109 110 111 112 113 114 115
    # IIS prints out warnings to the webpage, so ignore them, or log them
    # to a file if the file exists.
    if ($ENV{SERVER_SOFTWARE} && $ENV{SERVER_SOFTWARE} =~ /microsoft-iis/i) {
        $SIG{__WARN__} = sub {
            my ($msg) = @_;
            my $datadir = bz_locations()->{'datadir'};
            if (-w "$datadir/errorlog") {
                my $warning_log = new IO::File(">>$datadir/errorlog");
                print $warning_log $msg;
                $warning_log->close();
            }
        };
    }

116 117 118 119 120 121 122 123 124 125 126 127 128
    # If Bugzilla is shut down, do not allow anything to run, just display a
    # message to the user about the downtime and log out.  Scripts listed in 
    # SHUTDOWNHTML_EXEMPT are exempt from this message.
    #
    # Because this is code which is run live from perl "use" commands of other
    # scripts, we're skipping this part if we get here during a perl syntax 
    # check -- runtests.pl compiles scripts without running them, so we 
    # need to make sure that this check doesn't apply to 'perl -c' calls.
    #
    # This code must go here. It cannot go anywhere in Bugzilla::CGI, because
    # it uses Template, and that causes various dependency loops.
    if (!$^C && Bugzilla->params->{"shutdownhtml"} 
        && lsearch(SHUTDOWNHTML_EXEMPT, basename($0)) == -1)
129
    {
130 131 132 133 134 135 136 137
        # Allow non-cgi scripts to exit silently (without displaying any
        # message), if desired. At this point, no DBI call has been made
        # yet, and no error will be returned if the DB is inaccessible.
        if (lsearch(SHUTDOWNHTML_EXIT_SILENTLY, basename($0)) > -1
            && !i_am_cgi())
        {
            exit;
        }
138

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
        # For security reasons, log out users when Bugzilla is down.
        # Bugzilla->login() is required to catch the logincookie, if any.
        my $user = Bugzilla->login(LOGIN_OPTIONAL);
        my $userid = $user->id;
        Bugzilla->logout();

        my $template = Bugzilla->template;
        my $vars = {};
        $vars->{'message'} = 'shutdown';
        $vars->{'userid'} = $userid;
        # Generate and return a message about the downtime, appropriately
        # for if we're a command-line script or a CGI script.
        my $extension;
        if (i_am_cgi() && (!Bugzilla->cgi->param('ctype')
                           || Bugzilla->cgi->param('ctype') eq 'html')) {
            $extension = 'html';
        }
        else {
            $extension = 'txt';
        }
        print Bugzilla->cgi->header() if i_am_cgi();
        my $t_output;
        $template->process("global/message.$extension.tmpl", $vars, \$t_output)
            || ThrowTemplateError($template->error);
        print $t_output . "\n";
        exit;
165 166 167
    }
}

168 169
init_page() if !$ENV{MOD_PERL};

170 171 172
#####################################################################
# Subroutines and Methods
#####################################################################
173

174
sub template {
175
    my $class = shift;
176 177 178
    $class->request_cache->{language} = "";
    $class->request_cache->{template} ||= Bugzilla::Template->create();
    return $class->request_cache->{template};
179
}
180

181
sub template_inner {
182
    my ($class, $lang) = @_;
183 184 185 186 187
    $lang = defined($lang) ? $lang : ($class->request_cache->{language} || "");
    $class->request_cache->{language} = $lang;
    $class->request_cache->{"template_inner_$lang"}
        ||= Bugzilla::Template->create();
    return $class->request_cache->{"template_inner_$lang"};
188 189
}

190 191
sub cgi {
    my $class = shift;
192 193
    $class->request_cache->{cgi} ||= new Bugzilla::CGI();
    return $class->request_cache->{cgi};
194 195
}

196
sub localconfig {
197 198 199
    my $class = shift;
    $class->request_cache->{localconfig} ||= read_localconfig();
    return $class->request_cache->{localconfig};
200 201
}

202 203
sub params {
    my $class = shift;
204 205
    $class->request_cache->{params} ||= Bugzilla::Config::read_param_file();
    return $class->request_cache->{params};
206 207
}

208 209
sub user {
    my $class = shift;
210 211
    $class->request_cache->{user} ||= new Bugzilla::User;
    return $class->request_cache->{user};
212 213
}

214 215 216 217 218
sub set_user {
    my ($class, $user) = @_;
    $class->request_cache->{user} = $user;
}

219 220
sub sudoer {
    my $class = shift;    
221
    return $class->request_cache->{sudoer};
222 223 224
}

sub sudo_request {
225 226 227
    my ($class, $new_user, $new_sudoer) = @_;
    $class->request_cache->{user}   = $new_user;
    $class->request_cache->{sudoer} = $new_sudoer;
228 229 230
    # NOTE: If you want to log the start of an sudo session, do it here.
}

231 232
sub login {
    my ($class, $type) = @_;
233

234
    return $class->user if $class->user->id;
235

236
    my $authorizer = new Bugzilla::Auth();
237
    $type = LOGIN_REQUIRED if $class->cgi->param('GoAheadAndLogIn');
238
    if (!defined $type || $type == LOGIN_NORMAL) {
239
        $type = $class->params->{'requirelogin'} ? LOGIN_REQUIRED : LOGIN_NORMAL;
240 241
    }
    my $authenticated_user = $authorizer->login($type);
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
    
    # At this point, we now know if a real person is logged in.
    # We must now check to see if an sudo session is in progress.
    # For a session to be in progress, the following must be true:
    # 1: There must be a logged in user
    # 2: That user must be in the 'bz_sudoer' group
    # 3: There must be a valid value in the 'sudo' cookie
    # 4: A Bugzilla::User object must exist for the given cookie value
    # 5: That user must NOT be in the 'bz_sudo_protect' group
    my $sudo_cookie = $class->cgi->cookie('sudo');
    detaint_natural($sudo_cookie) if defined($sudo_cookie);
    my $sudo_target;
    $sudo_target = new Bugzilla::User($sudo_cookie) if defined($sudo_cookie);
    if (defined($authenticated_user)                 &&
        $authenticated_user->in_group('bz_sudoers')  &&
        defined($sudo_cookie)                        &&
        defined($sudo_target)                        &&
        !($sudo_target->in_group('bz_sudo_protect'))
       )
    {
262 263
        $class->set_user($sudo_target);
        $class->request_cache->{sudoer} = $authenticated_user;
264 265
        # And make sure that both users have the same Auth object,
        # since we never call Auth::login for the sudo target.
266
        $sudo_target->set_authorizer($authenticated_user->authorizer);
267 268 269 270

        # NOTE: If you want to do any special logging, do it here.
    }
    else {
271
        $class->set_user($authenticated_user);
272 273
    }
    
274
    return $class->user;
275 276 277
}

sub logout {
278 279
    my ($class, $option) = @_;

280
    # If we're not logged in, go away
281
    return unless $class->user->id;
282 283

    $option = LOGOUT_CURRENT unless defined $option;
284
    Bugzilla::Auth::Persist::Cookie->logout({type => $option});
285
    $class->logout_request() unless $option eq LOGOUT_KEEP_CURRENT;
286 287 288 289 290
}

sub logout_user {
    my ($class, $user) = @_;
    # When we're logging out another user we leave cookies alone, and
291
    # therefore avoid calling Bugzilla->logout() directly.
292
    Bugzilla::Auth::Persist::Cookie->logout({user => $user});
293 294
}

295 296 297 298 299 300 301 302
# just a compatibility front-end to logout_user that gets a user by id
sub logout_user_by_id {
    my ($class, $id) = @_;
    my $user = new Bugzilla::User($id);
    $class->logout_user($user);
}

# hack that invalidates credentials for a single request
303
sub logout_request {
304 305 306
    my $class = shift;
    delete $class->request_cache->{user};
    delete $class->request_cache->{sudoer};
307 308
    # We can't delete from $cgi->cookie, so logincookie data will remain
    # there. Don't rely on it: use Bugzilla->user->login instead!
309 310
}

311
sub dbh {
312
    my $class = shift;
313
    # If we're not connected, then we must want the main db
314
    $class->request_cache->{dbh} ||= $class->request_cache->{dbh_main} 
315
        = Bugzilla::DB::connect_main();
316

317
    return $class->request_cache->{dbh};
318 319
}

320
sub languages {
321 322 323
    my $class = shift;
    return $class->request_cache->{languages}
        if $class->request_cache->{languages};
324 325 326 327 328 329 330 331 332 333 334 335 336

    my @files = glob(catdir(bz_locations->{'templatedir'}, '*'));
    my @languages;
    foreach my $dir_entry (@files) {
        # It's a language directory only if it contains "default" or
        # "custom". This auto-excludes CVS directories as well.
        next unless (-d catdir($dir_entry, 'default')
                  || -d catdir($dir_entry, 'custom'));
        $dir_entry = basename($dir_entry);
        # Check for language tag format conforming to RFC 1766.
        next unless $dir_entry =~ /^[a-zA-Z]{1,8}(-[a-zA-Z]{1,8})?$/;
        push(@languages, $dir_entry);
    }
337
    return $class->request_cache->{languages} = \@languages;
338 339
}

340
sub error_mode {
341
    my ($class, $newval) = @_;
342
    if (defined $newval) {
343
        $class->request_cache->{error_mode} = $newval;
344
    }
345
    return $class->request_cache->{error_mode}
346 347 348 349
        || Bugzilla::Constants::ERROR_MODE_WEBPAGE;
}

sub usage_mode {
350
    my ($class, $newval) = @_;
351 352 353 354 355 356 357 358 359 360
    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);
        }
361 362 363
        elsif ($newval == USAGE_MODE_EMAIL) {
            $class->error_mode(ERROR_MODE_DIE);
        }
364 365 366 367
        else {
            ThrowCodeError('usage_mode_invalid',
                           {'invalid_usage_mode', $newval});
        }
368
        $class->request_cache->{usage_mode} = $newval;
369
    }
370
    return $class->request_cache->{usage_mode}
371
        || Bugzilla::Constants::USAGE_MODE_BROWSER;
372 373
}

374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
sub installation_mode {
    my ($class, $newval) = @_;
    ($class->request_cache->{installation_mode} = $newval) if defined $newval;
    return $class->request_cache->{installation_mode}
        || INSTALLATION_MODE_INTERACTIVE;
}

sub installation_answers {
    my ($class, $filename) = @_;
    if ($filename) {
        my $s = new Safe;
        $s->rdo($filename);

        die "Error reading $filename: $!" if $!;
        die "Error evaluating $filename: $@" if $@;

        # Now read the param back out from the sandbox
        $class->request_cache->{installation_answers} = $s->varglob('answer');
    }
    return $class->request_cache->{installation_answers} || {};
}

396
sub switch_to_shadow_db {
397
    my $class = shift;
398

399 400 401
    if (!$class->request_cache->{dbh_shadow}) {
        if ($class->params->{'shadowdb'}) {
            $class->request_cache->{dbh_shadow} = Bugzilla::DB::connect_shadow();
402
        } else {
403
            $class->request_cache->{dbh_shadow} = request_cache()->{dbh_main};
404 405 406
        }
    }

407
    $class->request_cache->{dbh} = $class->request_cache->{dbh_shadow};
408 409
    # we have to return $class->dbh instead of {dbh} as
    # {dbh_shadow} may be undefined if no shadow DB is used
410 411
    # and no connection to the main DB has been established yet.
    return $class->dbh;
412 413 414
}

sub switch_to_main_db {
415 416
    my $class = shift;

417
    $class->request_cache->{dbh} = $class->request_cache->{dbh_main};
418 419
    # We have to return $class->dbh instead of {dbh} as
    # {dbh_main} may be undefined if no connection to the main DB
420 421
    # has been established yet.
    return $class->dbh;
422 423
}

424 425 426
sub get_fields {
    my $class = shift;
    my $criteria = shift;
427 428 429 430 431
    # This function may be called during installation, and Field::match
    # may fail at that time. so we want to return an empty list in that
    # case.
    my $fields = eval { Bugzilla::Field->match($criteria) } || [];
    return @$fields;
432 433
}

434 435 436 437 438 439 440
sub active_custom_fields {
    my $class = shift;
    if (!exists $class->request_cache->{active_custom_fields}) {
        $class->request_cache->{active_custom_fields} =
          Bugzilla::Field->match({ custom => 1, obsolete => 0 });
    }
    return @{$class->request_cache->{active_custom_fields}};
441 442
}

443 444 445 446 447 448 449 450 451
sub has_flags {
    my $class = shift;

    if (!defined $class->request_cache->{has_flags}) {
        $class->request_cache->{has_flags} = Bugzilla::Flag::has_flags();
    }
    return $class->request_cache->{has_flags};
}

452 453 454 455 456 457
sub hook_args {
    my ($class, $args) = @_;
    $class->request_cache->{hook_args} = $args if $args;
    return $class->request_cache->{hook_args};
}

458 459 460
sub request_cache {
    if ($ENV{MOD_PERL}) {
        require Apache2::RequestUtil;
461
        return Apache2::RequestUtil->request->pnotes();
462 463 464 465
    }
    return $_request_cache;
}

466
# Private methods
467

468 469
# Per-process cleanup. Note that this is a plain subroutine, not a method,
# so we don't have $class available.
470
sub _cleanup {
471 472
    my $main   = Bugzilla->request_cache->{dbh_main};
    my $shadow = Bugzilla->request_cache->{dbh_shadow};
473 474 475 476 477
    foreach my $dbh ($main, $shadow) {
        next if !$dbh;
        $dbh->bz_rollback_transaction() if $dbh->bz_in_transaction;
        $dbh->disconnect;
    }
478
    undef $_request_cache;
479 480
}

481
sub END {
482 483
    # Bugzilla.pm cannot compile in mod_perl.pl if this runs.
    _cleanup() unless $ENV{MOD_PERL};
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
}

1;

__END__

=head1 NAME

Bugzilla - Semi-persistent collection of various objects used by scripts
and modules

=head1 SYNOPSIS

  use Bugzilla;

  sub someModulesSub {
500 501
    Bugzilla->dbh->prepare(...);
    Bugzilla->template->process(...);
502 503 504 505 506 507 508 509 510 511 512 513 514 515
  }

=head1 DESCRIPTION

Several Bugzilla 'things' are used by a variety of modules and scripts. This
includes database handles, template objects, and so on.

This module is a singleton intended as a central place to store these objects.
This approach has several advantages:

=over 4

=item *

516
They're not global variables, so we don't have issues with them staying around
517 518 519 520
with mod_perl

=item *

521
Everything is in one central place, so it's easy to access, modify, and maintain
522 523 524 525 526 527 528 529 530 531 532 533 534 535

=item *

Code in modules can get access to these objects without having to have them
all passed from the caller, and the caller's caller, and....

=item *

We can reuse objects across requests using mod_perl where appropriate (eg
templates), whilst destroying those which are only valid for a single request
(such as the current user)

=back

536
Note that items accessible via this object are demand-loaded when requested.
537 538 539 540 541 542

For something to be added to this object, it should either be able to benefit
from persistence when run under mod_perl (such as the a C<template> object),
or should be something which is globally required by a large ammount of code
(such as the current C<user> object).

543
=head1 METHODS
544

545
Note that all C<Bugzilla> functionality is method based; use C<Bugzilla-E<gt>dbh>
546 547
rather than C<Bugzilla::dbh>. Nothing cares about this now, but don't rely on
that.
548 549 550 551 552 553 554

=over 4

=item C<template>

The current C<Template> object, to be used for output

555 556 557
=item C<template_inner>

If you ever need a L<Bugzilla::Template> object while you're already
558 559 560 561
processing a template, use this. Also use it if you want to specify
the language to use. If no argument is passed, it uses the last
language set. If the argument is "" (empty string), the language is
reset to the current one (the one used by Bugzilla->template).
562

563 564 565 566 567 568
=item C<cgi>

The current C<cgi> object. Note that modules should B<not> be using this in
general. Not all Bugzilla actions are cgi requests. Its useful as a convenience
method for those scripts/templates which are only use via CGI, though.

569 570
=item C<user>

571 572 573 574 575
C<undef> if there is no currently logged in user or if the login code has not
yet been run.  If an sudo session is in progress, the C<Bugzilla::User>
corresponding to the person who is being impersonated.  If no session is in
progress, the current C<Bugzilla::User>.

576 577 578 579 580 581
=item C<set_user>

Allows you to directly set what L</user> will return. You can use this
if you want to bypass L</login> for some reason and directly "log in"
a specific L<Bugzilla::User>. Be careful with it, though!

582 583 584 585 586 587 588 589 590 591 592 593 594
=item C<sudoer>

C<undef> if there is no currently logged in user, the currently logged in user
is not in the I<sudoer> group, or there is no session in progress.  If an sudo
session is in progress, returns the C<Bugzilla::User> object corresponding to
the person who logged in and initiated the session.  If no session is in
progress, returns the C<Bugzilla::User> object corresponding to the currently
logged in user.

=item C<sudo_request>
This begins an sudo session for the current request.  It is meant to be 
used when a session has just started.  For normal use, sudo access should 
normally be set at login time.
595 596 597

=item C<login>

598
Logs in a user, returning a C<Bugzilla::User> object, or C<undef> if there is
599
no logged in user. See L<Bugzilla::Auth|Bugzilla::Auth>, and
600 601
L<Bugzilla::User|Bugzilla::User>.

602 603 604 605 606 607 608 609 610 611 612 613 614
=item C<logout($option)>

Logs out the current user, which involves invalidating user sessions and
cookies. Three options are available from
L<Bugzilla::Constants|Bugzilla::Constants>: LOGOUT_CURRENT (the
default), LOGOUT_ALL or LOGOUT_KEEP_CURRENT.

=item C<logout_user($user)>

Logs out the specified user (invalidating all his sessions), taking a
Bugzilla::User instance.

=item C<logout_by_id($id)>
615

616 617 618
Logs out the user with the id specified. This is a compatibility
function to be used in callsites where there is only a userid and no
Bugzilla::User instance.
619 620 621

=item C<logout_request>

622
Essentially, causes calls to C<Bugzilla-E<gt>user> to return C<undef>. This has the
623
effect of logging out a user for the current request only; cookies and
624
database sessions are left intact.
625

626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
=item C<error_mode>

Call either C<Bugzilla->error_mode(Bugzilla::Constants::ERROR_MODE_DIE)>
or C<Bugzilla->error_mode(Bugzilla::Constants::ERROR_MODE_DIE_SOAP_FAULT)> to
change this flag's default of C<Bugzilla::Constants::ERROR_MODE_WEBPAGE> 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<eval> 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.)

C<Bugzilla->error_mode> will return the current state of this flag.

Note that C<Bugzilla->error_mode> is being called by C<Bugzilla->usage_mode> on
usage mode changes.

=item C<usage_mode>

Call either C<Bugzilla->usage_mode(Bugzilla::Constants::USAGE_MODE_CMDLINE)>
or C<Bugzilla->usage_mode(Bugzilla::Constants::USAGE_MODE_WEBSERVICE)> near the
beginning of your script to change this flag's default of
C<Bugzilla::Constants::USAGE_MODE_BROWSER> and to indicate that Bugzilla is
being called in a non-interactive manner.
This influences error handling because on usage mode changes, C<usage_mode>
calls C<Bugzilla->error_mode> to set an error mode which makes sense for the
usage mode.
653

654
C<Bugzilla->usage_mode> will return the current state of this flag.
655

656 657 658 659 660 661 662 663 664 665
=item C<installation_mode>

Determines whether or not installation should be silent. See 
L<Bugzilla::Constants> for the C<INSTALLATION_MODE> constants.

=item C<installation_answers>

Returns a hashref representing any "answers" file passed to F<checksetup.pl>,
used to automatically answer or skip prompts.

666 667 668 669
=item C<dbh>

The current database handle. See L<DBI>.

670 671 672 673 674
=item C<languages>

Currently installed languages.
Returns a reference to a list of RFC 1766 language tags of installed languages.

675 676 677 678 679 680 681 682
=item C<switch_to_shadow_db>

Switch from using the main database to using the shadow database.

=item C<switch_to_main_db>

Change the database object to refer to the main database.

683 684 685 686 687 688
=item C<params>

The current Parameters of Bugzilla, as a hashref. If C<data/params>
does not exist, then we return an empty hashref. If C<data/params>
is unreadable or is not valid perl, we C<die>.

689 690 691 692 693
=item C<hook_args>

If you are running inside a code hook (see L<Bugzilla::Hook>) this
is how you get the arguments passed to the hook.

694
=back