From 996b3758e3cec98c31057f6d24a9bf7e721c9619 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Tue, 5 Apr 2016 14:51:43 +0200 Subject: [PATCH] Bug 16203: Convert item plugins to new style (see bug 10480) Content-Type: text/plain; charset=utf-8 Converts item plugins to new style (with builder and launcher). See also bugs 10480 and 13437. The following plugins have been adjusted: barcode_manual.pl barcode.pl callnumber-KU.pl callnumber.pl cn_browser.pl (Added license statement too) dateaccessioned.pl macles.pl stocknumberam123.pl stocknumberAV.pl stocknumber.pl Test plan: Connect the plugin to an item field. Verify that the plugin still works. Signed-off-by: Marcel de Rooy Tested if all plugins compile okay. Ran most of them thru FrameworkPlugin.t. Tested them in the item editor. Note: the form for macles.pl comes up, further hard to test. --- cataloguing/value_builder/barcode.pl | 40 ++++++++++---------- cataloguing/value_builder/barcode_manual.pl | 36 +++++++++--------- cataloguing/value_builder/callnumber-KU.pl | 32 +++++++++------- cataloguing/value_builder/callnumber.pl | 32 +++++++++------- cataloguing/value_builder/cn_browser.pl | 50 +++++++++++++++++-------- cataloguing/value_builder/dateaccessioned.pl | 36 +++++++++--------- cataloguing/value_builder/macles.pl | 45 +++++++++------------- cataloguing/value_builder/stocknumber.pl | 36 +++++++++--------- cataloguing/value_builder/stocknumberAV.pl | 28 ++++++++------ cataloguing/value_builder/stocknumberam123.pl | 30 ++++++++------- 10 files changed, 193 insertions(+), 172 deletions(-) diff --git a/cataloguing/value_builder/barcode.pl b/cataloguing/value_builder/barcode.pl index b1b4f61..3bd49f2 100755 --- a/cataloguing/value_builder/barcode.pl +++ b/cataloguing/value_builder/barcode.pl @@ -1,4 +1,7 @@ #!/usr/bin/perl + +# Converted to new plugin style (Bug 13437) + # Copyright 2000-2002 Katipo Communications # Parts copyright 2008-2010 Foundations Bible College # @@ -17,21 +20,19 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -use strict; -use warnings; -no warnings 'redefine'; # otherwise loading up multiple plugins fills the log with subroutine redefine warnings +use Modern::Perl; use C4::Context; -require C4::Barcodes::ValueBuilder; +use C4::Barcodes::ValueBuilder; use Koha::DateUtils; use Algorithm::CheckDigits; my $DEBUG = 0; -sub plugin_javascript { - my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_; - my $function_name= "barcode".(int(rand(100000))+1); +my $builder = sub { + my ( $params ) = @_; + my $function_name = $params->{id}; my %args; # find today's date @@ -45,13 +46,7 @@ sub plugin_javascript { warn "Barcode type = $autoBarcodeType" if $DEBUG; if ((not $autoBarcodeType) or $autoBarcodeType eq 'OFF') { # don't return a value unless we have the appropriate syspref set - return ($function_name, - ""); + return q||; } if ($autoBarcodeType eq 'annual') { ($nextnum, $scr) = C4::Barcodes::ValueBuilder::annual::get_barcode(\%args); @@ -65,6 +60,7 @@ sub plugin_javascript { elsif ($autoBarcodeType eq 'EAN13') { # not the best, two catalogers could add the same barcode easily this way :/ my $query = "select max(abs(barcode)) from items"; + my $dbh = $params->{dbh}; my $sth = $dbh->prepare($query); $sth->execute(); while (my ($last)= $sth->fetchrow_array) { @@ -88,23 +84,25 @@ sub plugin_javascript { $scr or $scr = < // END_OF_JS - return ($function_name, $js); -} + return $js; +}; + +return { builder => $builder }; diff --git a/cataloguing/value_builder/barcode_manual.pl b/cataloguing/value_builder/barcode_manual.pl index 6bf5ac4..a035769 100755 --- a/cataloguing/value_builder/barcode_manual.pl +++ b/cataloguing/value_builder/barcode_manual.pl @@ -1,4 +1,7 @@ #!/usr/bin/perl + +# Converted to new plugin style (Bug 13437) + # Copyright 2000-2002 Katipo Communications # Parts copyright 2008-2010 Foundations Bible College # @@ -17,21 +20,20 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -use strict; -use warnings; -no warnings 'redefine'; # otherwise loading up multiple plugins fills the log with subroutine redefine warnings +use Modern::Perl; use C4::Context; -require C4::Barcodes::ValueBuilder; +use C4::Barcodes::ValueBuilder; use Koha::DateUtils; my $DEBUG = 0; -sub plugin_javascript { - my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_; - my $function_name= "barcode".(int(rand(100000))+1); +my $builder = sub { + my ( $params ) = @_; + my $function_name = $params->{id}; my %args; + my $dbh = $params->{dbh}; $args{dbh} = $dbh; # find today's date @@ -45,13 +47,7 @@ sub plugin_javascript { warn "Barcode type = $autoBarcodeType" if $DEBUG; if ((not $autoBarcodeType) or $autoBarcodeType eq 'OFF') { # don't return a value unless we have the appropriate syspref set - return ($function_name, - ""); + return q||; } if ($autoBarcodeType eq 'annual') { ($nextnum, $scr) = C4::Barcodes::ValueBuilder::annual::get_barcode(\%args); @@ -70,16 +66,18 @@ sub plugin_javascript { } END_OF_JS - my $js = < // END_OF_JS - return ($function_name, $js); -} + return $js; +}; + +return { builder => $builder }; diff --git a/cataloguing/value_builder/callnumber-KU.pl b/cataloguing/value_builder/callnumber-KU.pl index 8394da0..5cbdd25 100755 --- a/cataloguing/value_builder/callnumber-KU.pl +++ b/cataloguing/value_builder/callnumber-KU.pl @@ -1,5 +1,7 @@ #!/usr/bin/perl +# Converted to new plugin style (Bug 13437) + # Copyright 2012 CatalystIT Ltd # # This file is part of Koha. @@ -17,10 +19,10 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -use strict; -use warnings; -use C4::Auth; +use Modern::Perl; use CGI qw ( -utf8 ); + +use C4::Auth; use C4::Context; use C4::Output; @@ -40,12 +42,12 @@ CCC QW - returns first unused number CCC QWxx starting with CCC QW01 =cut -sub plugin_javascript { - my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_; +my $builder = sub { + my ( $params ) = @_; my $res=" "; + return $res; +}; - return ($field_number,$res); -} - -my $BASE_CALLNUMBER_RE = qr/^(\w+) (\w+)$/; -sub plugin { - my ($input) = @_; +my $launcher = sub { + my ( $params ) = @_; + my $input = $params->{cgi}; my $code = $input->param('code'); my ($template, $loggedinuser, $cookie) = get_template_and_user({ @@ -74,6 +75,7 @@ sub plugin { debug => 1, }); + my $BASE_CALLNUMBER_RE = qr/^(\w+) (\w+)$/; my $ret; my ($alpha, $num) = ($code =~ $BASE_CALLNUMBER_RE); if (defined $num) { # otherwise no point @@ -117,4 +119,6 @@ sub plugin { return => $ret || $code ); output_html_with_http_headers $input, $cookie, $template->output; -} +}; + +return { builder => $builder, launcher => $launcher }; diff --git a/cataloguing/value_builder/callnumber.pl b/cataloguing/value_builder/callnumber.pl index 9d69f27..aeca228 100755 --- a/cataloguing/value_builder/callnumber.pl +++ b/cataloguing/value_builder/callnumber.pl @@ -1,5 +1,7 @@ #!/usr/bin/perl +# Converted to new plugin style (Bug 13437) + # Copyright 2010 BibLibre SARL # # This file is part of Koha. @@ -17,10 +19,10 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -use strict; -use warnings; -use C4::Auth; +use Modern::Perl; use CGI qw ( -utf8 ); + +use C4::Auth; use C4::Context; use C4::Output; @@ -37,12 +39,12 @@ In this case, a callnumber has this form : "PREFIX 0009678570". =cut -sub plugin_javascript { - my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_; +my $builder = sub { + my ( $params ) = @_; my $res=" "; + return $res; +}; - return ($field_number,$res); -} - -sub plugin { - my ($input) = @_; +my $launcher = sub { + my ( $params ) = @_; + my $input = $params->{cgi}; my $code = $input->param('code'); my ($template, $loggedinuser, $cookie) = get_template_and_user({ @@ -82,7 +84,7 @@ sub plugin { return => $max+1, ); } - # If a prefix is submited, we look for the highest itemcallnumber with this prefix, and return it incremented + # If a prefix is submitted, we look for the highest itemcallnumber with this prefix, and return it incremented } elsif ( $code =~ m/^[A-Z.\-']+$/ ) { my $sth = $dbh->prepare("SELECT MAX(CAST(SUBSTRING_INDEX(itemcallnumber,' ',-1) AS SIGNED)) FROM items WHERE itemcallnumber LIKE ?"); $sth->execute($code.' %'); @@ -104,4 +106,6 @@ sub plugin { ); } output_html_with_http_headers $input, $cookie, $template->output; -} +}; + +return { builder => $builder, launcher => $launcher }; diff --git a/cataloguing/value_builder/cn_browser.pl b/cataloguing/value_builder/cn_browser.pl index 9599666..51767a9 100755 --- a/cataloguing/value_builder/cn_browser.pl +++ b/cataloguing/value_builder/cn_browser.pl @@ -1,34 +1,52 @@ -use Modern::Perl; -no warnings 'redefine'; +#!/usr/bin/perl + +# Converted to new plugin style (Bug 13437) + +# Copyright 2015 Koha Development Team +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +use Modern::Perl; use CGI; + use C4::Auth; use C4::ClassSource; use C4::Output; -sub plugin_javascript { - my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_; - my $function_name = "328" . ( int( rand(100000) ) + 1 ); +my $builder = sub { + my ( $params ) = @_; + my $function_name = $params->{id}; my $res = " "; + return $res; +}; - return ( $function_name, $res ); -} - -sub plugin { - my ($input) = @_; - my $cgi = new CGI; - my $params = $cgi->Vars; +my $launcher = sub { + my ( $params ) = @_; + my $cgi = $params->{cgi}; my $results_per_page = 30; my $current_page = $cgi->param('page') || 1; @@ -143,6 +161,6 @@ sub plugin { $template->param( 'popup' => defined( $cgi->param('popup') ) ); output_html_with_http_headers $cgi, $cookie, $template->output; -} +}; -1; +return { builder => $builder, launcher => $launcher }; diff --git a/cataloguing/value_builder/dateaccessioned.pl b/cataloguing/value_builder/dateaccessioned.pl index 5244a1e..5fc1c45 100755 --- a/cataloguing/value_builder/dateaccessioned.pl +++ b/cataloguing/value_builder/dateaccessioned.pl @@ -1,5 +1,7 @@ #!/usr/bin/perl +# Converted to new plugin style (Bug 13437) + # Copyright 2000-2002 Katipo Communications # # This file is part of Koha. @@ -18,12 +20,12 @@ # along with Koha; if not, see . use Modern::Perl; +use C4::Biblio qw/GetMarcFromKohaField/; use Koha::DateUtils; -no warnings 'redefine'; -sub plugin_javascript { - # my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_; - my $function_name = "dateaccessioned".(int(rand(100000))+1); +my $builder = sub { + my ( $params ) = @_; + my $function_name = $params->{id}; my $date = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); @@ -35,29 +37,25 @@ sub plugin_javascript { // // from: cataloguing/value_builder/dateaccessioned.pl -function Focus$function_name(subfield_managed, id, force) { - //var summary = ""; - //for (i=0 ; i END_OF_JS - return ($function_name, $res); -} + return $res; +}; + +return { builder => $builder }; diff --git a/cataloguing/value_builder/macles.pl b/cataloguing/value_builder/macles.pl index c37b6a0..bed0c88 100755 --- a/cataloguing/value_builder/macles.pl +++ b/cataloguing/value_builder/macles.pl @@ -1,5 +1,6 @@ #!/usr/bin/perl +# Converted to new plugin style (Bug 13437) # Copyright 2000-2002 Katipo Communications # @@ -18,44 +19,33 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -use strict; -#use warnings; FIXME - Bug 2505 +use Modern::Perl; use CGI qw ( -utf8 ); + use C4::Context; use C4::Output; use C4::Auth; -# use Data::Dumper; -use vars qw( $tagslib); -use vars qw( $authorised_values_sth); -use vars qw( $is_a_modif ); -use utf8; - -sub plugin_javascript { -my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_; -my $function_name= "macles".(int(rand(100000))+1); -my $res=" +my $builder = sub { + my ( $params ) = @_; + my $function_name = $params->{id}; + my $res=" "; + return $res; +}; -return ($function_name,$res); -} - -sub plugin { -my ($input) = @_; - -# my $input = new CGI; +my $launcher = sub { + my ( $params ) = @_; + my $input = $params->{cgi}; my $index= $input->param('index'); - my $dbh = C4::Context->dbh; my $rq=$dbh->prepare("SELECT authorised_value, lib from authorised_values where category=\"MACLES\" order by authorised_value DESC"); #tabs @@ -90,7 +80,6 @@ my ($input) = @_; } else { unshift @{$numbers{$number}->{$tab->{'authorised_value'}}},$tab->{'lib'}; } -# use Data::Dumper;warn "BIGLOOP IN".Dumper(@BIGLOOP); } foreach my $num ( sort keys %numbers ) { my @tmpcolhdr; @@ -168,7 +157,7 @@ my ($input) = @_; $BIGLOOPcell{'number'} = $num; push @BIGLOOP, \%BIGLOOPcell; } -# warn "BIGLOOP OUT".Dumper(@BIGLOOP); + my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "cataloguing/value_builder/macles.tt", query => $input, @@ -180,4 +169,6 @@ my ($input) = @_; $template->param(BIGLOOP=>\@BIGLOOP); $template->param("index"=>$index); output_html_with_http_headers $input, $cookie, $template->output; -} +}; + +return { builder => $builder, launcher => $launcher }; diff --git a/cataloguing/value_builder/stocknumber.pl b/cataloguing/value_builder/stocknumber.pl index ae150dd..11e237c 100755 --- a/cataloguing/value_builder/stocknumber.pl +++ b/cataloguing/value_builder/stocknumber.pl @@ -1,5 +1,7 @@ #!/usr/bin/perl +# Converted to new plugin style (Bug 13437) + # Copyright 2000-2002 Katipo Communications # # This file is part of Koha. @@ -17,13 +19,13 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -use strict; -use warnings; +use Modern::Perl; use C4::Context; -sub plugin_javascript { - my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_; - my $function_name= "inventory".(int(rand(100000))+1); +my $builder = sub { + my ( $params ) = @_; + my $function_name = $params->{id}; + my $dbh = $params->{dbh}; my $branchcode = C4::Context->userenv->{'branch'}; @@ -34,26 +36,24 @@ sub plugin_javascript { my ($nextnum) = $sth->fetchrow; $nextnum = $branchcode.'_'.$nextnum; - my $scr = < // END_OF_JS - return ($function_name, $js); -} + return $js; +}; + +return { builder => $builder }; diff --git a/cataloguing/value_builder/stocknumberAV.pl b/cataloguing/value_builder/stocknumberAV.pl index 8860060..789a055 100755 --- a/cataloguing/value_builder/stocknumberAV.pl +++ b/cataloguing/value_builder/stocknumberAV.pl @@ -1,5 +1,7 @@ #!/usr/bin/perl +# Converted to new plugin style (Bug 13437) + # Copyright 2012 BibLibre SARL # # This file is part of Koha. @@ -18,8 +20,9 @@ # along with Koha; if not, see . use Modern::Perl; -use C4::Auth; use CGI qw ( -utf8 ); + +use C4::Auth; use C4::Context; use C4::Output; @@ -37,12 +40,12 @@ In this case, a stocknumber has this form : "PREFIX 0009678570". =cut -sub plugin_javascript { - my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_; +my $builder = sub { + my ( $params ) = @_; my $res = qq{ }; - return ($field_number,$res); -} + return $res; +}; -sub plugin { - my ($input) = @_; +my $launcher = sub { + my ( $params ) = @_; + my $input = $params->{cgi}; my $code = $input->param('code'); my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -98,4 +102,6 @@ sub plugin { } output_html_with_http_headers $input, $cookie, $template->output; -} +}; + +return { builder => $builder, launcher => $launcher }; diff --git a/cataloguing/value_builder/stocknumberam123.pl b/cataloguing/value_builder/stocknumberam123.pl index 6290be6..17d64ac 100755 --- a/cataloguing/value_builder/stocknumberam123.pl +++ b/cataloguing/value_builder/stocknumberam123.pl @@ -1,5 +1,7 @@ #!/usr/bin/perl +# Converted to new plugin style (Bug 13437) + # Copyright 2010 BibLibre SARL # # This file is part of Koha. @@ -17,10 +19,10 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -use strict; -use warnings; -use C4::Auth; +use Modern::Perl; use CGI qw ( -utf8 ); + +use C4::Auth; use C4::Context; use C4::Output; @@ -38,12 +40,12 @@ In this case, a stocknumber has this form : "PREFIX 0009678570". =cut -sub plugin_javascript { - my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_; +my $builder = sub { + my ( $params ) = @_; my $res=" "; - return ($field_number,$res); -} + return $res; +}; -sub plugin { - my ($input) = @_; +my $launcher = sub { + my ( $params ) = @_; + my $input = $params->{cgi}; my $code = $input->param('code'); my ($template, $loggedinuser, $cookie) = get_template_and_user({ @@ -100,4 +102,6 @@ sub plugin { ); } output_html_with_http_headers $input, $cookie, $template->output; -} +}; + +return { builder => $builder, launcher => $launcher }; -- 1.7.10.4