View | Details | Raw Unified | Return to bug 23975
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt (-2 / +1 lines)
Lines 71-77 Link Here
71
                                    <td><a href="[% sr.result.html_url | url %]" target="_new">[% sr.result.name %]</a></td>
71
                                    <td><a href="[% sr.result.html_url | url %]" target="_new">[% sr.result.name %]</a></td>
72
                                    <td>[% sr.result.description %]</td>
72
                                    <td>[% sr.result.description %]</td>
73
                                    <td>[% sr.repo.name %]</td>
73
                                    <td>[% sr.repo.name %]</td>
74
                                    <td><button class="btn btn-install-plugin"><i class="fa fa-download"></i> Install</button></td>
74
                                    <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>
75
                                </tr>
75
                                </tr>
76
                            [% END %]
76
                            [% END %]
77
                        </table>
77
                        </table>
Lines 196-202 Link Here
196
    [% INCLUDE 'calendar.inc' %]
196
    [% INCLUDE 'calendar.inc' %]
197
    <script>
197
    <script>
198
        $(document).ready(function(){
198
        $(document).ready(function(){
199
            $(".btn-install-plugin").on("click", function() { alert("Sorry, this functionality doesn't exist yet!"); });
200
            $(".uninstall_plugin").on("click", function(){
199
            $(".uninstall_plugin").on("click", function(){
201
                $(".dropdown").removeClass("open");
200
                $(".dropdown").removeClass("open");
202
                var plugin_name = $(this).data("plugin-name");
201
                var plugin_name = $(this).data("plugin-name");
(-)a/plugins/plugins-home.pl (+8 lines)
Lines 69-74 if ($plugins_enabled) { Link Here
69
                my $response = from_json( get($url) );
69
                my $response = from_json( get($url) );
70
                foreach my $result ( @{ $response->{items} } ) {
70
                foreach my $result ( @{ $response->{items} } ) {
71
                    next unless $result->{name} =~ /^koha-plugin-/;
71
                    next unless $result->{name} =~ /^koha-plugin-/;
72
                    my $releases = $result->{url} . "/releases/latest";
73
                    my $release = from_json( get($releases) );
74
                    for my $asset ( @{$release->{assets}} ) {
75
                        if ($asset->{browser_download_url} =~ m/\.kpz$/) {
76
                            $result->{install_name} = $asset->{name};
77
                            $result->{install_url} = $asset->{browser_download_url};
78
                        }
79
                    }
72
                    push( @results, { repo => $r, result => $result } );
80
                    push( @results, { repo => $r, result => $result } );
73
                }
81
                }
74
            }
82
            }
(-)a/plugins/plugins-upload.pl (-8 / +18 lines)
Lines 20-25 use Modern::Perl; Link Here
20
20
21
use Archive::Extract;
21
use Archive::Extract;
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
use Mojo::UserAgent;
23
use File::Copy;
24
use File::Copy;
24
use File::Temp;
25
use File::Temp;
25
26
Lines 46-51 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
46
47
47
my $uploadfilename = $input->param('uploadfile');
48
my $uploadfilename = $input->param('uploadfile');
48
my $uploadfile     = $input->upload('uploadfile');
49
my $uploadfile     = $input->upload('uploadfile');
50
my $uploadlocation = $input->param('uploadlocation');
49
my $op             = $input->param('op') || q{};
51
my $op             = $input->param('op') || q{};
50
52
51
my ( $total, $handled, @counts, $tempfile, $tfh );
53
my ( $total, $handled, @counts, $tempfile, $tfh );
Lines 53-59 my ( $total, $handled, @counts, $tempfile, $tfh ); Link Here
53
my %errors;
55
my %errors;
54
56
55
if ($plugins_enabled) {
57
if ($plugins_enabled) {
56
    if ( ( $op eq 'Upload' ) && $uploadfile ) {
58
    if ( ( $op eq 'Upload' ) && ( $uploadfile || $uploadlocation ) ) {
57
        my $plugins_dir = C4::Context->config("pluginsdir");
59
        my $plugins_dir = C4::Context->config("pluginsdir");
58
        $plugins_dir = ref($plugins_dir) eq 'ARRAY' ? $plugins_dir->[0] : $plugins_dir;
60
        $plugins_dir = ref($plugins_dir) eq 'ARRAY' ? $plugins_dir->[0] : $plugins_dir;
59
61
Lines 69-83 if ($plugins_enabled) { Link Here
69
        $errors{'NOTKPZ'} = 1 if ( $uploadfilename !~ /\.kpz$/i );
71
        $errors{'NOTKPZ'} = 1 if ( $uploadfilename !~ /\.kpz$/i );
70
        $errors{'NOWRITETEMP'}    = 1 unless ( -w $dirname );
72
        $errors{'NOWRITETEMP'}    = 1 unless ( -w $dirname );
71
        $errors{'NOWRITEPLUGINS'} = 1 unless ( -w $plugins_dir );
73
        $errors{'NOWRITEPLUGINS'} = 1 unless ( -w $plugins_dir );
72
        $errors{'EMPTYUPLOAD'}    = 1 unless ( length($uploadfile) > 0 );
74
75
        if ( $uploadlocation ) {
76
            my $ua = Mojo::UserAgent->new(max_redirects => 5);
77
            my $tx = $ua->get($uploadlocation);
78
            $tx->result->save_to($tempfile);
79
        } else {
80
            $errors{'EMPTYUPLOAD'}    = 1 unless ( length($uploadfile) > 0 );
81
        }
73
82
74
        if (%errors) {
83
        if (%errors) {
75
            $template->param( ERRORS => [ \%errors ] );
84
            $template->param( ERRORS => [ \%errors ] );
76
        } else {
85
        } else {
77
            while (<$uploadfile>) {
86
            if ( $uploadfile ) {
78
                print $tfh $_;
87
                while (<$uploadfile>) {
88
                    print $tfh $_;
89
                }
90
                close $tfh;
79
            }
91
            }
80
            close $tfh;
81
92
82
            my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' );
93
            my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' );
83
            unless ( $ae->extract( to => $plugins_dir ) ) {
94
            unless ( $ae->extract( to => $plugins_dir ) ) {
Lines 90-100 if ($plugins_enabled) { Link Here
90
101
91
            Koha::Plugins->new()->InstallPlugins();
102
            Koha::Plugins->new()->InstallPlugins();
92
        }
103
        }
93
    } elsif ( ( $op eq 'Upload' ) && !$uploadfile ) {
104
    } elsif ( ( $op eq 'Upload' ) && !$uploadfile && !$uploadlocation ) {
94
        warn "Problem uploading file or no file uploaded.";
105
        warn "Problem uploading file or no file uploaded.";
95
    }
106
    }
96
107
97
    if ( $uploadfile && !%errors && !$template->param('ERRORS') ) {
108
    if ( ($uploadfile || $uploadlocation) && !%errors && !$template->param('ERRORS') ) {
98
        print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl");
109
        print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl");
99
    } else {
110
    } else {
100
        output_html_with_http_headers $input, $cookie, $template->output;
111
        output_html_with_http_headers $input, $cookie, $template->output;
101
- 

Return to bug 23975