From efe52666259d533d2c0a375cb7c764dbff3a58d3 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Tue, 12 May 2015 17:49:04 +0200 Subject: [PATCH] Bug 13437: Preliminary changes for marc21 plugins field 008 Preliminary work on marc21_field_008.pl and 008_authorities.pl. Moving $dateentered en $defaultval to lower scope level. date_entered is a new sub (in a module); sub Field008 has been reduced to one line. Added a trivial unit test for date_entered. Note: the format used in date_entered could be added in DateUtils, moving this logic to a better place. Test plan: Use both plugins in the marc21 editor (biblios/authorities). Run the adjusted unit test. Signed-off-by: Bernardo Gonzalez Kriegel Both plugins works, no errors Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- Koha/Util/FrameworkPlugin.pm | 16 +++++++++++- cataloguing/value_builder/marc21_field_008.pl | 10 +++---- .../marc21_field_008_authorities.pl | 26 +++++-------------- t/Koha_Util_FrameworkPlugin.t | 7 +++-- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/Koha/Util/FrameworkPlugin.pm b/Koha/Util/FrameworkPlugin.pm index f0eabc07cb..e226295a13 100644 --- a/Koha/Util/FrameworkPlugin.pm +++ b/Koha/Util/FrameworkPlugin.pm @@ -27,7 +27,7 @@ BEGIN { require Exporter; @ISA = qw( Exporter ); @EXPORT = qw( ); - @EXPORT_OK = qw( wrapper ); + @EXPORT_OK = qw( wrapper date_entered ); } =head1 NAME @@ -52,4 +52,18 @@ sub wrapper { return $str; } +=head2 date_entered + + date_entered returns date in yymmdd format as needed by MARC21 field 008 + +=cut + +sub date_entered { + # find today's date + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + $year +=1900; + $mon +=1; + return substr($year,2,2).sprintf ("%0.2d", $mon).sprintf ("%0.2d",$mday); +} + 1; diff --git a/cataloguing/value_builder/marc21_field_008.pl b/cataloguing/value_builder/marc21_field_008.pl index cc2d28d2f5..01d63d76c6 100755 --- a/cataloguing/value_builder/marc21_field_008.pl +++ b/cataloguing/value_builder/marc21_field_008.pl @@ -27,6 +27,7 @@ use C4::Search; use C4::Output; use XML::LibXML; +use Koha::Util::FrameworkPlugin qw|date_entered|; =head1 DESCRIPTION @@ -34,13 +35,6 @@ plugin_parameters : other parameters added when the plugin is called by the dopo =cut -# find today's date -my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time); - -$year += 1900; -$mon += 1; -my $dateentered = substr($year, 2, 2) . sprintf("%0.2d", $mon) . sprintf("%0.2d", $mday); - sub plugin_javascript { my $lang = C4::Context->preference('DefaultLanguageField008' ); $lang = "eng" unless $lang; @@ -48,6 +42,7 @@ sub plugin_javascript { my ($dbh, $record, $tagslib, $field_number, $tabloop) = @_; my $function_name = $field_number; + my $dateentered = date_entered(); my $res = "