]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 396243: Allow extensions (aka plugins) to extend the WebService interface
authormkanat%bugzilla.org <>
Fri, 19 Oct 2007 12:58:48 +0000 (12:58 +0000)
committermkanat%bugzilla.org <>
Fri, 19 Oct 2007 12:58:48 +0000 (12:58 +0000)
This also includes the first checkin of the example plugin.
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=ghendricks, a=mkanat

.cvsignore
Bugzilla/Hook.pm
extensions/example/code/webservice.pl [new file with mode: 0644]
extensions/example/disabled [new file with mode: 0644]
extensions/example/lib/WSExample.pm [new file with mode: 0644]
xmlrpc.cgi

index 1d378db06e38e06d0d105cf0e2fffa454fcce711..cba381bab8a05481d08b4f0cf358bb98ffedc538 100644 (file)
@@ -4,4 +4,3 @@ data
 localconfig
 index.html
 old-params.txt
-extensions
index a9cfc649ce16e185ab04238e72ad3dc03470afb4..9d65fbe69cf88cc3e20c34251abeccbaa15ac86c 100644 (file)
@@ -62,7 +62,7 @@ __END__
 
 =head1 NAME
 
-Bugzilla::Hook - Extendible extension hooks for Bugzilla code
+Bugzilla::Hook - Extendable extension hooks for Bugzilla code
 
 =head1 SYNOPSIS
 
@@ -193,3 +193,36 @@ definitions. F<checksetup.pl> will automatically add these tables to the
 database when run.
 
 =back
+
+=head2 webservice
+
+This hook allows you to add your own modules to the WebService. (See
+L<Bugzilla::WebService>.)
+
+Params:
+
+=over
+
+=item C<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 
+L<SOAP::Lite/dispatch_with>. You can see how that's used in F<xmlrpc.cgi>.)
+
+The Perl module name must start with C<extensions::yourextension::lib::>
+(replace C<yourextension> with the name of your extension). The C<package>
+declaration inside that module must also start with 
+C<extensions::yourextension::lib::> in that module's code.
+
+Example:
+
+  $dispatch->{Example} = "extensions::example::lib::Example";
+
+And then you'd have a module F<extensions/example/lib/Example.pm>
+
+It's recommended that all the keys you put in C<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).
+
+=back
diff --git a/extensions/example/code/webservice.pl b/extensions/example/code/webservice.pl
new file mode 100644 (file)
index 0000000..cf608c0
--- /dev/null
@@ -0,0 +1,5 @@
+use strict;
+use warnings;
+use Bugzilla;
+my $dispatch = Bugzilla->hook_args->{dispatch};
+$dispatch->{Example} = "extensions::example::lib::WSExample";
diff --git a/extensions/example/disabled b/extensions/example/disabled
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/extensions/example/lib/WSExample.pm b/extensions/example/lib/WSExample.pm
new file mode 100644 (file)
index 0000000..05975b8
--- /dev/null
@@ -0,0 +1,10 @@
+package extensions::example::lib::WSExample;
+use strict;
+use warnings;
+
+use base qw(Bugzilla::WebService);
+
+# This can be called as Example.hello() from XML-RPC.
+sub hello { return 'Hello!'; }
+
+1;
index 227815d267cfa87393d2249425f5e1caee61db16..2ac34e67539fb5ae27d26097d43e50d48e125408 100755 (executable)
@@ -20,6 +20,7 @@ use lib qw(. lib);
 
 use Bugzilla;
 use Bugzilla::Constants;
+use Bugzilla::Hook;
 
 # Use an eval here so that runtests.pl accepts this script even if SOAP-Lite
 # is not installed.
@@ -29,11 +30,16 @@ $@ && ThrowCodeError('soap_not_installed');
 
 Bugzilla->usage_mode(Bugzilla::Constants::USAGE_MODE_WEBSERVICE);
 
+my %hook_dispatch;
+Bugzilla::Hook::process('webservice', { dispatch => \%hook_dispatch });
+local @INC = (bz_locations()->{extensionsdir}, @INC);
+
 my $response = Bugzilla::WebService::XMLRPC::Transport::HTTP::CGI
     ->dispatch_with({'Bugzilla' => 'Bugzilla::WebService::Bugzilla',
                      'Bug'      => 'Bugzilla::WebService::Bug',
                      'User'     => 'Bugzilla::WebService::User',
                      'Product'  => 'Bugzilla::WebService::Product',
+                     %hook_dispatch
                     })
     ->on_action(\&Bugzilla::WebService::handle_login)
     ->handle;