<<

Bugzilla::Hook

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

The implementation of extensions is described in Bugzilla::Extension.

There is sample code for every hook in the Example extension, located in extensions/Example/Extension.pm.

How Hooks Work

When a hook named HOOK_NAME is run, Bugzilla looks through all enabled extensions for extensions that implement a subroutine named HOOK_NAME.

See Bugzilla::Extension for more details about how an extension can run code during a hook.

SUBROUTINES

process
Description

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

See Bugzilla::Extension 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 passed as arguments to the hook method in the extension.
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.

admin_editusers_action

This hook allows you to add additional actions to the admin Users page.

Params:

vars

You can add as many new key/value pairs as you want to this hashref. It will be passed to the template.

action

A text which indicates the different behaviors that editusers.cgi will have. With this hook you can change the behavior of an action or add new actions.

user

This is a Bugzilla::User object of the user.

attachment_process_data

This happens at the very beginning process of the attachment creation. You can edit the attachment content itself as well as all attributes of the attachment, before they are validated and inserted into the DB.

Params:

data - A reference pointing either to the content of the file being uploaded or pointing to the filehandle associated with the file.
attributes - A hashref whose keys are the same as the input to "create" in Bugzilla::Attachment. The data in this hashref hasn't been validated yet.

auth_login_methods

This allows you to add new login types to Bugzilla. (See Bugzilla::Auth::Login.)

Params:

modules

This is a hash--a mapping from login-type "names" to the actual module on disk. The keys will be all the values that were passed to "login" in Bugzilla::Auth for the Login parameter. The values are the actual path to the module on disk. (For example, if the key is DB, the value is Bugzilla/Auth/Login/DB.pm.)

For your extension, the path will start with Bugzilla/Extension/Foo/, where "Foo" is the name of your Extension. (See the code in the example extension.)

If your login type is in the hash as a key, you should set that key to the right path to your module. That module's new method will be called, probably with empty parameters. If your login type is not in the hash, you should not set it.

You will be prevented from adding new keys to the hash, so make sure your key is in there before you modify it. (In other words, you can't add in login methods that weren't passed to "login" in Bugzilla::Auth.)

auth_verify_methods

This works just like "auth_login_methods" except it's for login verification methods (See Bugzilla::Auth::Verify.) It also takes a modules parameter, just like "auth_login_methods".

bug_columns

DEPRECATED Use "object_columns" instead.

This allows you to add new fields that will show up in every Bugzilla::Bug object. Note that you will also need to use the "bug_fields" hook in conjunction with this hook to make this work.

Params:

columns - An arrayref containing an array of column names. Push your column name(s) onto the array.

bug_end_of_create

This happens at the end of "create" in Bugzilla::Bug, after all other changes are made to the database. This occurs inside a database transaction.

Params:

bug - The created bug object.
timestamp - The timestamp used for all updates in this transaction, as a SQL date string.

bug_end_of_create_validators

This happens during "create" in Bugzilla::Bug, after all parameters have been validated, but before anything has been inserted into the database.

Params:

params

A hashref. The validated parameters passed to create.

bug_end_of_update

This happens at the end of "update" in Bugzilla::Bug, after all other changes are made to the database. This generally occurs inside a database transaction.

Params:

bug

The changed bug object, with all fields set to their updated values.

old_bug

A bug object pulled from the database before the fields were set to their updated values (so it has the old values available for each field).

timestamp

The timestamp used for all updates in this transaction, as a SQL date string.

changes

The hash of changed fields. $changes->{field} = [old, new]

bug_check_can_change_field

This hook controls what fields users are allowed to change. You can add code here for site-specific policy changes and other customizations.

This hook is only executed if the field's new and old values differ.

Any denies take priority over any allows. So, if another extension denies a change but yours allows the change, the other extension's deny will override your extension's allow.

Params:

bug

Bugzilla::Bug - The current bug object that this field is changing on.

field

The name (from the fielddefs table) of the field that we are checking.

new_value

The new value that the field is being changed to.

old_value

The old value that the field is being changed from.

priv_results

array - This is how you explicitly allow or deny a change. You should only push something into this array if you want to explicitly allow or explicitly deny the change, and thus skip all other permission checks that would otherwise happen after this hook is called. If you don't care about the field change, then don't push anything into the array.

The pushed value should be a choice from the following constants:

PRIVILEGES_REQUIRED_NONE

No privileges required. This explicitly allows a change.

PRIVILEGES_REQUIRED_REPORTER

User is not the reporter, assignee or an empowered user, so deny.

PRIVILEGES_REQUIRED_ASSIGNEE

User is not the assignee or an empowered user, so deny.

PRIVILEGES_REQUIRED_EMPOWERED

User is not a sufficiently empowered user, so deny.

bug_fields

Allows the addition of database fields from the bugs table to the standard list of allowable fields in a Bugzilla::Bug object, so that you can call the field as a method.

Note: You should add here the names of any fields you added in "bug_columns".

Params:

columns - A arrayref containing an array of column names. Push your column name(s) onto the array.

bug_format_comment

Allows you to do custom parsing on comments before they are displayed. You do this by returning two regular expressions: one that matches the section you want to replace, and then another that says what you want to replace that match with.

The matching and replacement will be run with the /g switch on the regex.

Params:

regexes

An arrayref of hashrefs.

You should push a hashref containing two keys (match and replace) in to this array. match is the regular expression that matches the text you want to replace, replace is what you want to replace that text with. (This gets passed into a regular expression like s/$match/$replace/.)

Instead of specifying a regular expression for replace you can also return a coderef (a reference to a subroutine). If you want to use backreferences (using $1, $2, etc. in your replace), you have to use this method--it won't work if you specify $1, $2 in a regular expression for replace. Your subroutine will get a hashref as its only argument. This hashref contains a single key, matches. matches is an arrayref that contains $1, $2, $3, etc. in order, up to $10. Your subroutine should return what you want to replace the full match with. (See the code example for this hook if you want to see how this actually all works in code. It's simpler than it sounds.)

You are responsible for HTML-escaping your returned data. Failing to do so could open a security hole in Bugzilla.

text

A reference to the exact text that you are parsing.

Generally you should not modify this yourself. Instead you should be returning regular expressions using the regexes array.

The text has not been parsed in any way. (So, for example, it is not HTML-escaped. You get "&", not "&amp;".)

bug

The Bugzilla::Bug object that this comment is on. Sometimes this is undef, meaning that we are parsing text that is not on a bug.

comment

A Bugzilla::Comment object representing the comment you are about to parse.

Sometimes this is undef, meaning that we are parsing text that is not a bug comment (but could still be some other part of a bug, like the summary line).

user

The Bugzilla::User object representing the user who will see the text. This is useful to determine how much confidential information can be displayed to the user.

bug_start_of_update

This happens near the beginning of "update" in Bugzilla::Bug, after "update" in Bugzilla::Object is called, but before all other special changes are made to the database. Once use case is this allows for adding your own entries to the changes hash which gets added to the bugs_activity table later keeping you from having to do it yourself. Also this is also helpful if your extension needs to add CC members, flags, keywords, groups, etc. This generally occurs inside a database transaction.

Params:

bug

The changed bug object, with all fields set to their updated values.

old_bug

A bug object pulled from the database before the fields were set to their updated values (so it has the old values available for each field).

timestamp

The timestamp used for all updates in this transaction, as a SQL date string.

changes

The hash of changed fields. $changes->{field} = [old, new]

bug_url_sub_classes

Allows you to add more Bugzilla::BugUrl sub-classes.

See the MoreBugUrl extension to see how things work.

Params:

sub_classes - An arrayref of strings which represent Bugzilla::BugUrl sub-classes.

buglist_columns

This happens in "COLUMNS" in Bugzilla::Search, which determines legal bug list columns for buglist.cgi and colchange.cgi. 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 };

buglist_column_joins

This allows you to join additional tables to display additional columns in buglists. This hook is generally used in combination with the buglist_columns hook.

Params:

column_joins - A hashref containing data to return back to Bugzilla::Search. This hashref contains names of the columns as keys and a hashref about table to join as values. This hashref has the following keys:
table - The name of the additional table to join.
as - (optional) The alias used for the additional table. This alias must not conflict with an existing alias already used in the query.
from - (optional) The name of the column in the bugs table which the additional table should be linked to. If omitted, bug_id will be used.
to - (optional) The name of the column in the additional table which should be linked to the column in the bugs table, see from above. If omitted, bug_id will be used.
join - (optional) Either INNER or LEFT. Determine how the additional table should be joined with the bugs table. If omitted, LEFT is used.

search_operator_field_override

This allows you to modify "OPERATOR_FIELD_OVERRIDE" in Bugzilla::Search, which determines the search functions for fields. It allows you to specify custom search functionality for certain fields.

See "OPERATOR_FIELD_OVERRIDE" in Bugzilla::Search for reference and see the code in the example extension.

Note that the interface to this hook is UNSTABLE and it may change in the future.

Params:

operators - See "OPERATOR_FIELD_OVERRIDE" in Bugzilla::Search to get an idea of the structure.
search - The Bugzilla::Search object.

bugmail_recipients

This allows you to modify the list of users who are going to be receiving a particular bugmail. It also allows you to specify why they are receiving the bugmail.

Users' bugmail preferences will be applied to any users that you add to the list. (So, for example, if you add somebody as though they were a CC on the bug, and their preferences state that they don't get email when they are a CC, they won't get email.)

This hook is called before watchers or globalwatchers are added to the recipient list.

Params:

bug

The Bugzilla::Bug that bugmail is being sent about.

recipients

This is a hashref. The keys are numeric user ids from the profiles table in the database, for each user who should be receiving this bugmail. The values are hashrefs. The keys in these hashrefs correspond to the "relationship" that the user has to the bug they're being emailed about, and the value should always be 1. The "relationships" are described by the various REL_ constants in Bugzilla::Constants.

Here's an example of adding userid 123 to the recipient list as though they were on the CC list:

 $recipients->{123}->{+REL_CC} = 1

(We use + in front of REL_CC so that Perl interprets it as a constant instead of as a string.)

users

This is a hash of Bugzilla::User objects, keyed by id. This is so you can find out more information about any of the user ids in the recipients hash. Every id in the incoming recipients hash will have an object in here. (But if you add additional recipients to the recipients hash, you are not required to add them to this hash.)

diffs

This is a list of hashes, each hash representing a change to the bug. Each hash has the following members: field_name, bug_when, old, new and who (a Bugzilla::User). If appropriate, there will also be attach_id or comment_id; if either is present, there will be isprivate. See _get_diffs in Bugzilla/BugMail.pm to see exactly how it is populated. Warning: the format and existence of the "diffs" parameter is subject to change in future releases of Bugzilla.

bugmail_relationships

There are various sorts of "relationships" that a user can have to a bug, such as Assignee, CC, etc. If you want to add a new type of relationship, you should use this hook.

Params:

relationships

A hashref, where the keys are numbers and the values are strings.

The keys represent a numeric identifier for the relationship. The numeric identifier should be a negative number between -1 and -127. The number must be unique across all extensions. (Negative numbers are used so as not to conflict with relationship identifiers in Bugzilla itself.)

The value is the "name" of this relationship that will show up in email headers in bugmails. The "name" should be short and should contain no spaces.

cgi_headers

This allows you to modify the HTTP headers sent out on every Bugzilla response.

Params:

headers

A hashref, where the keys are header names and the values are header values. Keys need to be lower-case, and begin with a "-". If you use the "_" character it will be converted to "-", and the library will also fix the casing to Camel-Case.

You can delete (some) headers that Bugzilla adds by deleting entries from the hash.

cgi

The CGI object, which may tell you useful things about the response on which to base a decision of whether or not to add a header.

config_add_panels

If you want to add new panels to the Parameters administrative interface, this is where you do it.

Params:

panel_modules

A hashref, where the keys are the "name" of the panel and the value is the Perl module representing that panel. For example, if the name is Auth, the value would be Bugzilla::Config::Auth.

For your extension, the Perl module would start with Bugzilla::Extension::Foo, where "Foo" is the name of your Extension. (See the code in the example extension.)

config_modify_panels

This is how you modify already-existing panels in the Parameters administrative interface. For example, if you wanted to add a new Auth method (modifying Bugzilla::Config::Auth) this is how you'd do it.

Params:

panels

A hashref, where the keys are lower-case panel "names" (like auth, admin, etc.) and the values are hashrefs. The hashref contains a single key, params. params is an arrayref--the return value from get_param_list for that module. You can modify params and your changes will be reflected in the interface.

Adding new keys to panels will have no effect. You should use "config_add_panels" if you want to add new panels.

email_in_before_parse

This happens right after an inbound email is converted into an Email::MIME object, but before we start parsing the email to extract field data. This means the email has already been decoded for you. It gives you a chance to interact with the email itself before email_in starts parsing its content.

mail - An Email::MIME object. The decoded incoming email.
fields - A hashref. The hash which will contain extracted data.

email_in_after_parse

This happens after all the data has been extracted from the email, but before the reporter is validated, during email_in. This lets you do things after the normal parsing of the email, such as sanitizing field data, changing the user account being used to file a bug, etc.

fields - A hashref. The hash containing the extracted field data.

enter_bug_entrydefaultvars

DEPRECATED - Use "template_before_process" instead.

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.

error_catch

This hook allows extensions to catch errors thrown by Bugzilla and take the appropriate actions.

Params:

error

A string representing the error code thrown by Bugzilla. This string matches the error variable in global/user-error.html.tmpl and global/code-error.html.tmpl.

message

If the error mode is set to ERROR_MODE_WEBPAGE, you get a reference to the whole HTML page with the error message in it, including its header and footer. If you need to extract the error message itself, you can do it by looking at the content of the table cell whose ID is error_msg. If the error mode is not set to ERROR_MODE_WEBPAGE, you get a reference to the error message itself.

vars

This hash contains all the data passed to the error template. Its content depends on the error thrown.

flag_end_of_update

This happens at the end of "update_flags" in Bugzilla::Flag, after all other changes are made to the database and after emails are sent. It gives you a before/after snapshot of flags so you can react to specific flag changes. This generally occurs inside a database transaction.

Note that the interface to this hook is UNSTABLE and it may change in the future.

Params:

object - The changed bug or attachment object.
timestamp - The timestamp used for all updates in this transaction, as a SQL date string.
old_flags - The snapshot of flag summaries from before the change.
new_flags - The snapshot of flag summaries after the change. Call my ($removed, $added) = diff_arrays(old_flags, new_flags) to get the list of changed flags, and search for a specific condition like added eq 'review-'.

group_before_delete

This happens in "remove_from_db" in Bugzilla::Group, after we've confirmed that the group can be deleted, but before any rows have actually been removed from the database. This occurs inside a database transaction.

Params:

group - The Bugzilla::Group being deleted.

group_end_of_create

This happens at the end of "create" in Bugzilla::Group, after all other changes are made to the database. This occurs inside a database transaction.

Params:

group

The new Bugzilla::Group object that was just created.

group_end_of_update

This happens at the end of "update" in Bugzilla::Group, after all other changes are made to the database. This occurs inside a database transaction.

Params:

group - The changed Bugzilla::Group object, with all fields set to their updated values.
changes - The hash of changed fields. $changes->{$field} = [$old, $new]

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. If this is true, messages that are always printed by checksetup.pl should be suppressed, but messages about any changes that are just being done this one time should be printed.

install_filesystem

Allows for additional files and directories to be added to the list of files and directories already managed by checksetup.pl. You will be able to also set permissions for the files and directories using this hook. You can also use this hook to create appropriate .htaccess files for any directory to secure its contents. For examples see FILESYSTEM in Bugzilla::Install::Filesystem.

Params:

files

Hash reference of files that are already present when your extension was installed but need to have specific permissions set. Each file key points to another hash reference containing the following settings.

Params:

perms - Permissions to be set on the file.
create_dirs

Hash reference containing the name of each directory that will be created, pointing at its default permissions.

non_recurse_dirs

Hash reference containing directories that we want to set the perms on, but not recurse through. These are directories not created in checksetup.pl. Each directory key's value is the permissions to be set on the directory.

recurse_dirs

Hash reference of directories that will have permissions set for each item inside each of the directories, including the directory itself. Each directory key points to another hash reference containing the following settings.

Params:

files - Permissions to be set on any files beneath the directory.
dirs - Permissions to be set on the directory itself and any directories beneath it.
create_files

Hash reference of additional files to be created. Each file key points to another hash reference containing the following settings.

Params:

perms - The permissions to be set on the file itself.
contents - The contents to be added to the file or leave blank for an empty file.
htaccess

Hash reference containing htaccess files to be created. You can set the permissions for the htaccess as well as the contents of the file. Each file key points to another hash reference containing the following settings.

Params:

perms - Permissions to be set on the htaccess file.
contents - Contents of the htaccess file. It can be set manually or use HT_DEFAULT_DENY defined in Bugzilla::Install::Filesystem to deny all by default.

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 or add new columns to existing tables, do it here. No params are passed.

install_update_db_fielddefs

This is used to update the schema of the fielddefs table before any other schema changes take place. No params are passed.

This hook should only be used for updating the schema of the fielddefs table. Do not modify any other table in this hook. To modify other tables, use the "install_update_db" hook.

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 (preferably the name of your Extension), 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.

job_map

Bugzilla has a system - Bugzilla::JobQueue - for running jobs asynchronously, if the administrator has set it up. This hook allows the addition of mappings from job names to handler classes, so an extension can fire off jobs.

Params:

job_map - The job map hash. Key: the name of the job, as should be passed to Bugzilla->job_queue->insert(). Value: the name of the Perl module which implements the task (an instance of TheSchwartz::Worker).

mailer_before_send

Called right before Bugzilla::Mailer sends a message to the MTA.

Params:

email - The Email::MIME object that's about to be sent.

object_before_create

This happens at the beginning of "create" in Bugzilla::Object.

Params:

class

The name of the class that create was called on. You can check this like if ($class->isa('Some::Class')) in your code, to perform specific tasks before create for only certain classes.

params

A hashref. The set of named parameters passed to create.

object_before_delete

This happens in "remove_from_db" in Bugzilla::Object, after we've confirmed that the object can be deleted, but before any rows have actually been removed from the database. This sometimes occurs inside a database transaction.

Params:

object - The Bugzilla::Object being deleted. You will probably want to check its type like $object->isa('Some::Class') before doing anything with it.

object_before_set

Called during "set" in Bugzilla::Object, before any actual work is done. You can use this to perform actions before a value is changed for specific fields on certain types of objects.

Params:

object

The object that set was called on. You will probably want to do something like if ($object->isa('Some::Class')) in your code to limit your changes to only certain subclasses of Bugzilla::Object.

field

The name of the field being updated in the object.

value

The value being set on the object.

object_columns

This hook allows you to add new "fields" to existing Bugzilla objects, that correspond to columns in their tables.

For example, if you added an example column to the "bugs" table, you would have to also add an example field to the Bugzilla::Bug object in order to access that data via Bug objects.

Don't do anything slow inside this hook--it's called several times on every page of Bugzilla.

Params:

class

The name of the class that this hook is being called on. You can check this like if ($class->isa('Some::Class')) in your code, to add new fields only for certain classes.

columns

An arrayref. Add the string names of columns to this array to add new values to objects.

For example, if you add an example column to a particular table (using "install_update_db"), and then push the string example into this array for the object that uses that table, then you can access the information in that column via $object->{example} on all objects of that type.

This arrayref does not contain the standard column names--you cannot modify or remove standard object columns using this hook.

object_end_of_create

Called at the end of "create" in Bugzilla::Object, after all other changes are made to the database. This occurs inside a database transaction.

Params:

class

The name of the class that create was called on. You can check this like if ($class->isa('Some::Class')) in your code, to perform specific tasks for only certain classes.

object

The created object.

object_end_of_create_validators

Called at the end of "run_create_validators" in Bugzilla::Object. You can use this to run additional validation when creating an object.

If a subclass has overridden run_create_validators, then this usually happens before the subclass does its custom validation.

Params:

class

The name of the class that create was called on. You can check this like if ($class->isa('Some::Class')) in your code, to perform specific tasks for only certain classes.

params

A hashref. The set of named parameters passed to create, modified and validated by the VALIDATORS specified for the object.

object_end_of_set

Called during "set" in Bugzilla::Object, after all the code of the function has completed (so the value has been validated and the field has been set to the new value). You can use this to perform actions after a value is changed for specific fields on certain types of objects.

The new value is not specifically passed to this hook because you can get it as $object->{$field}.

Params:

object

The object that set was called on. You will probably want to do something like if ($object->isa('Some::Class')) in your code to limit your changes to only certain subclasses of Bugzilla::Object.

field

The name of the field that was updated in the object.

object_end_of_set_all

This happens at the end of "set_all" in Bugzilla::Object. This is a good place to call custom set_ functions on objects, or to make changes to an object before update() is called.

Params:

object

The Bugzilla::Object which is being updated. You will probably want to do something like if ($object->isa('Some::Class')) in your code to limit your changes to only certain subclasses of Bugzilla::Object.

params

A hashref. The set of named parameters passed to set_all.

object_end_of_update

Called during "update" in Bugzilla::Object, after changes are made to the database, but while still inside a transaction.

Params:

object

The object that update was called on. You will probably want to do something like if ($object->isa('Some::Class')) in your code to limit your changes to only certain subclasses of Bugzilla::Object.

old_object

The object as it was before it was updated.

changes

The fields that have been changed, in the same format that "update" in Bugzilla::Object returns.

object_update_columns

If you've added fields to bugs via "object_columns", then this hook allows you to say which of those columns should be updated in the database when "update" in Bugzilla::Object is called on the object.

If you don't use this hook, then your custom columns won't be modified in the database by Bugzilla.

Params:

object

The object that is about to be updated. You should check this like if ($object->isa('Some::Class')) in your code, to modify the "update columns" only for certain classes.

columns

An arrayref. Add the string names of columns to this array to allow that column to be updated when update() is called on the object.

This arrayref does not contain the standard column names--you cannot stop standard columns from being updated by using this hook.

object_validators

Allows you to add new items to "VALIDATORS" in Bugzilla::Object for particular classes.

Params:

class

The name of the class that VALIDATORS was called on. You can check this like if ($class->isa('Some::Class')) in your code, to add validators only for certain classes.

validators

A hashref, where the keys are database columns and the values are subroutine references. You can add new validators or modify existing ones. If you modify an existing one, you should remember to call the original validator inside of your modified validator. (This way, several extensions can all modify the same validator.)

page_before_template

This is a simple way to add your own pages to Bugzilla. This hooks page.cgi, which loads templates from template/en/default/pages. For example, page.cgi?id=fields.html loads template/en/default/pages/fields.html.tmpl.

This hook is called right before the template is loaded, so that you can pass your own variables to your own pages.

You can also use this to implement complex custom pages, by doing your own output and then calling exit at the end of the hook, thus preventing the normal page.cgi behavior from occurring.

Params:

page_id

This is the name of the page being loaded, like fields.html.

Note that if two extensions use the same name, it is uncertain which will override the others, so you should be careful with how you name your pages. Usually extensions prefix their pages with a directory named after their extension, so for an extension named "Foo", page ids usually look like foo/mypage.html.

vars

This is a hashref--put variables into here if you want them passed to your template.

path_info_whitelist

By default, Bugzilla removes the Path-Info information from URLs before passing data to CGI scripts. If this information is needed for your customizations, you can enumerate the pages you want to whitelist here.

Params:

whitelist

An array of script names that will not have their Path-Info automatically removed.

post_bug_after_creation

DEPRECATED (Use "bug_end_of_create" instead.)

This happens after a bug is created and before bug mail is sent during post_bug.cgi. Note that this only happens during post_bug.cgi, it doesn't happen during any of the other methods of creating a bug.

Params:

vars - The template vars hashref.

product_confirm_delete

DEPRECATED - Use "template_before_process" instead.

Called before displaying the confirmation message when deleting a product.

Params:

vars - The template vars hashref.

product_end_of_create

Called right after a new product has been created, allowing additional changes to be made to the new product's attributes. This occurs inside of a database transaction, so if the hook throws an error, all previous changes will be rolled back, including the creation of the new product. (However, note that such rollbacks should not normally be used, as some databases that Bugzilla supports have very bad rollback performance. If you want to validate input and throw errors before the Product is created, use "object_end_of_create_validators" instead, or add a validator using "object_validators".)

Params:

product - The new Bugzilla::Product object that was just created.

quicksearch_map

This hook allows you to alter the Quicksearch syntax to include e.g. special searches for custom fields you have.

Params:

map - a hash where the key is the name you want to use in Quicksearch, and the value is the name from the fielddefs table that you want it to map to. You can modify existing mappings or add new ones.

sanitycheck_check

This hook allows for extra sanity checks to be added, for use by sanitycheck.cgi.

Params:

status - a CODEREF that allows status messages to be displayed to the user. (sanitycheck.cgi's Status)

sanitycheck_repair

This hook allows for extra sanity check repairs to be made, for use by sanitycheck.cgi.

Params:

status - a CODEREF that allows status messages to be displayed to the user. (sanitycheck.cgi's Status)

template_before_create

This hook allows you to modify the configuration of Bugzilla::Template objects before they are created. For example, you could add a new global template variable this way.

Params:

config

A hashref--the configuration that will be passed to "new" in Template. See http://template-toolkit.org/docs/modules/Template.html#section_CONFIGURATION_SUMMARY for information on how this configuration variable is structured (or just look at the code for create in Bugzilla::Template.)

template_before_process

This hook is called any time Bugzilla processes a template file, including calls to $template->process, PROCESS statements in templates, and INCLUDE statements in templates. It is not called when templates process a BLOCK, only when they process a file.

This hook allows you to define additional variables that will be available to the template being processed, or to modify the variables that are currently in the template. It works exactly as though you inserted code to modify template variables at the top of a template.

You probably want to restrict this hook to operating only if a certain file is being processed (which is why you get a file argument below). Otherwise, modifying the vars argument will affect every single template in Bugzilla.

Note: This hook is not called if you are already in this hook. (That is, it won't call itself recursively.) This prevents infinite recursion in situations where this hook needs to process a template (such as if this hook throws an error).

Params:

vars

This is the entire set of variables that the current template can see. Technically, this is a Template::Stash object, but you can just use it like a hashref if you want.

file

The name of the template file being processed. This is relative to the main template directory for the language (i.e. for template/en/default/bug/show.html.tmpl, this variable will contain bug/show.html.tmpl).

context

A Template::Context object. Usually you will not have to use this, but if you need information about the template itself (other than just its name), you can get it from here.

user_preferences

This hook allows you to add additional panels to the User Preferences page, and validate data displayed and returned from these panels. It works in combination with the tabs hook available in the template/en/default/account/prefs/prefs.html.tmpl template. To make it work, you must define two templates in your extension: extensions/Foo/template/en/default/hook/account/prefs/prefs-tabs.html.tmpl contains a list of additional panels to include. extensions/Foo/template/en/default/account/prefs/bar.html.tmpl contains the content of the panel itself. See the Example extension to see how things work.

Params:

current_tab

The name of the current panel being viewed by the user. You should always make sure that the name of the panel matches what you expect it to be. Else you could be interacting with the panel of another extension.

save_changes

A boolean which is true when data should be validated and the DB updated accordingly. This means the user clicked the "Submit Changes" button.

handled

This is a reference to a scalar, not a scalar. (So you would set it like $$handled = 1, not like $handled = 1.) Set this to a true value to let Bugzilla know that the passed-in panel is valid and that you have handled it. (Otherwise, Bugzilla will throw an error that the panel is invalid.) Don't set this to true if you didn't handle the panel listed in current_tab.

vars

You can add as many new key/value pairs as you want to this hashref. It will be passed to the template.

webservice

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

Params:

dispatch

A hashref where you can specify the names of your modules and which 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 will most likely start with Bugzilla::Extension::Foo:: (where "Foo" is the name of your extension).

Example:

  $dispatch->{'Example.Blah'} = "Bugzilla::Extension::Example::Webservice::Blah";

And then you'd have a module extensions/Example/lib/Webservice/Blah.pm, and could call methods from that module like Example.Blah.Foo() using the WebServices interface.

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

webservice_error_codes

If your webservice extension throws custom errors, you can set numeric codes for those errors here.

Extensions should use error codes above 10000, unless they are re-using an already-existing error code.

Params:

error_map

A hash that maps the names of errors (like invalid_param) to numbers. See "WS_ERROR_CODE" in Bugzilla::WebService::Constants for an example.

webservice_fix_credentials

This hook allows for altering the credential parameters provided by the client before authentication actually occurs. For example, this can be used to allow mapping of custom parameters to the standard Bugzilla_login and Bugzilla_password parameters.

Params:

params

A hash ref containing the parameters passed into the webservice after they have been obtained from the URL or body of the request.

webservice_rest_request

This hook allows for altering any of the parameters provided by the client after authentication has occured. You are able to change things like renaming of keys, removing values, or adding additional information.

Params:

params

A hash ref containing the parameters passed into the webservice after they have been obtained from the URL or body of the request.

rpc

The current JSONRPC, XMLRPC, or REST object.

webservice_rest_resources

This hook allows for altering of the REST resources data allowing you to add additional paths to perform additional operations or to override the resources already provided by the webservice modules.

Params:

resources

A hash returned from each module loaded that is used to determine which code handler to use based on a regex match of the CGI path.

rpc

The current JSONRPC, XMLRPC, or REST object.

webservice_rest_response

This hook allows for altering the result data or response object that is being returned by the current REST webservice call.

Params:

response

The HTTP response object generated by JSON-RPC library. You can use this to add headers, etc.

result

A reference to a hash that contains the result data.

rpc

The current JSONRPC, XMLRPC, or REST object.

webservice_status_code_map

This hook allows an extension to change the status codes returned by specific webservice errors. The valid internal error codes that Bugzilla generates, and the status codes they map to by default, are defined in the WS_ERROR_CODE constant in Bugzilla::WebService::Constants. When remapping an error, you may wish to use an existing status code constant. Such constants are also in Bugzilla::WebService::Constants and start with STATUS_* such as STATUS_BAD_REQUEST.

Params:

status_code_map

A hash reference containing the current status code mapping.

SEE ALSO

Bugzilla::Extension

<<