Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Copyright 2023 Koha Development Team |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
20 |
|
21 |
=head1 NAME |
22 |
|
23 |
run_koha_plugin.pl - Script to execute a Koha plugin from the CLI |
24 |
|
25 |
=head1 SYNOPSIS |
26 |
|
27 |
./run_koha_plugin --class Koha::Plugin::Awesome --method awesome_method |
28 |
|
29 |
=head1 DESCRIPTION |
30 |
|
31 |
This script will load the specified Koha plugin class and run the specified method |
32 |
|
33 |
=head1 OPTIONS |
34 |
|
35 |
=over |
36 |
|
37 |
=item B<--class> |
38 |
|
39 |
This is the class/package name of the Koha plugin in Perl module syntax |
40 |
|
41 |
=item B<--method> |
42 |
|
43 |
This is the name of the method to run. It must already be registered in Koha's |
44 |
database. |
45 |
|
46 |
=back |
47 |
|
48 |
=cut |
49 |
|
50 |
use Modern::Perl; |
51 |
use Getopt::Long; |
52 |
use Pod::Usage; |
53 |
use JSON; |
54 |
|
55 |
use Koha::Script; |
56 |
use Koha::Plugins::Handler; |
57 |
|
58 |
my $class; |
59 |
my $method; |
60 |
my $params; |
61 |
my $json_params; |
62 |
|
63 |
GetOptions( |
64 |
"class=s" => \$class, |
65 |
"method=s" => \$method, |
66 |
"params=s" => \$json_params, |
67 |
) || pod2usage(1); |
68 |
|
69 |
if ($json_params){ |
70 |
my $json = JSON->new; |
71 |
$params = $json->decode($json_params); |
72 |
} |
73 |
|
74 |
if ( $class && $method ) { |
75 |
my $result = Koha::Plugins::Handler->run( { class => $class, method => $method, params => $params, } ); |
76 |
} else { |
77 |
pod2usage(1); |
78 |
} |