<<

# Bugzilla::Hook

- NAME
- SYNOPSIS
- DESCRIPTION
  - How Hooks Work
  - Arguments Passed to Hooks
- SUBROUTINES
- HOOKS
  - buglist-columns
  - enter_bug-entrydefaultvars
  - install-before_final_checks
  - install-requirements
  - install-update_db
  - db_schema-abstract_schema
  - webservice

# NAME

Bugzilla::Hook - Extendable extension hooks for Bugzilla code

# SYNOPSIS

     use Bugzilla::Hook;

     Bugzilla::Hook::process("hookname", { arg => $value, arg2 => $value2 });

# DESCRIPTION

Bugzilla allows extension modules to drop in and add routines at arbitrary points in Bugzilla code. These points are refered to as hooks. When a piece of standard Bugzilla code wants to allow an extension to perform additional functions, it uses Bugzilla::Hook's "process" subroutine to invoke any extension code if installed.

## How Hooks Work

When a hook named `HOOK_NAME` is run, Bugzilla will attempt to invoke any source files named extensions/*/code/HOOK_NAME.pl.

So, for example, if your extension is called "testopia", and you want to have code run during the "install-update_db" hook, you would have a file called extensions/testopia/code/install-update_db.pl that contained perl code to run during that hook.

## Arguments Passed to Hooks

Some hooks have params that are passed to them.

These params are accessible through "hook_args" in Bugzilla. That returns a hashref. Very frequently, if you want your hook to do anything, you have to modify these variables.

# SUBROUTINES

`process`
  Description

    Invoke any code hooks with a matching name from any installed extensions.

    See `customization.xml` in the Bugzilla Guide for more information on Bugzilla's extension mechanism.

  Params
    `$name` - The name of the hook to invoke.
    `$args` - A hashref. The named args to pass to the hook. They will be accessible to the hook via "hook_args" in Bugzilla.
  Returns (nothing)

# HOOKS

This describes what hooks exist in Bugzilla currently. They are mostly in alphabetical order, but some related hooks are near each other instead of being alphabetical.

## buglist-columns

This happens in buglist.cgi after the standard columns have been defined and right before the display column determination. It gives you the opportunity to add additional display columns.

Params:

`columns` - A hashref, where the keys are unique string identifiers for the column being defined and the values are hashrefs with the following fields:
  `name` - The name of the column in the database.
  `title` - The title of the column as displayed to users.

  The definition is structured as:

       $columns->{$id} = { name => $name, title => $title };

## enter_bug-entrydefaultvars

This happens right before the template is loaded on enter_bug.cgi.

Params:

`vars` - A hashref. The variables that will be passed into the template.

## install-before_final_checks

Allows execution of custom code before the final checks are done in checksetup.pl.

Params:

`silent`

  A flag that indicates whether or not checksetup is running in silent mode.

## install-requirements

Because of the way Bugzilla installation works, there can't be a normal hook during the time that checksetup.pl checks what modules are installed. (`Bugzilla::Hook` needs to have those modules installed--it's a chicken-and-egg problem.)

So instead of the way hooks normally work, this hook just looks for two subroutines (or constants, since all constants are just subroutines) in your file, called `OPTIONAL_MODULES` and `REQUIRED_MODULES`, which should return arrayrefs in the same format as `OPTIONAL_MODULES` and `REQUIRED_MODULES` in Bugzilla::Install::Requirements.

These subroutines will be passed an arrayref that contains the current Bugzilla requirements of the same type, in case you want to modify Bugzilla's requirements somehow. (Probably the most common would be to alter a version number or the "feature" element of `OPTIONAL_MODULES`.)

checksetup.pl will add these requirements to its own.

Please remember--if you put something in `REQUIRED_MODULES`, then checksetup.pl cannot complete unless the user has that module installed! So use `OPTIONAL_MODULES` whenever you can.

## install-update_db

This happens at the very end of all the tables being updated during an installation or upgrade. If you need to modify your custom schema, do it here. No params are passed.

## db_schema-abstract_schema

This allows you to add tables to Bugzilla. Note that we recommend that you prefix the names of your tables with some word, so that they don't conflict with any future Bugzilla tables.

If you wish to add new columns to existing Bugzilla tables, do that in "install-update_db".

Params:

`schema` - A hashref, in the format of "ABSTRACT_SCHEMA" in Bugzilla::DB::Schema. Add new hash keys to make new table definitions. checksetup.pl will automatically add these tables to the database when run.

## webservice

This hook allows you to add your own modules to the WebService. (See Bugzilla::WebService.)

Params:

`dispatch`

  A hashref that you can specify the names of your modules and what Perl module handles the functions for that module. (This is actually sent to "dispatch_with" in SOAP::Lite. You can see how that's used in xmlrpc.cgi.)

  The Perl module name must start with `extensions::yourextension::lib::` (replace `yourextension` with the name of your extension). The `package` declaration inside that module must also start with `extensions::yourextension::lib::` in that module's code.

  Example:

        $dispatch->{Example} = "extensions::example::lib::Example";

  And then you'd have a module extensions/example/lib/Example.pm

  It's recommended that all the keys you put in `dispatch` start with the name of your extension, so that you don't conflict with the standard Bugzilla WebService functions (and so that you also don't conflict with other plugins).

<<