Bug 15903 - Remove use of recordpayment in paycollect.pl
[koha.git] / Koha / Plugins / Handler.pm
blob0c0a7b476b15f86576968500249ea71e4687bea2
1 package Koha::Plugins::Handler;
3 # Copyright 2012 Kyle Hall
5 # This file is part of Koha.
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.
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.
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>.
20 use Modern::Perl;
22 use File::Path qw(remove_tree);
24 use Module::Load::Conditional qw(can_load);
26 use C4::Context;
28 BEGIN {
29 push @INC, C4::Context->config("pluginsdir");
30 pop @INC if $INC[-1] eq '.' ;
33 =head1 NAME
35 C4::Plugins::Handler - Handler Module for running plugins
37 =head1 SYNOPSIS
39 Koha::Plugins::Handler->run({ class => $class, method => $method, cgi => $cgi });
40 $p->run();
42 =over 2
44 =cut
46 =item run
48 Runs a plugin
50 =cut
52 sub run {
53 my ( $class, $args ) = @_;
55 return unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
57 my $plugin_class = $args->{'class'};
58 my $plugin_method = $args->{'method'};
59 my $cgi = $args->{'cgi'};
60 my $params = $args->{'params'};
62 if ( can_load( modules => { $plugin_class => undef } ) ) {
63 my $plugin = $plugin_class->new( { cgi => $cgi, enable_plugins => $args->{'enable_plugins'} } );
64 if ( $plugin->can($plugin_method) ) {
65 return $plugin->$plugin_method( $params );
66 } else {
67 warn "Plugin does not have method $plugin_method";
69 } else {
70 warn "Plugin $plugin_class cannot be loaded";
74 =item delete
76 Deletes a plugin
78 =cut
80 sub delete {
81 my ( $class, $args ) = @_;
83 return unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
85 my $plugin_class = $args->{'class'};
86 my $plugin_dir = C4::Context->config("pluginsdir");
87 my $plugin_path = "$plugin_dir/" . join( '/', split( '::', $args->{'class'} ) );
89 Koha::Plugins::Handler->run({
90 class => $plugin_class,
91 method => 'uninstall',
92 enable_plugins => $args->{enable_plugins},
93 });
95 C4::Context->dbh->do( "DELETE FROM plugin_data WHERE plugin_class = ?", undef, ($plugin_class) );
97 unlink("$plugin_path.pm");
98 remove_tree($plugin_path);
102 __END__
104 =back
106 =head1 AUTHOR
108 Kyle M Hall <kyle.m.hall@gmail.com>
110 =cut