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

(-)a/Koha/Plugins.pm (-1 / +1 lines)
Lines 38-44 Koha::Plugins - Module for loading and managing plugins. Link Here
38
sub new {
38
sub new {
39
    my ( $class, $args ) = @_;
39
    my ( $class, $args ) = @_;
40
40
41
    die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
41
    return unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
42
42
43
    $args->{'pluginsdir'} = C4::Context->config("pluginsdir");
43
    $args->{'pluginsdir'} = C4::Context->config("pluginsdir");
44
44
(-)a/Koha/Plugins/Base.pm (-1 / +1 lines)
Lines 39-45 C4::Plugins::Base - Base Module for plugins Link Here
39
sub new {
39
sub new {
40
    my ( $class, $args ) = @_;
40
    my ( $class, $args ) = @_;
41
41
42
    die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
42
    return unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
43
43
44
    $args->{'class'} = $class;
44
    $args->{'class'} = $class;
45
    $args->{'template'} = Template->new( { ABSOLUTE => 1 } );
45
    $args->{'template'} = Template->new( { ABSOLUTE => 1 } );
(-)a/Koha/Plugins/Handler.pm (-1 / +1 lines)
Lines 51-57 Runs a plugin Link Here
51
sub run {
51
sub run {
52
    my ( $class, $args ) = @_;
52
    my ( $class, $args ) = @_;
53
53
54
    die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
54
    return unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
55
55
56
    my $plugin_class  = $args->{'class'};
56
    my $plugin_class  = $args->{'class'};
57
    my $plugin_method = $args->{'method'};
57
    my $plugin_method = $args->{'method'};
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-disabled.tt (+30 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; Plugins &rsaquo; Upload Plugin
3
 </title>
4
[% INCLUDE 'doc-head-close.inc' %]
5
[% INCLUDE 'calendar.inc' %]
6
</head>
7
8
<body>
9
[% INCLUDE 'header.inc' %]
10
[% INCLUDE 'circ-search.inc' %]
11
12
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a>
13
&rsaquo; <a href="/cgi-bin/koha/plugins/plugins-home.pl">Plugins</a>
14
&rsaquo; Plugins disabled
15
</div>
16
17
<div id="doc3" class="yui-t2">
18
    <div id="bd">
19
        <div id="yui-main">
20
    <div class="yui-b">
21
        <div class="yui-g">
22
            <div class="yui-u first">
23
                <h1>Plugins disabled!</h1>
24
25
                <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>
26
            </div>
27
        </div>
28
    </div>
29
</div>
30
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/plugins/plugins-home.pl (-11 / +14 lines)
Lines 29-57 use C4::Dates; Link Here
29
use C4::Debug;
29
use C4::Debug;
30
use C4::Context;
30
use C4::Context;
31
31
32
die("Koha plugins are disabled!")
32
my $plugins_enabled = C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins");
33
  unless C4::Context->preference('UseKohaPlugins');
34
33
35
my $input  = new CGI;
34
my $input  = new CGI;
36
my $method = $input->param('method');
35
my $method = $input->param('method');
37
36
38
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
37
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
39
    {   template_name   => "plugins/plugins-home.tmpl",
38
    {   template_name => ($plugins_enabled) ? "plugins/plugins-home.tt" : "plugins/plugins-disabled.tt",
40
        query           => $input,
39
        query         => $input,
41
        type            => "intranet",
40
        type          => "intranet",
42
        authnotrequired => 0,
41
        authnotrequired => 0,
43
        flagsrequired   => { plugins => '*' },
42
        flagsrequired   => { plugins => '*' },
44
        debug           => 1,
43
        debug           => 1,
45
    }
44
    }
46
);
45
);
47
46
48
$template->param(
47
if ($plugins_enabled) {
49
    koha_version => C4::Context->preference("Version"),
48
50
    method       => $method,
49
    $template->param(
51
);
50
        koha_version => C4::Context->preference("Version"),
51
        method       => $method,
52
    );
53
54
    my @plugins = Koha::Plugins->new()->GetPlugins($method);
52
55
53
my @plugins = Koha::Plugins->new()->GetPlugins($method);
56
    $template->param( plugins => \@plugins, );
54
57
55
$template->param( plugins => \@plugins );
58
}
56
59
57
output_html_with_http_headers( $input, $cookie, $template->output );
60
output_html_with_http_headers( $input, $cookie, $template->output );
(-)a/plugins/plugins-upload.pl (-36 / +41 lines)
Lines 1-4 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
#
3
#
3
# This file is part of Koha.
4
# This file is part of Koha.
4
#
5
#
Lines 30-44 use C4::Members; Link Here
30
use C4::Debug;
31
use C4::Debug;
31
use Koha::Plugins;
32
use Koha::Plugins;
32
33
33
die("Koha plugins are disabled!")
34
my $plugins_enabled = C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins");
34
  unless C4::Context->preference('UseKohaPlugins');
35
35
36
my $input = new CGI;
36
my $input = new CGI;
37
37
38
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39
    {   template_name   => "plugins/plugins-upload.tmpl",
39
    {   template_name => ($plugins_enabled) ? "plugins/plugins-upload.tmpl" : "plugins/plugins-disabled.tt",
40
        query           => $input,
40
        query         => $input,
41
        type            => "intranet",
41
        type          => "intranet",
42
        authnotrequired => 0,
42
        authnotrequired => 0,
43
        flagsrequired   => { plugins => 'manage' },
43
        flagsrequired   => { plugins => 'manage' },
44
        debug           => 1,
44
        debug           => 1,
Lines 53-98 my ( $total, $handled, @counts, $tempfile, $tfh ); Link Here
53
53
54
my %errors;
54
my %errors;
55
55
56
if ( ( $op eq 'Upload' ) && $uploadfile ) {
56
if ($plugins_enabled) {
57
    my $plugins_dir = C4::Context->config("pluginsdir");
57
    if ( ( $op eq 'Upload' ) && $uploadfile ) {
58
58
        my $plugins_dir = C4::Context->config("pluginsdir");
59
    my $dirname = File::Temp::tempdir( CLEANUP => 1 );
60
    $debug and warn "dirname = $dirname";
61
59
62
    my $filesuffix;
60
        my $dirname = File::Temp::tempdir( CLEANUP => 1 );
63
    $filesuffix = $1 if $uploadfilename =~ m/(\..+)$/i;
61
        $debug and warn "dirname = $dirname";
64
    ( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 );
65
62
66
    $debug and warn "tempfile = $tempfile";
63
        my $filesuffix;
64
        $filesuffix = $1 if $uploadfilename =~ m/(\..+)$/i;
65
        ( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 );
67
66
68
    $errors{'NOTKPZ'} = 1 if ( $uploadfilename !~ /\.kpz$/i );
67
        $debug and warn "tempfile = $tempfile";
69
    $errors{'NOWRITETEMP'}    = 1 unless ( -w $dirname );
70
    $errors{'NOWRITEPLUGINS'} = 1 unless ( -w $plugins_dir );
71
    $errors{'EMPTYUPLOAD'}    = 1 unless ( length($uploadfile) > 0 );
72
68
73
    if (%errors) {
69
        $errors{'NOTKPZ'} = 1 if ( $uploadfilename !~ /\.kpz$/i );
74
        $template->param( ERRORS => [ \%errors ] );
70
        $errors{'NOWRITETEMP'}    = 1 unless ( -w $dirname );
75
    } else {
71
        $errors{'NOWRITEPLUGINS'} = 1 unless ( -w $plugins_dir );
76
        while (<$uploadfile>) {
72
        $errors{'EMPTYUPLOAD'}    = 1 unless ( length($uploadfile) > 0 );
77
            print $tfh $_;
78
        }
79
        close $tfh;
80
73
81
        my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' );
74
        if (%errors) {
82
        unless ( $ae->extract( to => $plugins_dir ) ) {
83
            warn "ERROR: " . $ae->error;
84
            $errors{'UZIPFAIL'} = $uploadfilename;
85
            $template->param( ERRORS => [ \%errors ] );
75
            $template->param( ERRORS => [ \%errors ] );
86
            output_html_with_http_headers $input, $cookie, $template->output;
76
        } else {
87
            exit;
77
            while (<$uploadfile>) {
78
                print $tfh $_;
79
            }
80
            close $tfh;
81
82
            my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' );
83
            unless ( $ae->extract( to => $plugins_dir ) ) {
84
                warn "ERROR: " . $ae->error;
85
                $errors{'UZIPFAIL'} = $uploadfilename;
86
                $template->param( ERRORS => [ \%errors ] );
87
                output_html_with_http_headers $input, $cookie, $template->output;
88
                exit;
89
            }
88
        }
90
        }
91
    } elsif ( ( $op eq 'Upload' ) && !$uploadfile ) {
92
        warn "Problem uploading file or no file uploaded.";
93
    }
94
95
    if ( $uploadfile && !%errors && !$template->param('ERRORS') ) {
96
        print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl");
97
    } else {
98
        output_html_with_http_headers $input, $cookie, $template->output;
89
    }
99
    }
90
} elsif ( ( $op eq 'Upload' ) && !$uploadfile ) {
91
    warn "Problem uploading file or no file uploaded.";
92
}
93
100
94
if ( $uploadfile && !%errors && !$template->param('ERRORS') ) {
95
    print $input->redirect("/cgi-bin/koha/plugins/plugins-home.pl");
96
} else {
101
} else {
97
    output_html_with_http_headers $input, $cookie, $template->output;
102
    output_html_with_http_headers $input, $cookie, $template->output;
98
}
103
}
(-)a/plugins/run.pl (-5 / +7 lines)
Lines 29-36 use C4::Dates; Link Here
29
use C4::Debug;
29
use C4::Debug;
30
use C4::Context;
30
use C4::Context;
31
31
32
die("Koha plugins are disabled!")
32
my $plugins_enabled = C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins");
33
  unless C4::Context->preference('UseKohaPlugins');
34
33
35
my $cgi = new CGI;
34
my $cgi = new CGI;
36
35
Lines 38-44 my $class = $cgi->param('class'); Link Here
38
my $method = $cgi->param('method');
37
my $method = $cgi->param('method');
39
38
40
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
39
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
41
    {   template_name   => "plugins/plugins-home.tmpl",
40
    {   template_name   => "plugins/plugins-disabled.tmpl",
42
        query           => $cgi,
41
        query           => $cgi,
43
        type            => "intranet",
42
        type            => "intranet",
44
        authnotrequired => 0,
43
        authnotrequired => 0,
Lines 47-50 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
47
    }
46
    }
48
);
47
);
49
48
50
my $plugin = Koha::Plugins::Handler->run( { class => $class, method => $method, cgi => $cgi } );
49
if ( $plugins_enabled ) {
50
    my $plugin = Koha::Plugins::Handler->run( { class => $class, method => $method, cgi => $cgi } );
51
} else {
52
    output_html_with_http_headers( $cgi, $cookie, $template->output );
53
}
51
- 

Return to bug 7804