Merge branch 'bug_7804' into 3.12-master

This commit is contained in:
Jared Camins-Esakov 2013-03-20 14:51:23 -04:00
commit fb28e0e53d
46 changed files with 1127 additions and 18 deletions

View File

@ -133,7 +133,7 @@ EOQ
sub get_template_and_user {
my $in = shift;
my $template =
C4::Templates::gettemplate( $in->{'template_name'}, $in->{'type'}, $in->{'query'} );
C4::Templates::gettemplate( $in->{'template_name'}, $in->{'type'}, $in->{'query'}, $in->{'is_plugin'} );
my ( $user, $cookie, $sessionID, $flags );
if ( $in->{'template_name'} !~m/maintenance/ ) {
( $user, $cookie, $sessionID, $flags ) = checkauth(
@ -202,6 +202,7 @@ sub get_template_and_user {
$template->param( CAN_user_serials => 1 );
$template->param( CAN_user_reports => 1 );
$template->param( CAN_user_staffaccess => 1 );
$template->param( CAN_user_plugins => 1 );
foreach my $module (keys %$all_perms) {
foreach my $subperm (keys %{ $all_perms->{$module} }) {
$template->param( "CAN_user_${module}_${subperm}" => 1 );
@ -366,6 +367,7 @@ sub get_template_and_user {
OPACLocalCoverImages => C4::Context->preference('OPACLocalCoverImages'),
AllowMultipleCovers => C4::Context->preference('AllowMultipleCovers'),
EnableBorrowerFiles => C4::Context->preference('EnableBorrowerFiles'),
UseKohaPlugins => C4::Context->preference('UseKohaPlugins'),
);
}
else {

View File

@ -634,6 +634,46 @@ our $PERL_DEPS = {
'required' => '1',
'min_ver' => '0.22',
},
'File::Temp' => {
'usage' => 'Plugins',
'required' => '0',
'min_ver' => '0.22',
},
'File::Copy' => {
'usage' => 'Plugins',
'required' => '0',
'min_ver' => '2.08',
},
'File::Path' => {
'usage' => 'Plugins',
'required' => '0',
'min_ver' => '2.07',
},
'Archive::Extract' => {
'usage' => 'Plugins',
'required' => '0',
'min_ver' => '0.60',
},
'Archive::Zip' => {
'usage' => 'Plugins',
'required' => '0',
'min_ver' => '1.30',
},
'Module::Load::Conditional' => {
'usage' => 'Plugins',
'required' => '0',
'min_ver' => '0.38',
},
'Module::Bundled::Files' => {
'usage' => 'Plugins',
'required' => '0',
'min_ver' => '0.03',
},
'Module::Pluggable' => {
'usage' => 'Plugins',
'required' => '0',
'min_ver' => '3.9',
},
};
1;

View File

@ -228,13 +228,15 @@ sub _get_template_file {
sub gettemplate {
my ( $tmplbase, $interface, $query ) = @_;
my ( $tmplbase, $interface, $query, $is_plugin ) = @_;
($query) or warn "no query in gettemplate";
my $path = C4::Context->preference('intranet_includes') || 'includes';
$tmplbase =~ s/\.tmpl$/.tt/;
my ($htdocs, $theme, $lang, $filename)
= _get_template_file($tmplbase, $interface, $query);
$filename = $tmplbase if ( $is_plugin );
my $template = C4::Templates->new($interface, $filename, $tmplbase, $query);
# NOTE: Commenting these out rather than deleting them so that those who need
# to know how we previously shimmed these directories will be able to understand.
# my $is_intranet = $interface eq 'intranet';

87
Koha/Plugins.pm Normal file
View File

@ -0,0 +1,87 @@
package Koha::Plugins;
# Copyright 2012 Kyle Hall
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use Modern::Perl;
use Module::Load::Conditional qw(can_load);
use Module::Pluggable search_path => ['Koha::Plugin'];
use C4::Context;
use C4::Output;
BEGIN {
push @INC, C4::Context->config("pluginsdir");
}
=head1 NAME
Koha::Plugins - Module for loading and managing plugins.
=cut
sub new {
my ( $class, $args ) = @_;
return unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
$args->{'pluginsdir'} = C4::Context->config("pluginsdir");
return bless( $args, $class );
}
=head2 GetPlugins()
This will return a list of all the available plugins of the passed type.
Usage: my @plugins = C4::Plugins::GetPlugins( $method );
At the moment, the available types are 'report' and 'tool'.
=cut
sub GetPlugins {
my $self = shift;
my $method = shift;
my @plugin_classes = $self->plugins();
my @plugins;
foreach my $plugin_class (@plugin_classes) {
if ( can_load( modules => { $plugin_class => undef } ) ) {
my $plugin = $plugin_class->new();
if ($method) {
if ( $plugin->can($method) ) {
push( @plugins, $plugin );
}
} else {
push( @plugins, $plugin );
}
}
}
return @plugins;
}
1;
__END__
=head1 AUTHOR
Kyle M Hall <kyle.m.hall@gmail.com>
=cut

187
Koha/Plugins/Base.pm Normal file
View File

@ -0,0 +1,187 @@
package Koha::Plugins::Base;
# Copyright 2012 Kyle Hall
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use Modern::Perl;
use Module::Pluggable require => 1;
use base qw{Module::Bundled::Files};
use C4::Context;
use C4::Auth;
BEGIN {
push @INC, C4::Context->config("pluginsdir");
}
=head1 NAME
C4::Plugins::Base - Base Module for plugins
=cut
sub new {
my ( $class, $args ) = @_;
return unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
$args->{'class'} = $class;
$args->{'template'} = Template->new( { ABSOLUTE => 1 } );
my $self = bless( $args, $class );
## Run the installation method if it exists and hasn't been run before
if ( $self->can('install') && !$self->retrieve_data('__INSTALLED__') ) {
if ( $self->install() ) {
$self->store_data( { '__INSTALLED__' => 1 } );
} else {
warn "Plugin $class failed during installation!";
}
}
return $self;
}
=head2 store_data
store_data allows a plugin to store key value pairs in the database for future use.
usage: $self->store_data({ param1 => 'param1val', param2 => 'param2value' })
=cut
sub store_data {
my ( $self, $data ) = @_;
my $dbh = C4::Context->dbh;
my $sql = "REPLACE INTO plugin_data SET plugin_class = ?, plugin_key = ?, plugin_value = ?";
my $sth = $dbh->prepare($sql);
foreach my $key ( keys %$data ) {
$sth->execute( $self->{'class'}, $key, $data->{$key} );
}
}
=head2 retrieve_data
retrieve_data allows a plugin to read the values that were previously saved with store_data
usage: my $value = $self->retrieve_data( $key );
=cut
sub retrieve_data {
my ( $self, $key ) = @_;
my $dbh = C4::Context->dbh;
my $sql = "SELECT plugin_value FROM plugin_data WHERE plugin_class = ? AND plugin_key = ?";
my $sth = $dbh->prepare($sql);
$sth->execute( $self->{'class'}, $key );
my $row = $sth->fetchrow_hashref();
return $row->{'plugin_value'};
}
=head2 get_template
get_template returns a Template object. Eventually this will probably be calling
C4:Template, but at the moment, it does not.
=cut
sub get_template {
my ( $self, $args ) = @_;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{ template_name => $self->mbf_path( $args->{'file'} ),
query => $self->{'cgi'},
type => "intranet",
authnotrequired => 1,
# flagsrequired => { tools => '*' },
is_plugin => 1,
}
);
$template->param(
CLASS => $self->{'class'},
METHOD => $self->{'cgi'}->param('method'),
PLUGIN_PATH => $self->get_plugin_http_path(),
);
return $template;
}
sub get_metadata {
my ( $self, $args ) = @_;
return $self->{'metadata'};
}
=head2 get_qualified_table_name
To avoid naming conflict, each plugins tables should use a fully qualified namespace.
To avoid hardcoding and make plugins more flexible, this method will return the proper
fully qualified table name.
usage: my $table = $self->get_qualified_table_name( 'myTable' );
=cut
sub get_qualified_table_name {
my ( $self, $table_name ) = @_;
return lc( join( '_', split( '::', $self->{'class'} ), $table_name ) );
}
=head2 get_plugin_http_path
To access a plugin's own resources ( images, js files, css files, etc... )
a plugin will need to know what path to use in the template files. This
method returns that path.
usage: my $path = $self->get_plugin_http_path();
=cut
sub get_plugin_http_path {
my ($self) = @_;
return "/plugin/" . join( '/', split( '::', $self->{'class'} ) );
}
=head2 go_home
go_home is a quick redirect to the Koha plugins home page
=cut
sub go_home {
my ( $self, $params ) = @_;
print $self->{'cgi'}->redirect("/cgi-bin/koha/plugins/plugins-home.pl");
}
1;
__END__
=head1 AUTHOR
Kyle M Hall <kyle.m.hall@gmail.com>
=cut

101
Koha/Plugins/Handler.pm Normal file
View File

@ -0,0 +1,101 @@
package Koha::Plugins::Handler;
# Copyright 2012 Kyle Hall
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use Modern::Perl;
use File::Path qw(remove_tree);
use Module::Load::Conditional qw(can_load);
use C4::Context;
BEGIN {
push @INC, C4::Context->config("pluginsdir");
}
=head1 NAME
C4::Plugins::Handler - Handler Module for running plugins
=head1 SYNOPSIS
Koha::Plugins::Handler->run({ class => $class, method => $method, cgi => $cgi });
$p->run();
=over 2
=cut
=item run
Runs a plugin
=cut
sub run {
my ( $class, $args ) = @_;
return unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
my $plugin_class = $args->{'class'};
my $plugin_method = $args->{'method'};
my $cgi = $args->{'cgi'};
if ( can_load( modules => { $plugin_class => undef } ) ) {
my $plugin = $plugin_class->new( { cgi => $cgi } );
if ( $plugin->can($plugin_method) ) {
return $plugin->$plugin_method();
} else {
warn "Plugin does not have method $plugin_method";
}
} else {
warn "Plugin $plugin_class cannot be loaded";
}
}
=item delete
Deletes a plugin
=cut
sub delete {
my ( $class, $args ) = @_;
my $plugin_class = $args->{'class'};
my $plugin_dir = C4::Context->config("pluginsdir");
my $plugin_path = "$plugin_dir/" . join( '/', split( '::', $args->{'class'} ) );
Koha::Plugins::Handler->run( { class => $plugin_class, method => 'uninstall' } );
C4::Context->dbh->do( "DELETE FROM plugin_data WHERE plugin_class = ?", undef, ($plugin_class) );
unlink("$plugin_path.pm");
remove_tree($plugin_path);
}
1;
__END__
=back
=head1 AUTHOR
Kyle M Hall <kyle.m.hall@gmail.com>
=cut

View File

@ -230,6 +230,10 @@ Directory for Apache and Zebra logs produced by Koha.
Directory for backup files produced by Koha.
=item PLUGINS_DIR
Directory for external Koha plugins.
=item PAZPAR2_CONF_DIR
Directory for PazPar2 configuration files.
@ -310,6 +314,7 @@ my $target_map = {
'./skel/var/lib/koha/zebradb/biblios/register' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
'./skel/var/lib/koha/zebradb/biblios/shadow' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
'./skel/var/lib/koha/zebradb/biblios/tmp' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
'./skel/var/lib/koha/plugins' => { target => 'PLUGINS_DIR', trimdir => 6 },
'./sms' => 'INTRANET_CGI_DIR',
'./suggestion' => 'INTRANET_CGI_DIR',
'./svc' => 'INTRANET_CGI_DIR',
@ -1235,6 +1240,7 @@ sub get_target_directories {
$dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
$dirmap{'LOG_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'log');
$dirmap{'BACKUP_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'spool');
$dirmap{'PLUGINS_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'koha', 'plugins');
$dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
$dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
} elsif ($mode eq 'dev') {
@ -1265,6 +1271,7 @@ sub get_target_directories {
$dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
$dirmap{'LOG_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'log');
$dirmap{'BACKUP_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'spool');
$dirmap{'PLUGINS_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'plugins');
$dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
$dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
} else {
@ -1287,6 +1294,7 @@ sub get_target_directories {
$dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lock', $package, 'zebradb');
$dirmap{'LOG_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'log', $package);
$dirmap{'BACKUP_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'spool', $package);
$dirmap{'PLUGINS_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'plugins');
$dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'zebradb');
$dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'run', $package, 'zebradb');
}
@ -1560,7 +1568,7 @@ make_upgrade_backup ::
\t\$(NOECHO) umask 022; \$(MOD_BACKUP) \\
/;
foreach my $key (qw/KOHA_CONF_DIR INTRANET_TMPL_DIR INTRANET_WWW_DIR OPAC_TMPL_DIR OPAC_WWW_DIR
PAZPAR2_CONF_DIR ZEBRA_CONF_DIR/) {
PAZPAR2_CONF_DIR ZEBRA_CONF_DIR PLUGINS_DIR/) {
$upgrade .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or
exists $skip_directories->{$key} or

View File

@ -257,6 +257,8 @@
<biblioservershadow>1</biblioservershadow>
<authorityserver>authorities</authorityserver>
<authorityservershadow>1</authorityservershadow>
<pluginsdir>__PLUGINS_DIR__</pluginsdir>
<enable_plugins>0</enable_plugins>
<intranetdir>/usr/share/koha/intranet/cgi-bin</intranetdir>
<opacdir>/usr/share/koha/opac/cgi-bin/opac</opacdir>
<opachtdocs>/usr/share/koha/opac/htdocs/opac-tmpl</opachtdocs>

View File

@ -276,6 +276,7 @@ __PAZPAR2_TOGGLE_XML_POST__
<biblioservershadow>1</biblioservershadow>
<authorityserver>authorities</authorityserver>
<authorityservershadow>1</authorityservershadow>
<pluginsdir>__PLUGINS_DIR__</pluginsdir>
<intranetdir>__INTRANET_CGI_DIR__</intranetdir>
<opacdir>__OPAC_CGI_DIR__/opac</opacdir>
<opachtdocs>__OPAC_TMPL_DIR__</opachtdocs>

View File

@ -105,6 +105,7 @@
ScriptAlias /cgi-bin/koha/ "__INTRANET_CGI_DIR__/"
ScriptAlias /index.html "__INTRANET_CGI_DIR__/mainpage.pl"
ScriptAlias /search "__INTRANET_CGI_DIR__/search.pl"
Alias /plugin/ "__PLUGINS_DIR__/"
ErrorLog __LOG_DIR__/koha-error_log
# TransferLog __LOG_DIR__/koha-access.log
SetEnv KOHA_CONF "__KOHA_CONF_DIR__/koha-conf.xml"

View File

@ -15,3 +15,4 @@ INSERT INTO `userflags` VALUES(14,'editauthorities','Normdaten ändern',0);
INSERT INTO `userflags` VALUES(15,'serials','Zugang auf Abonnementverwaltung/Zeitschriftenmodul',0);
INSERT INTO `userflags` VALUES(16,'reports','Zugang auf Reportmodul',0);
INSERT INTO `userflags` VALUES(17,'staffaccess','Berechtigungen für Bibliotheksmitarbeiter vergeben',0);
INSERT INTO `userflags` VALUES(19, 'plugins', 'Koha plugins', '0');

View File

@ -52,5 +52,8 @@ INSERT INTO permissions (module_bit, code, description) VALUES
(15, 'renew_subscription', 'Abonnements verlängern'),
(15, 'routing', 'Umlauflisten verwalten'),
(16, 'execute_reports', 'SQL-Reports ausführen'),
(16, 'create_reports', 'SQL-Reports erstellen')
(16, 'create_reports', 'SQL-Reports erstellen'),
(19, 'tool', 'Use tool plugins'),
(19, 'report', 'Use report plugins'),
(19, 'configure', 'Configure plugins')
;

View File

@ -15,3 +15,4 @@ INSERT INTO `userflags` VALUES(14,'editauthorities','Edit Authorities',0);
INSERT INTO `userflags` VALUES(15,'serials','Manage serial subscriptions',0);
INSERT INTO `userflags` VALUES(16,'reports','Allow access to the reports module',0);
INSERT INTO `userflags` VALUES(17,'staffaccess','Allow staff members to modify permissions for other staff members',0);
INSERT INTO `userflags` VALUES(19, 'plugins', 'Koha plugins', '0');

View File

@ -52,5 +52,9 @@ INSERT INTO permissions (module_bit, code, description) VALUES
(15, 'renew_subscription', 'Renew a subscription'),
(15, 'routing', 'Routing'),
(16, 'execute_reports', 'Execute SQL reports'),
(16, 'create_reports', 'Create SQL Reports')
(16, 'create_reports', 'Create SQL Reports'),
(19, 'manage', 'Manage plugins ( install / uninstall )'),
(19, 'tool', 'Use tool plugins'),
(19, 'report', 'Use report plugins'),
(19, 'configure', 'Configure plugins')
;

View File

@ -15,3 +15,4 @@ INSERT INTO `userflags` VALUES(14,'editauthorities','Allow to edit authorities',
INSERT INTO `userflags` VALUES(15,'serials','Allow to manage serials subscriptions',0);
INSERT INTO `userflags` VALUES(16,'reports','Allow to access to the reports module',0);
INSERT INTO `userflags` VALUES(17,'staffaccess','Modify login / permissions for staff users',0);
INSERT INTO `userflags` VALUES(19, 'plugins', 'Koha plugins', '0');

View File

@ -52,5 +52,8 @@ INSERT INTO permissions (module_bit, code, description) VALUES
(15, 'renew_subscription', 'Renew a subscription'),
(15, 'routing', 'Routing'),
(16, 'execute_reports', 'Execute SQL reports'),
(16, 'create_reports', 'Create SQL Reports')
(16, 'create_reports', 'Create SQL Reports'),
(19, 'tool', 'Use tool plugins'),
(19, 'report', 'Use report plugins'),
(19, 'configure', 'Configure plugins')
;

View File

@ -16,3 +16,4 @@ INSERT INTO `userflags` VALUES(13,'tools','Outils (export, import, impression de
INSERT INTO `userflags` VALUES(14,'editauthorities','Gestion des autorités',0);
INSERT INTO `userflags` VALUES(15,'serials','Gestion du module périodique',0);
INSERT INTO `userflags` VALUES(16,'reports','Accès aux statistiques',0);
INSERT INTO `userflags` VALUES(19, 'plugins', 'Koha plugins', '0');

View File

@ -52,6 +52,9 @@ INSERT INTO permissions (module_bit, code, description) VALUES
(15, 'renew_subscription', 'Renouveler les abonnements'),
(15, 'routing', 'Mettre en circulation'),
(16, 'execute_reports', 'Lancer les rapports SQL'),
(16, 'create_reports', 'Créer les rapports SQL Reports')
(16, 'create_reports', 'Créer les rapports SQL Reports'),
(19, 'tool', 'Use tool plugins'),
(19, 'report', 'Use report plugins'),
(19, 'configure', 'Configure plugins')
;

View File

@ -17,5 +17,6 @@ INSERT INTO `userflags` VALUES(14,'editauthorities','autorizza la modifica delle
INSERT INTO `userflags` VALUES(15,'serials','autorizza la gestione degli abbonamenti ai periodici',0);
INSERT INTO `userflags` VALUES(16,'reports','autorizza accesso al modulo dei reports',0);
INSERT INTO `userflags` VALUES(17,'staffaccess','modifica la login o i permessi degli staff users',0);
INSERT INTO `userflags` VALUES(19, 'plugins', 'Koha plugins', '0');
SET FOREIGN_KEY_CHECKS=1;

View File

@ -54,6 +54,9 @@ INSERT INTO permissions (module_bit, code, description) VALUES
(15, 'renew_subscription', 'Rinnova un abbonamento'),
(15, 'routing', 'Crea/Manipola liste di distribuzione dei fascicoli ( routing list)'),
(16, 'execute_reports', 'Esegui reports SQL'),
(16, 'create_reports', 'Crea reports SQL')
(16, 'create_reports', 'Crea reports SQL'),
(19, 'tool', 'Use tool plugins'),
(19, 'report', 'Use report plugins'),
(19, 'configure', 'Configure plugins')
;
SET FOREIGN_KEY_CHECKS=1;

View File

@ -3063,6 +3063,17 @@ CREATE TABLE linktracker (
KEY dateidx (timeclicked)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Table structure for table 'plugin_data'
--
CREATE TABLE IF NOT EXISTS plugin_data (
plugin_class varchar(255) NOT NULL,
plugin_key varchar(255) NOT NULL,
plugin_value text,
PRIMARY KEY (plugin_class,plugin_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;

View File

@ -36,3 +36,4 @@ INSERT INTO `userflags` VALUES(14,'editauthorities','Tilgang til å endre autori
INSERT INTO `userflags` VALUES(15,'serials','Tilgang til å endre abonnementer',0);
INSERT INTO `userflags` VALUES(16,'reports','Tilgang til rapportmodulen',0);
INSERT INTO `userflags` VALUES(17,'staffaccess','Endre innlogging og rettigheter for bibliotekansatte',0);
INSERT INTO `userflags` VALUES(19, 'plugins', 'Koha plugins', '0');

View File

@ -72,5 +72,8 @@ INSERT INTO permissions (module_bit, code, description) VALUES
(15, 'renew_subscription', 'Fornye abonnementer'),
(15, 'routing', 'Sirkulasjon'),
(16, 'execute_reports', 'Kjøre SQL-rapporter'),
(16, 'create_reports', 'Opprette SQL-rapporter')
(16, 'create_reports', 'Opprette SQL-rapporter'),
(19, 'tool', 'Use tool plugins'),
(19, 'report', 'Use report plugins'),
(19, 'configure', 'Configure plugins')
;

View File

@ -15,3 +15,4 @@ INSERT INTO `userflags` VALUES(14,'editauthorities','Allow to edit authorities',
INSERT INTO `userflags` VALUES(15,'serials','Allow to manage serials subscriptions',0);
INSERT INTO `userflags` VALUES(16,'reports','Allow to access to the reports module',0);
INSERT INTO `userflags` VALUES(17,'staffaccess','Modify login / permissions for staff users',0);
INSERT INTO `userflags` VALUES(19, 'plugins', 'Koha plugins', '0');

View File

@ -53,5 +53,8 @@ INSERT INTO permissions (module_bit, code, description) VALUES
(15, 'renew_subscription', 'Renew a subscription'),
(15, 'routing', 'Routing'),
(16, 'execute_reports', 'Execute SQL reports'),
(16, 'create_reports', 'Create SQL Reports')
(16, 'create_reports', 'Create SQL Reports'),
(19, 'tool', 'Use tool plugins'),
(19, 'report', 'Use report plugins'),
(19, 'configure', 'Configure plugins')
;

View File

@ -17,7 +17,8 @@ INSERT INTO userflags (bit, flag, flagdesc, defaulton) VALUES
(14,'editauthorities', 'Разрешение на изменение авторитетных источников',0),
(15,'serials', 'Разрешение на управление подпиской периодических изданий',0),
(16,'reports', 'Разрешение на доступ к модулю отчетов',0),
(17,'staffaccess', 'Смена имени(логина)/привилегий для работников библиотеки',0)
(17,'staffaccess', 'Смена имени(логина)/привилегий для работников библиотеки',0),
(19,'plugins', 'Koha plugins', '0')
;
TRUNCATE permissions;
@ -76,6 +77,9 @@ INSERT INTO permissions (module_bit, code, description) VALUES
(15, 'renew_subscription', 'Renew a subscription'),
(15, 'routing', 'Routing'),
(16, 'execute_reports', 'Execute SQL reports'),
(16, 'create_reports', 'Create SQL Reports')
(16, 'create_reports', 'Create SQL Reports'),
(19, 'tool', 'Use tool plugins'),
(19, 'report', 'Use report plugins'),
(19, 'configure', 'Configure plugins')
;

View File

@ -418,3 +418,4 @@ INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) V
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('UseQueryParser', '0', 'If enabled, try to use QueryParser for queries.', NULL, 'YesNo');
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('FinesIncludeGracePeriod','1','If enabled, fines calculations will include the grace period.',NULL,'YesNo');
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('UNIMARCAuthorsFacetsSeparator',', ', 'UNIMARC authors facets separator', NULL, 'short');
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('UseKohaPlugins','1','Enable or disable the ability to use Koha Plugins.','','YesNo');

View File

@ -17,7 +17,8 @@ INSERT INTO userflags (bit, flag, flagdesc, defaulton) VALUES
(14,'editauthorities', 'Дозвіл на редагування авторитетних джерел',0),
(15,'serials', 'Дозвіл на керування підпискою періодичних видань',0),
(16,'reports', 'Дозвіл на доступ до модуля звітів',0),
(17,'staffaccess', 'Зміна імені(логіну)/привілеїв для працівників бібліотеки',0)
(17,'staffaccess', 'Зміна імені(логіну)/привілеїв для працівників бібліотеки',0),
(19,'plugins', 'Koha plugins', '0')
;
TRUNCATE permissions;
@ -76,6 +77,9 @@ INSERT INTO permissions (module_bit, code, description) VALUES
(15, 'renew_subscription', 'Renew a subscription'),
(15, 'routing', 'Routing'),
(16, 'execute_reports', 'Execute SQL reports'),
(16, 'create_reports', 'Create SQL Reports')
(16, 'create_reports', 'Create SQL Reports'),
(19, 'tool', 'Use tool plugins'),
(19, 'report', 'Use report plugins'),
(19, 'configure', 'Configure plugins')
;

View File

@ -6631,6 +6631,30 @@ if ( CheckVersion($DBversion) ) {
}
$DBversion = "3.11.00.106";
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
$dbh->do("INSERT INTO userflags (bit, flag, flagdesc, defaulton) VALUES ('19', 'plugins', 'Koha plugins', '0')");
$dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES
('19', 'manage', 'Manage plugins ( install / uninstall )'),
('19', 'tool', 'Use tool plugins'),
('19', 'report', 'Use report plugins'),
('19', 'configure', 'Configure plugins')
");
$dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('UseKohaPlugins','1','Enable or disable the ability to use Koha Plugins.','','YesNo')");
$dbh->do("
CREATE TABLE IF NOT EXISTS plugin_data (
plugin_class varchar(255) NOT NULL,
plugin_key varchar(255) NOT NULL,
plugin_value text,
PRIMARY KEY (plugin_class,plugin_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
");
print "Upgrade to $DBversion done (Bug 7804: Added plugin system.)\n";
SetVersion($DBversion);
}
=head1 FUNCTIONS
=head2 TableExists($table)

View File

@ -30,6 +30,9 @@
[% IF ( CAN_user_tools ) %]
<li><a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a></li>
[% END %]
[% IF ( UseKohaPlugins && CAN_user_plugins ) %]
<li><a href="/cgi-bin/koha/plugins/plugins-home.pl">Plugins</a></li>
[% END %]
[% IF ( CAN_user_parameters ) %]
<li><a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a></li>
[% END %]
@ -93,4 +96,4 @@
</div>
</div>
[% IF ( intranetbookbag ) %]<div id="cartDetails">Your cart is empty.</div>[% END %]
</div>
</div>

View File

@ -319,3 +319,10 @@ Enhanced Content:
- pref: HTML5MediaExtensions
class: multi
- (separated with |).
Plugins:
-
- pref: UseKohaPlugins
choices:
yes: Enable
no: "Don't enable"
- the ability to use Koha Plugins. Note, the plugin system must also be enabled in the Koha configuration file to be fully enabled.

View File

@ -0,0 +1,30 @@
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; Tools &rsaquo; Plugins &rsaquo; Upload Plugin
</title>
[% INCLUDE 'doc-head-close.inc' %]
[% INCLUDE 'calendar.inc' %]
</head>
<body>
[% INCLUDE 'header.inc' %]
[% INCLUDE 'circ-search.inc' %]
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a>
&rsaquo; <a href="/cgi-bin/koha/plugins/plugins-home.pl">Plugins</a>
&rsaquo; Plugins disabled
</div>
<div id="doc3" class="yui-t2">
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<div class="yui-g">
<div class="yui-u first">
<h1>Plugins disabled!</h1>
<p>To enable Koha plugins, the system preference UseKohaPlugins must be enabled, and the flag enable_plugins must be set in the Koha configuration file</p>
</div>
</div>
</div>
</div>
[% INCLUDE 'intranet-bottom.inc' %]

View File

@ -0,0 +1,116 @@
[% USE KohaDates %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; Tools &rsaquo; Plugins </title>
[% INCLUDE 'doc-head-close.inc' %]
[% INCLUDE 'calendar.inc' %]
</head>
<body>
[% INCLUDE 'header.inc' %]
[% INCLUDE 'circ-search.inc' %]
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a>
&rsaquo; Plugins
</div>
<div id="doc3" class="yui-t1">
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<div class="details">
<h1>Plugins</h1>
[% UNLESS ( plugins ) %]
[% UNLESS ( method ) %]
<h3>No plugins installed</h3>
[% ELSE %]
[% IF method == 'tool' %]
<h3>No plugins that can be used as a tool are installed</h3>
[% ELSIF method == 'report' %]
<h3>No plugins that can create a report are installed</h3>
[% ELSE %]
<h3>Unknown plugin type <i>[% method %]</i>
[% END %]
[% END %]
[% ELSE %]
<table>
<tr>
<th>Name</th>
<th>&nbsp;</th>
<th>Description</th>
<th>Author</th>
<th>Plugin Version</th>
<th>Minimum Koha Version</th>
<th>Maximum Koha Version</th>
<th>Last Updated</th>
[% IF ( CAN_user_plugins_configure ) %]<th>Configure</th>[% END %]
[% IF ( CAN_user_plugins_manage ) %]<th>Uninstall</th>[% END %]
</tr>
[% FOREACH plugin IN plugins %]
<tr>
<td><strong>[% plugin.metadata.name %]</strong></td>
<td>
[% IF ( CAN_user_plugins_report ) %]
[% IF plugin.can('report') %]
<p style="white-space:nowrap"><a href="/cgi-bin/koha/plugins/run.pl?class=[% plugin.class %]&method=report">Run report</a></p>
[% END %]
[% END %]
[% IF ( CAN_user_plugins_tool ) %]
[% IF plugin.can('tool') %]
<p style="white-space:nowrap"><a href="/cgi-bin/koha/plugins/run.pl?class=[% plugin.class %]&method=tool">Run tool</a></p>
[% END %]
[% END %]
</td>
<td>
[% plugin.metadata.description %]
[% IF ( plugin.metadata.minimum_version && koha_version < plugin.metadata.minimum_version ) %]
<div class="error">Warning: This report was written for a newer version of Koha. Run at your own risk.</div>
[% END %]
[% IF ( plugin.metadata.maximum_version && koha_version > plugin.metadata.maximum_version ) %]
<div class="error">Warning: This report was written for an older version of Koha. Run at your own risk.</div>
[% END %]
</td>
<td>[% plugin.metadata.author %]</td>
<td>[% plugin.metadata.version %]</td>
<td>[% plugin.metadata.minimum_version %]</td>
<td>[% plugin.metadata.maximum_version %]</td>
<td>[% plugin.metadata.date_updated | $KohaDates %]</td>
[% IF ( CAN_user_plugins_configure ) %]
<td>
[% IF plugin.can('configure') %]
<a href="/cgi-bin/koha/plugins/run.pl?class=[% plugin.class %]&method=configure">Configure</a>
[% END %]
</td>
[% END %]
[% IF ( CAN_user_plugins_manage ) %]
<td>
[% IF plugin.can('uninstall') %]
<a href="/cgi-bin/koha/plugins/plugins-uninstall.pl?class=[% plugin.class %]" onclick="return confirm('Are you sure you want to uninstall the plugin [% plugin.metadata.name %]?')">Uninstall</a>
[% END %]
</td>
[% END %]
[% END %]
</table>
[% END %]
</div>
</div>
</div>
<div class="yui-b noprint">
<div id="navmenu">
<ul id="navmenulist">
[% IF ( CAN_user_plugins_manage ) %]
<li><a href="plugins-upload.pl">Upload a plugin</a></li>
[% END %]
</ul>
</div>
</div>
</div>
</div>
[% INCLUDE 'intranet-bottom.inc' %]

View File

@ -0,0 +1,55 @@
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; Tools &rsaquo; Plugins &rsaquo; Upload Plugin
</title>
[% INCLUDE 'doc-head-close.inc' %]
[% INCLUDE 'calendar.inc' %]
</head>
<body>
[% INCLUDE 'header.inc' %]
[% INCLUDE 'circ-search.inc' %]
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a>
&rsaquo; <a href="/cgi-bin/koha/plugins/plugins-home.pl">Plugins</a>
&rsaquo; Upload Plugins
</div>
<div id="doc3" class="yui-t2">
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<div class="yui-g">
<div class="yui-u first">
<h1>Upload Koha Plugin</h1>
[% IF ( ERRORS ) %]
<div class="dialog alert">
[% FOREACH ERROR IN ERRORS %]
[% IF ( ERROR.NOTKPZ ) %]<li><b>The upload file does not appear to be a kpz file. The extention is not '.kpz'.</b></li>
[% ELSIF ( ERROR.NOWRITETEMP ) %]<li><b>This script is not able to create/write to the necessary temporary directory.</b></li>
[% ELSIF ( ERROR.EMPTYUPLOAD ) %]<li><b>The upload file appears to be empty.</b></li>
[% ELSIF ( ERROR.UZIPFAIL ) %]<li><b>[% ERROR.UZIPFAIL %] failed to unpack.<br />Please verify the integrity of the zip file and retry.</b></li>
[% ELSIF ( ERROR.NOWRITEPLUGINS ) %]<li><b>Cannot unpack file to the plugins directory.<br />Please verify that the Apache user can write to the plugins directory.</b></li>
[% ELSE %]<li><b>[% ERROR.CORERR %] An unknown error has occurred.<br />Please review the error log for more details.</b></li>[% END %]
[% END %]
</div>
[% END %]
<form method="post" action="/cgi-bin/koha/plugins/plugins-upload.pl" enctype="multipart/form-data">
<fieldset class="brief">
<div class="hint"><b>NOTE:</b> Only KPZ file format is supported.</div>
<ol>
<li>
<label for="uploadfile">Select the file to upload: </label><input type="file" id="uploadfile" name="uploadfile" />
</li>
</ol>
</fieldset>
<fieldset class="action">
<input type="hidden" name="op" value="Upload" />
<input type="submit" value="Upload" class="submit" />
</fieldset>
</form>
</div>
</div>
</div>
</div>
[% INCLUDE 'intranet-bottom.inc' %]

View File

@ -35,7 +35,16 @@
<li><a href="/cgi-bin/koha/reports/issues_stats.pl">Circulation</a></li>
<li><a href="/cgi-bin/koha/reports/serials_stats.pl">Serials</a></li>
<li><a href="/cgi-bin/koha/reports/reserves_stats.pl">Holds</a></li>
</ul></div>
</ul>
[% IF UseKohaPlugins %]
<h2>Report Plugins</h2>
<ul>
<li><a href="/cgi-bin/koha/plugins/plugins-home.pl?method=report">Report Plugins</a></li>
</ul>
[% END %]
</div>
<div class="yui-u"><h2>Top lists</h2>
<ul>

View File

@ -97,6 +97,11 @@
<dd>Quote editor for Quote-of-the-day feature in OPAC</dd>
[% END %]
[% IF ( UseKohaPlugins && CAN_user_plugins_tool ) %]
<dt><a href="/cgi-bin/koha/plugins/plugins-home.pl?method=tool">Tool Plugins</a></dt>
<dd>Use tool plugins</dd>
[% END %]
</dl>
</div>
<div class="yui-u">

View File

@ -16,7 +16,7 @@ the kohaversion is divided in 4 parts :
use strict;
sub kohaversion {
our $VERSION = '3.11.00.105';
our $VERSION = '3.11.00.106';
# version needs to be set this way
# so that it can be picked up by Makefile.PL
# during install

60
plugins/plugins-home.pl Executable file
View File

@ -0,0 +1,60 @@
#!/usr/bin/perl
# Copyright 2010 Kyle M Hall <kyle.m.hall@gmail.com>
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
use warnings;
use CGI;
use Koha::Plugins;
use C4::Auth;
use C4::Output;
use C4::Dates;
use C4::Debug;
use C4::Context;
my $plugins_enabled = C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins");
my $input = new CGI;
my $method = $input->param('method');
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
{ template_name => ($plugins_enabled) ? "plugins/plugins-home.tt" : "plugins/plugins-disabled.tt",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => { plugins => '*' },
debug => 1,
}
);
if ($plugins_enabled) {
$template->param(
koha_version => C4::Context->preference("Version"),
method => $method,
);
my @plugins = Koha::Plugins->new()->GetPlugins($method);
$template->param( plugins => \@plugins, );
}
output_html_with_http_headers( $input, $cookie, $template->output );

52
plugins/plugins-uninstall.pl Executable file
View File

@ -0,0 +1,52 @@
#!/usr/bin/perl
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
use warnings;
use Archive::Extract;
use File::Temp;
use File::Copy;
use CGI;
use C4::Context;
use C4::Auth;
use C4::Output;
use C4::Members;
use C4::Debug;
use Koha::Plugins::Handler;
die("Koha plugins are disabled!")
unless C4::Context->preference('UseKohaPlugins');
my $input = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{ template_name => "plugins/plugins-upload.tmpl",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => { plugins => 'manage' },
debug => 1,
}
);
my $class = $input->param('class');
Koha::Plugins::Handler->delete( { class => $class } );
print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl");

103
plugins/plugins-upload.pl Executable file
View File

@ -0,0 +1,103 @@
#!/usr/bin/perl
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
use warnings;
use Archive::Extract;
use File::Temp;
use File::Copy;
use CGI;
use C4::Context;
use C4::Auth;
use C4::Output;
use C4::Members;
use C4::Debug;
use Koha::Plugins;
my $plugins_enabled = C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins");
my $input = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{ template_name => ($plugins_enabled) ? "plugins/plugins-upload.tmpl" : "plugins/plugins-disabled.tt",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => { plugins => 'manage' },
debug => 1,
}
);
my $uploadfilename = $input->param('uploadfile');
my $uploadfile = $input->upload('uploadfile');
my $op = $input->param('op');
my ( $total, $handled, @counts, $tempfile, $tfh );
my %errors;
if ($plugins_enabled) {
if ( ( $op eq 'Upload' ) && $uploadfile ) {
my $plugins_dir = C4::Context->config("pluginsdir");
my $dirname = File::Temp::tempdir( CLEANUP => 1 );
$debug and warn "dirname = $dirname";
my $filesuffix;
$filesuffix = $1 if $uploadfilename =~ m/(\..+)$/i;
( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 );
$debug and warn "tempfile = $tempfile";
$errors{'NOTKPZ'} = 1 if ( $uploadfilename !~ /\.kpz$/i );
$errors{'NOWRITETEMP'} = 1 unless ( -w $dirname );
$errors{'NOWRITEPLUGINS'} = 1 unless ( -w $plugins_dir );
$errors{'EMPTYUPLOAD'} = 1 unless ( length($uploadfile) > 0 );
if (%errors) {
$template->param( ERRORS => [ \%errors ] );
} else {
while (<$uploadfile>) {
print $tfh $_;
}
close $tfh;
my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' );
unless ( $ae->extract( to => $plugins_dir ) ) {
warn "ERROR: " . $ae->error;
$errors{'UZIPFAIL'} = $uploadfilename;
$template->param( ERRORS => [ \%errors ] );
output_html_with_http_headers $input, $cookie, $template->output;
exit;
}
}
} elsif ( ( $op eq 'Upload' ) && !$uploadfile ) {
warn "Problem uploading file or no file uploaded.";
}
if ( $uploadfile && !%errors && !$template->param('ERRORS') ) {
print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl");
} else {
output_html_with_http_headers $input, $cookie, $template->output;
}
} else {
output_html_with_http_headers $input, $cookie, $template->output;
}

53
plugins/run.pl Executable file
View File

@ -0,0 +1,53 @@
#!/usr/bin/perl
# Copyright 2010 Kyle M Hall <kyle.m.hall@gmail.com>
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
use warnings;
use CGI;
use Koha::Plugins::Handler;
use C4::Auth;
use C4::Output;
use C4::Dates;
use C4::Debug;
use C4::Context;
my $plugins_enabled = C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins");
my $cgi = new CGI;
my $class = $cgi->param('class');
my $method = $cgi->param('method');
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
{ template_name => "plugins/plugins-disabled.tmpl",
query => $cgi,
type => "intranet",
authnotrequired => 0,
flagsrequired => { plugins => $method },
debug => 1,
}
);
if ( $plugins_enabled ) {
my $plugin = Koha::Plugins::Handler->run( { class => $class, method => $method, cgi => $cgi } );
} else {
output_html_with_http_headers( $cgi, $cookie, $template->output );
}

View File

@ -43,7 +43,7 @@ guesses worked out by the script.
The following configuration keywords are available:
PREFIX,
BASE_DIR, CGI_DIR, LOG_DIR, INSTALL_BASE,
BASE_DIR, CGI_DIR, LOG_DIR, PLUGINS_DIR, INSTALL_BASE,
DB_TYPE, DB_HOST, DB_PORT, DB_NAME, DB_PASS, DB_USER, WEBMASTER_EMAIL, WEBSERVER_DOMAIN,
WEBSERVER_HOST, WEBSERVER_IP, WEBSERVER_PORT, WEBSERVER_PORT_LIBRARIAN, ZEBRA_PASS, ZEBRA_USER
@ -82,6 +82,7 @@ $prefix = $ENV{'INSTALL_BASE'} || "/usr";
%configuration = (
"__KOHA_INSTALLED_VERSION__" => "no_version_found",
"__LOG_DIR__" => "/var/log",
"__PLUGINS_DIR__" => "/var/lib/koha/plugins",
"__DB_TYPE__" => "mysql",
"__DB_NAME__" => "koha",
"__DB_HOST__" => $myhost,

View File

@ -0,0 +1 @@
plugins dir

53
t/Koha/Plugin/Test.pm Normal file
View File

@ -0,0 +1,53 @@
package Koha::Plugin::Test;
## It's good practive to use Modern::Perl
use Modern::Perl;
## Required for all plugins
use base qw(Koha::Plugins::Base);
our $VERSION = 1.01;
our $metadata = {
name => 'Test Plugin',
author => 'Kyle M Hall',
description => 'Test plugin',
date_authored => '2013-01-14',
date_updated => '2013-01-14',
minimum_version => '3.11',
maximum_version => undef,
version => $VERSION,
};
## This is the minimum code required for a plugin's 'new' method
## More can be added, but none should be removed
sub new {
my ( $class, $args ) = @_;
$args->{'metadata'} = $metadata;
my $self = $class->SUPER::new($args);
return $self;
}
sub report {
my ( $self, $args ) = @_;
return "Koha::Plugin::Test::report";
}
sub tool {
my ( $self, $args ) = @_;
return "Koha::Plugin::Test::tool";
}
sub configure {
my ( $self, $args ) = @_;
return "Koha::Plugin::Test::configure";;
}
sub install {
my ( $self, $args ) = @_;
return "Koha::Plugin::Test::install";
}
sub uninstall {
my ( $self, $args ) = @_;
return "Koha::Plugin::Test::uninstall";
}

Binary file not shown.

57
t/db_dependent/Plugins.t Executable file
View File

@ -0,0 +1,57 @@
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 20;
use File::Basename;
use FindBin qw($Bin);
use Archive::Extract;
use Module::Load::Conditional qw(can_load);
use C4::Context;
BEGIN {
push( @INC, dirname(__FILE__) . '/..' );
use_ok('Koha::Plugins');
use_ok('Koha::Plugins::Handler');
use_ok('Koha::Plugins::Base');
use_ok('Koha::Plugin::Test');
}
ok( can_load( modules => { "Koha::Plugin::Test" => undef } ), 'Test can_load' );
my $plugin = Koha::Plugin::Test->new({ enable_plugins => 1});
isa_ok( $plugin, "Koha::Plugin::Test", 'Test plugin class' );
isa_ok( $plugin, "Koha::Plugins::Base", 'Test plugin parent class' );
ok( $plugin->can('report'), 'Test plugin can report' );
ok( $plugin->can('tool'), 'Test plugin can tool' );
ok( $plugin->can('configure'), 'Test plugin can configure' );
ok( $plugin->can('install'), 'Test plugin can install' );
ok( $plugin->can('uninstall'), 'Test plugin can install' );
ok( Koha::Plugins::Handler->run({ class => "Koha::Plugin::Test", method => 'report' }) eq "Koha::Plugin::Test::report", 'Test run plugin report method' );
my $metadata = $plugin->get_metadata();
ok( $metadata->{'name'} eq 'Test Plugin', 'Test $plugin->get_metadata()' );
ok( $plugin->get_qualified_table_name('mytable') eq 'koha_plugin_test_mytable', 'Test $plugin->get_qualified_table_name()' );
ok( $plugin->get_plugin_http_path() eq '/plugin/Koha/Plugin/Test', 'Test $plugin->get_plugin_http_path()' );
my @plugins = Koha::Plugins->new()->GetPlugins( 'report' );
ok( $plugins[0]->get_metadata()->{'name'} eq 'Test Plugin', "Koha::Plugins::GetPlugins functions correctly" );
my $plugins_dir = C4::Context->config("pluginsdir");
my $ae = Archive::Extract->new( archive => "$Bin/KitchenSinkPlugin.kpz", type => 'zip' );
unless ( $ae->extract( to => $plugins_dir ) ) {
warn "ERROR: " . $ae->error;
}
use_ok('Koha::Plugin::Com::ByWaterSolutions::KitchenSink');
$plugin = Koha::Plugin::Com::ByWaterSolutions::KitchenSink->new({ enable_plugins => 1});
ok( -f $plugins_dir . "/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm", "KitchenSink plugin installed successfully" );
Koha::Plugins::Handler->delete({ class => "Koha::Plugin::Com::ByWaterSolutions::KitchenSink" });
ok( !( -f $plugins_dir . "/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm" ), "Koha::Plugins::Handler::delete works correctly." );