Kyle M Hall
ea6a11ec82
It would be very useful to be able to define multiple plugin directories in the Koha conf file. This would allow for ease of plugin development so that each plugin installed can live in its own git repository. For compatibility, the first plugindir instance defined should be the one used for uploading plugins via the web interface. Test Plan: 1) Apply this patch 2) Define a second pluginsdir line in your koha-conf.xml 3) Clone the kitchen sink plugin to this new path like this: git clone https://github.com/bywatersolutions/koha-plugin-kitchen-sink.git /path/to/new/plugins/dir 4) Restart memcached if you are running it 5) The Kitchen Sink plugin should now appear in your list of plugins! Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> I rebased it against master and tested it on a kohadevbox Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
104 lines
3.4 KiB
Perl
Executable file
104 lines
3.4 KiB
Perl
Executable file
#!/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 3 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, see <http://www.gnu.org/licenses>.
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use Archive::Extract;
|
|
use File::Temp;
|
|
use File::Copy;
|
|
use CGI qw ( -utf8 );
|
|
|
|
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.tt" : "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");
|
|
$plugins_dir = ref($plugins_dir) eq 'ARRAY' ? $plugins_dir->[0] : $plugins_dir;
|
|
|
|
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;
|
|
}
|