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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 use File::Path qw(remove_tree);
24 use Module::Load::Conditional qw(can_load);
29 push @INC, C4::Context->config("pluginsdir");
34 C4::Plugins::Handler - Handler Module for running plugins
38 Koha::Plugins::Handler->run({ class => $class, method => $method, cgi => $cgi });
52 my ( $class, $args ) = @_;
54 die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
56 my $plugin_class = $args->{'class'};
57 my $plugin_method = $args->{'method'};
58 my $cgi = $args->{'cgi'};
60 if ( can_load( modules => { $plugin_class => undef } ) ) {
61 my $plugin = $plugin_class->new( { cgi => $cgi } );
62 if ( $plugin->can($plugin_method) ) {
63 $plugin->$plugin_method();
65 warn "Plugin does not have method $plugin_method";
68 warn "Plugin $plugin_class cannot be loaded";
79 my ( $class, $args ) = @_;
80 my $plugin_class = $args->{'class'};
81 my $plugin_dir = C4::Context->config("pluginsdir");
82 my $plugin_path = "$plugin_dir/" . join( '/', split( '::', $args->{'class'} ) );
84 Koha::Plugins::Handler->run( { class => $plugin_class, method => 'uninstall' } );
86 C4::Context->dbh->do( "DELETE FROM plugin_data WHERE plugin_class = ?", undef, ($plugin_class) );
88 unlink("$plugin_path.pm");
89 remove_tree($plugin_path);
99 Kyle M Hall <kyle.m.hall@gmail.com>