<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>
[% 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");
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 } );
}
}
use Archive::Extract;
use CGI qw ( -utf8 );
+use Mojo::UserAgent;
use File::Copy;
use File::Temp;
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 );
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;
$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 ) ) {
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;