<<

Bugzilla

NAME

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

SYNOPSIS

  use Bugzilla;

  sub someModulesSub {
    Bugzilla->dbh->prepare(...);
    Bugzilla->template->process(...);
  }

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:

Note that items accessible via this object are demand-loaded when requested.

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 template object), or should be something which is globally required by a large ammount of code (such as the current user object).

METHODS

Note that all Bugzilla functionality is method based; use Bugzilla->dbh rather than Bugzilla::dbh. Nothing cares about this now, but don't rely on that.

template

The current Template object, to be used for output

template_inner

If you ever need a Bugzilla::Template object while you're already 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).

cgi

The current cgi object. Note that modules should 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.

user

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 Bugzilla::User corresponding to the person who is being impersonated. If no session is in progress, the current Bugzilla::User.

set_user

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

sudoer

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

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.
login

Logs in a user, returning a Bugzilla::User object, or undef if there is no logged in user. See Bugzilla::Auth, and Bugzilla::User.

page_requires_login

If the current page always requires the user to log in (for example, enter_bug.cgi or any page called with ?GoAheadAndLogIn=1) then this will return something true. Otherwise it will return false. (This is set when you call "login".)

logout($option)

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

logout_user($user)

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

logout_by_id($id)

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.

logout_request

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

error_mode

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

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

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

usage_mode

Call either Bugzilla-usage_mode(Bugzilla::Constants::USAGE_MODE_CMDLINE)> or Bugzilla-usage_mode(Bugzilla::Constants::USAGE_MODE_WEBSERVICE)> near the beginning of your script to change this flag's default of 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, usage_mode calls Bugzilla-error_mode> to set an error mode which makes sense for the usage mode.

Bugzilla-usage_mode> will return the current state of this flag.

installation_mode

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

installation_answers

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

dbh

The current database handle. See DBI.

languages

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

switch_to_shadow_db

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

switch_to_main_db

Change the database object to refer to the main database.

params

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

hook_args

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

local_timezone

Returns the local timezone of the Bugzilla installation, as a DateTime::TimeZone object. This detection is very time consuming, so we cache this information for future references.

job_queue

Returns a Bugzilla::JobQueue that you can use for queueing jobs. Will throw an error if job queueing is not correctly configured on this Bugzilla installation.

<<