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 die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") );
31 push @INC, C4::Context->config("pluginsdir");
36 C4::Plugins::Handler - Handler Module for running plugins
40 Koha::Plugins::Handler->run({ class => $class, method => $method, cgi => $cgi });
54 my ( $class, $args ) = @_;
55 my $plugin_class = $args->{'class'};
56 my $plugin_method = $args->{'method'};
57 my $cgi = $args->{'cgi'};
59 if ( can_load( modules => { $plugin_class => undef } ) ) {
60 my $plugin = $plugin_class->new( { cgi => $cgi } );
61 if ( $plugin->can($plugin_method) ) {
62 $plugin->$plugin_method();
64 warn "Plugin does not have method $plugin_method";
67 warn "Plugin $plugin_class cannot be loaded";
78 my ( $class, $args ) = @_;
79 my $plugin_class = $args->{'class'};
80 my $plugin_dir = C4::Context->config("pluginsdir");
81 my $plugin_path = "$plugin_dir/" . join( '/', split( '::', $args->{'class'} ) );
83 Koha::Plugins::Handler->run( { class => $plugin_class, method => 'uninstall' } );
85 C4::Context->dbh->do( "DELETE FROM plugin_data WHERE plugin_class = ?", undef, ($plugin_class) );
87 unlink("$plugin_path.pm");
88 remove_tree($plugin_path);
98 Kyle M Hall <kyle.m.hall@gmail.com>