Browse Source

Bug 23975: Add 'Install' support for github results

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
20.05.x
Martin Renvoize 4 years ago
parent
commit
f1dc82d70b
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 3
      koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt
  2. 8
      plugins/plugins-home.pl
  3. 25
      plugins/plugins-upload.pl

3
koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt

@ -71,7 +71,7 @@
<td><a href="[% sr.result.html_url | url %]" target="_new">[% sr.result.name %]</a></td>
<td>[% sr.result.description %]</td>
<td>[% sr.repo.name %]</td>
<td><button class="btn btn-install-plugin"><i class="fa fa-download"></i> Install</button></td>
<td><a class="btn btn-install-plugin" href="/cgi-bin/koha/plugins/plugins-upload.pl?op=Upload&uploadfile=[% sr.result.install_name | uri %]&uploadlocation=[% sr.result.install_url | uri %]"><i class="fa fa-download"></i> Install</a></td>
</tr>
[% END %]
</table>
@ -196,7 +196,6 @@
[% INCLUDE 'calendar.inc' %]
<script>
$(document).ready(function(){
$(".btn-install-plugin").on("click", function() { alert("Sorry, this functionality doesn't exist yet!"); });
$(".uninstall_plugin").on("click", function(){
$(".dropdown").removeClass("open");
var plugin_name = $(this).data("plugin-name");

8
plugins/plugins-home.pl

@ -69,6 +69,14 @@ if ($plugins_enabled) {
my $response = from_json( get($url) );
foreach my $result ( @{ $response->{items} } ) {
next unless $result->{name} =~ /^koha-plugin-/;
my $releases = $result->{url} . "/releases/latest";
my $release = from_json( get($releases) );
for my $asset ( @{$release->{assets}} ) {
if ($asset->{browser_download_url} =~ m/\.kpz$/) {
$result->{install_name} = $asset->{name};
$result->{install_url} = $asset->{browser_download_url};
}
}
push( @results, { repo => $r, result => $result } );
}
}

25
plugins/plugins-upload.pl

@ -20,6 +20,7 @@ use Modern::Perl;
use Archive::Extract;
use CGI qw ( -utf8 );
use Mojo::UserAgent;
use File::Copy;
use File::Temp;
@ -46,6 +47,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
my $uploadfilename = $input->param('uploadfile');
my $uploadfile = $input->upload('uploadfile');
my $uploadlocation = $input->param('uploadlocation');
my $op = $input->param('op') || q{};
my ( $total, $handled, @counts, $tempfile, $tfh );
@ -53,7 +55,7 @@ my ( $total, $handled, @counts, $tempfile, $tfh );
my %errors;
if ($plugins_enabled) {
if ( ( $op eq 'Upload' ) && $uploadfile ) {
if ( ( $op eq 'Upload' ) && ( $uploadfile || $uploadlocation ) ) {
my $plugins_dir = C4::Context->config("pluginsdir");
$plugins_dir = ref($plugins_dir) eq 'ARRAY' ? $plugins_dir->[0] : $plugins_dir;
@ -69,15 +71,24 @@ if ($plugins_enabled) {
$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 ( $uploadlocation ) {
my $ua = Mojo::UserAgent->new(max_redirects => 5);
my $tx = $ua->get($uploadlocation);
$tx->result->save_to($tempfile);
} else {
$errors{'EMPTYUPLOAD'} = 1 unless ( length($uploadfile) > 0 );
}
if (%errors) {
$template->param( ERRORS => [ \%errors ] );
} else {
while (<$uploadfile>) {
print $tfh $_;
if ( $uploadfile ) {
while (<$uploadfile>) {
print $tfh $_;
}
close $tfh;
}
close $tfh;
my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' );
unless ( $ae->extract( to => $plugins_dir ) ) {
@ -90,11 +101,11 @@ if ($plugins_enabled) {
Koha::Plugins->new()->InstallPlugins();
}
} elsif ( ( $op eq 'Upload' ) && !$uploadfile ) {
} elsif ( ( $op eq 'Upload' ) && !$uploadfile && !$uploadlocation ) {
warn "Problem uploading file or no file uploaded.";
}
if ( $uploadfile && !%errors && !$template->param('ERRORS') ) {
if ( ($uploadfile || $uploadlocation) && !%errors && !$template->param('ERRORS') ) {
print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl");
} else {
output_html_with_http_headers $input, $cookie, $template->output;

Loading…
Cancel
Save