Bugzilla – Attachment 15572 Details for
Bug 7804
Add Koha Plugin System
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 7804 - Add Koha Plugin System - QA Followup 2
Bug-7804---Add-Koha-Plugin-System---QA-Followup-2.patch (text/plain), 12.67 KB, created by
Kyle M Hall (khall)
on 2013-02-20 18:46:06 UTC
(
hide
)
Description:
Bug 7804 - Add Koha Plugin System - QA Followup 2
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2013-02-20 18:46:06 UTC
Size:
12.67 KB
patch
obsolete
>From 724bc85a821a73a8be746790da0808a23cb7878e Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Wed, 20 Feb 2013 13:32:25 -0500 >Subject: [PATCH] Bug 7804 - Add Koha Plugin System - QA Followup 2 > >* Add "Plugins disabled" screen instead of error >* Allow plugins to return a value, add a test run that checks the return value >--- > Koha/Plugins.pm | 2 +- > Koha/Plugins/Base.pm | 2 +- > Koha/Plugins/Handler.pm | 4 +- > .../prog/en/modules/plugins/plugins-disabled.tt | 30 ++++++++ > plugins/plugins-home.pl | 25 ++++--- > plugins/plugins-upload.pl | 77 +++++++++++--------- > plugins/run.pl | 11 ++- > t/Koha/Plugin/Test.pm | 10 ++-- > t/db_dependent/Plugins.t | 4 +- > 9 files changed, 104 insertions(+), 61 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-disabled.tt > >diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm >index bc4a3bb..1360afa 100644 >--- a/Koha/Plugins.pm >+++ b/Koha/Plugins.pm >@@ -38,7 +38,7 @@ Koha::Plugins - Module for loading and managing plugins. > sub new { > my ( $class, $args ) = @_; > >- die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} ); >+ return unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} ); > > $args->{'pluginsdir'} = C4::Context->config("pluginsdir"); > >diff --git a/Koha/Plugins/Base.pm b/Koha/Plugins/Base.pm >index 0e1aedc..2681ee7 100644 >--- a/Koha/Plugins/Base.pm >+++ b/Koha/Plugins/Base.pm >@@ -39,7 +39,7 @@ C4::Plugins::Base - Base Module for plugins > sub new { > my ( $class, $args ) = @_; > >- die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} ); >+ return unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} ); > > $args->{'class'} = $class; > $args->{'template'} = Template->new( { ABSOLUTE => 1 } ); >diff --git a/Koha/Plugins/Handler.pm b/Koha/Plugins/Handler.pm >index d2f324a..18ceba1 100644 >--- a/Koha/Plugins/Handler.pm >+++ b/Koha/Plugins/Handler.pm >@@ -51,7 +51,7 @@ Runs a plugin > sub run { > my ( $class, $args ) = @_; > >- die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} ); >+ return unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} ); > > my $plugin_class = $args->{'class'}; > my $plugin_method = $args->{'method'}; >@@ -60,7 +60,7 @@ sub run { > if ( can_load( modules => { $plugin_class => undef } ) ) { > my $plugin = $plugin_class->new( { cgi => $cgi } ); > if ( $plugin->can($plugin_method) ) { >- $plugin->$plugin_method(); >+ return $plugin->$plugin_method(); > } else { > warn "Plugin does not have method $plugin_method"; > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-disabled.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-disabled.tt >new file mode 100644 >index 0000000..4b100cd >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-disabled.tt >@@ -0,0 +1,30 @@ >+[% INCLUDE 'doc-head-open.inc' %] >+<title>Koha › Tools › Plugins › Upload Plugin >+ </title> >+[% INCLUDE 'doc-head-close.inc' %] >+[% INCLUDE 'calendar.inc' %] >+</head> >+ >+<body> >+[% INCLUDE 'header.inc' %] >+[% INCLUDE 'circ-search.inc' %] >+ >+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> >+› <a href="/cgi-bin/koha/plugins/plugins-home.pl">Plugins</a> >+› Plugins disabled >+</div> >+ >+<div id="doc3" class="yui-t2"> >+ <div id="bd"> >+ <div id="yui-main"> >+ <div class="yui-b"> >+ <div class="yui-g"> >+ <div class="yui-u first"> >+ <h1>Plugins disabled!</h1> >+ >+ <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> >+ </div> >+ </div> >+ </div> >+</div> >+[% INCLUDE 'intranet-bottom.inc' %] >diff --git a/plugins/plugins-home.pl b/plugins/plugins-home.pl >index 8b7a42a..03095bb 100755 >--- a/plugins/plugins-home.pl >+++ b/plugins/plugins-home.pl >@@ -29,29 +29,32 @@ use C4::Dates; > use C4::Debug; > use C4::Context; > >-die("Koha plugins are disabled!") >- unless C4::Context->preference('UseKohaPlugins'); >+my $plugins_enabled = C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins"); > > my $input = new CGI; > my $method = $input->param('method'); > > my ( $template, $borrowernumber, $cookie ) = get_template_and_user( >- { template_name => "plugins/plugins-home.tmpl", >- query => $input, >- type => "intranet", >+ { template_name => ($plugins_enabled) ? "plugins/plugins-home.tt" : "plugins/plugins-disabled.tt", >+ query => $input, >+ type => "intranet", > authnotrequired => 0, > flagsrequired => { plugins => '*' }, > debug => 1, > } > ); > >-$template->param( >- koha_version => C4::Context->preference("Version"), >- method => $method, >-); >+if ($plugins_enabled) { >+ >+ $template->param( >+ koha_version => C4::Context->preference("Version"), >+ method => $method, >+ ); >+ >+ my @plugins = Koha::Plugins->new()->GetPlugins($method); > >-my @plugins = Koha::Plugins->new()->GetPlugins($method); >+ $template->param( plugins => \@plugins, ); > >-$template->param( plugins => \@plugins ); >+} > > output_html_with_http_headers( $input, $cookie, $template->output ); >diff --git a/plugins/plugins-upload.pl b/plugins/plugins-upload.pl >index 4548104..28a647a 100755 >--- a/plugins/plugins-upload.pl >+++ b/plugins/plugins-upload.pl >@@ -1,4 +1,5 @@ > #!/usr/bin/perl >+ > # > # This file is part of Koha. > # >@@ -30,15 +31,14 @@ use C4::Members; > use C4::Debug; > use Koha::Plugins; > >-die("Koha plugins are disabled!") >- unless C4::Context->preference('UseKohaPlugins'); >+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/plugins-upload.tmpl", >- query => $input, >- type => "intranet", >+ { template_name => ($plugins_enabled) ? "plugins/plugins-upload.tmpl" : "plugins/plugins-disabled.tt", >+ query => $input, >+ type => "intranet", > authnotrequired => 0, > flagsrequired => { plugins => 'manage' }, > debug => 1, >@@ -53,46 +53,51 @@ my ( $total, $handled, @counts, $tempfile, $tfh ); > > my %errors; > >-if ( ( $op eq 'Upload' ) && $uploadfile ) { >- my $plugins_dir = C4::Context->config("pluginsdir"); >- >- my $dirname = File::Temp::tempdir( CLEANUP => 1 ); >- $debug and warn "dirname = $dirname"; >+if ($plugins_enabled) { >+ if ( ( $op eq 'Upload' ) && $uploadfile ) { >+ my $plugins_dir = C4::Context->config("pluginsdir"); > >- my $filesuffix; >- $filesuffix = $1 if $uploadfilename =~ m/(\..+)$/i; >- ( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 ); >+ my $dirname = File::Temp::tempdir( CLEANUP => 1 ); >+ $debug and warn "dirname = $dirname"; > >- $debug and warn "tempfile = $tempfile"; >+ my $filesuffix; >+ $filesuffix = $1 if $uploadfilename =~ m/(\..+)$/i; >+ ( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 ); > >- $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 ); >+ $debug and warn "tempfile = $tempfile"; > >- if (%errors) { >- $template->param( ERRORS => [ \%errors ] ); >- } else { >- while (<$uploadfile>) { >- print $tfh $_; >- } >- close $tfh; >+ $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 ); > >- my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' ); >- unless ( $ae->extract( to => $plugins_dir ) ) { >- warn "ERROR: " . $ae->error; >- $errors{'UZIPFAIL'} = $uploadfilename; >+ if (%errors) { > $template->param( ERRORS => [ \%errors ] ); >- output_html_with_http_headers $input, $cookie, $template->output; >- exit; >+ } 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; > } >-} 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; > } >diff --git a/plugins/run.pl b/plugins/run.pl >index 6b8ef28..6c462ed 100755 >--- a/plugins/run.pl >+++ b/plugins/run.pl >@@ -29,8 +29,7 @@ use C4::Dates; > use C4::Debug; > use C4::Context; > >-die("Koha plugins are disabled!") >- unless C4::Context->preference('UseKohaPlugins'); >+my $plugins_enabled = C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins"); > > my $cgi = new CGI; > >@@ -38,7 +37,7 @@ my $class = $cgi->param('class'); > my $method = $cgi->param('method'); > > my ( $template, $borrowernumber, $cookie ) = get_template_and_user( >- { template_name => "plugins/plugins-home.tmpl", >+ { template_name => "plugins/plugins-disabled.tmpl", > query => $cgi, > type => "intranet", > authnotrequired => 0, >@@ -47,4 +46,8 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( > } > ); > >-my $plugin = Koha::Plugins::Handler->run( { class => $class, method => $method, cgi => $cgi } ); >+if ( $plugins_enabled ) { >+ my $plugin = Koha::Plugins::Handler->run( { class => $class, method => $method, cgi => $cgi } ); >+} else { >+ output_html_with_http_headers( $cgi, $cookie, $template->output ); >+} >diff --git a/t/Koha/Plugin/Test.pm b/t/Koha/Plugin/Test.pm >index d34a6eb..ca59564 100644 >--- a/t/Koha/Plugin/Test.pm >+++ b/t/Koha/Plugin/Test.pm >@@ -29,25 +29,25 @@ sub new { > > sub report { > my ( $self, $args ) = @_; >- return 1; >+ return "Koha::Plugin::Test::report"; > } > > sub tool { > my ( $self, $args ) = @_; >- return 1; >+ return "Koha::Plugin::Test::tool"; > } > > sub configure { > my ( $self, $args ) = @_; >- return 1; >+ return "Koha::Plugin::Test::configure";; > } > > sub install { > my ( $self, $args ) = @_; >- return 1; >+ return "Koha::Plugin::Test::intstall"; > } > > sub uninstall { > my ( $self, $args ) = @_; >- return 1; >+ return "Koha::Plugin::Test::uninstall"; > } >diff --git a/t/db_dependent/Plugins.t b/t/db_dependent/Plugins.t >index 52495ea..a36fe3c 100755 >--- a/t/db_dependent/Plugins.t >+++ b/t/db_dependent/Plugins.t >@@ -3,7 +3,7 @@ > use strict; > use warnings; > >-use Test::More tests => 15; >+use Test::More tests => 16; > use File::Basename; > > use Module::Load::Conditional qw(can_load); >@@ -32,6 +32,8 @@ ok( $plugin->can('configure'), 'Test plugin can configure' ); > ok( $plugin->can('install'), 'Test plugin can install' ); > ok( $plugin->can('uninstall'), 'Test plugin can install' ); > >+ok( Koha::Plugins::Handler->run({ class => "Koha::Plugin::Test", method => 'report' }) eq "Koha::Plugin::Test::report", 'Test run plugin report method' ); >+ > my $metadata = $plugin->get_metadata(); > ok( $metadata->{'name'} eq 'Test Plugin', 'Test $plugin->get_metadata()' ); > >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 7804
:
8525
|
8528
|
8545
|
8546
|
8591
|
8595
|
8596
|
8597
|
8607
|
8608
|
8609
|
9565
|
9636
|
9637
|
9644
|
9755
|
11606
|
14506
|
14508
|
14509
|
14510
|
14511
|
14512
|
14513
|
14514
|
14530
|
14531
|
14538
|
14539
|
14540
|
14541
|
14542
|
14543
|
14545
|
14562
|
14563
|
14632
|
14633
|
14731
|
15166
|
15167
|
15168
|
15531
|
15532
|
15533
|
15570
|
15571
|
15572
|
15653
|
15654
|
15655
|
15656
|
16220
|
16221
|
16222
|
16223
|
16297
|
16298
|
16299