<<

# Bugzilla

- NAME
- SYNOPSIS
- DESCRIPTION
- METHODS
- CACHING
- Methods in need of POD

# 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:

- They're not global variables, so we don't have issues with them staying around with mod_perl
- Everything is in one central place, so it's easy to access, modify, and maintain
- 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....
- 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)

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.

`input_params`

  When running under the WebService, this is a hashref containing the arguments passed to the WebService method that was called. When running in a normal script, this is a hashref containing the contents of the CGI parameters.

  Modifying this hashref will modify the CGI parameters or the WebService arguments (depending on what `input_params` currently represents).

  This should be used instead of "cgi" in situations where your code could be being called by either a normal CGI script or a WebService method, such as during a code hook.

  Note: When `input_params` represents the CGI parameters, any parameter specified more than once (like `foo=bar&foo=baz`) will appear as an arrayref in the hash, but any value specified only once will appear as a scalar. This means that even if a value can appear multiple times, if it only does appear once, then it will be a scalar in `input_params`, not an arrayref.

`user`

  Default `Bugzilla::User` object 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 their 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.

`fields`

  This is the standard way to get arrays or hashes of Bugzilla::Field objects when you need them. It takes the following named arguments in a hashref:

  `by_name`

    If false (or not specified), this method will return an arrayref of the requested fields.

    If true, this method will return a hashref of fields, where the keys are field names and the valules are Bugzilla::Field objects.

  `type`

    Either a single `FIELD_TYPE_*` constant or an arrayref of them. If specified, the returned fields will be limited to the types in the list. If you don't specify this argument, all fields will be returned.

`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_XMLRPC)> 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.

`dbh_main`

  The main database handle. See DBI.

`languages`

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

`current_language`

  The currently active language.

`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.json` does not exist, then we return an empty hashref. If `data/params.json` is unreadable or is not valid, we `die`.

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

`markdown`

  The current Markdown object, to be used for Markdown rendering.

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

`feature`

  Tells you whether or not a specific feature is enabled. For names of features, see `OPTIONAL_MODULES` in `Bugzilla::Install::Requirements`.

# CACHING

Bugzilla has several different caches available which provide different capabilities and lifetimes.

The keys of all caches are unregulated; use of prefixes is suggested to avoid collisions.

Request Cache

  The request cache is a hashref which supports caching any perl variable for the duration of the current request. At the end of the current request the contents of this cache are cleared.

  Examples of its use include caching objects to avoid re-fetching the same data from the database, and passing data between otherwise unconnected parts of Bugzilla.

  `request_cache`

    Returns a hashref which can be checked and modified to store any perl variable for the duration of the current request.

  `clear_request_cache`

    Removes all entries from the `request_cache`.

Process Cache

  The process cache is a hashref which support caching of any perl variable. If Bugzilla is configured to run using Apache mod_perl, the contents of this cache are persisted across requests for the lifetime of the Apache worker process (which varies depending on the SizeLimit configuration in mod_perl.pl).

  If Bugzilla isn't running under mod_perl, the process cache's contents are cleared at the end of the request.

  The process cache is only suitable for items which never change while Bugzilla is running (for example the path where Bugzilla is installed).

  `process_cache`

    Returns a hashref which can be checked and modified to store any perl variable for the duration of the current process (mod_perl) or request (mod_cgi).

Memcached

  If Memcached is installed and configured, Bugzilla can use it to cache data across requests and between webheads. Unlike the request and process caches, only scalars, hashrefs, and arrayrefs can be stored in Memcached.

  Memcached integration is only required for large installations of Bugzilla -- if you have multiple webheads then configuring Memcached is recommended.

  `memcached`

    Returns a `Bugzilla::Memcached` object. An object is always returned even if Memcached is not available.

    See the documentation for the `Bugzilla::Memcached` module for more information.

# Methods in need of POD

init_page
extensions
logout_user_by_id
localconfig
active_custom_fields
has_flags

<<