View | Details | Raw Unified | Return to bug 34335
Collapse All | Expand All

(-)a/misc/run_koha_plugin.pl (-1 / +82 lines)
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 [--params '{"msg": "this is awesome"}']
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
=item B<--params>
47
48
You can optionally provide JSON-encoded parameters that will be passed to the plugin method
49
50
=back
51
52
=cut
53
54
use Modern::Perl;
55
use Getopt::Long;
56
use Pod::Usage;
57
use JSON;
58
59
use Koha::Script;
60
use Koha::Plugins::Handler;
61
62
my $class;
63
my $method;
64
my $params;
65
my $json_params;
66
67
GetOptions(
68
    "class=s"  => \$class,
69
    "method=s" => \$method,
70
    "params=s" => \$json_params,
71
) || pod2usage(1);
72
73
if ($json_params) {
74
    my $json = JSON->new;
75
    $params = $json->decode($json_params);
76
}
77
78
if ( $class && $method ) {
79
    my $result = Koha::Plugins::Handler->run( { class => $class, method => $method, params => $params, } );
80
} else {
81
    pod2usage(1);
82
}

Return to bug 34335