Browse Source

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 <bgkriegel@gmail.com>
Both plugins works, no errors

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
3.22.x
Marcel de Rooy 6 years ago
committed by Tomas Cohen Arazi
parent
commit
efe5266625
  1. 16
      Koha/Util/FrameworkPlugin.pm
  2. 10
      cataloguing/value_builder/marc21_field_008.pl
  3. 26
      cataloguing/value_builder/marc21_field_008_authorities.pl
  4. 7
      t/Koha_Util_FrameworkPlugin.t

16
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;

10
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 = "
<script type=\"text/javascript\">
//<![CDATA[
@ -149,6 +144,7 @@ sub plugin {
}
);
my $dateentered = date_entered();
$result = "$dateentered" . "b xxu||||| |||| 00| 0 $lang d" unless $result;
my $errorXml = '';
# Check if the xml, xsd exists and is validated

26
cataloguing/value_builder/marc21_field_008_authorities.pl

@ -1,6 +1,5 @@
#!/usr/bin/perl
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
@ -26,6 +25,7 @@ use C4::Context;
use C4::Search;
use C4::Output;
use Koha::Util::FrameworkPlugin qw|date_entered|;
use constant FIXLEN_DATA_ELTS => '|| aca||aabn | a|a d';
use constant PREF_008 => 'MARCAuthorityControlField008';
@ -36,16 +36,11 @@ 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);
my $defaultval = Field008();
sub plugin_javascript {
my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
my $function_name= $field_number;
my $dateentered = date_entered();
my $defaultval = substr( C4::Context->preference(PREF_008) || FIXLEN_DATA_ELTS, 0, 34 );
my $res="
<script type=\"text/javascript\">
//<![CDATA[
@ -79,6 +74,8 @@ sub plugin {
my $index= $input->param('index');
my $result= $input->param('result');
my $authtype= $input->param('authtypecode')||'';
my $defaultval = substr( C4::Context->preference(PREF_008) || FIXLEN_DATA_ELTS, 0, 34 );
substr($defaultval,14-6,1)='b' if $authtype=~ /TOPIC_TERM|GENRE.FORM|CHRON_TERM/;
my $dbh = C4::Context->dbh;
@ -91,6 +88,7 @@ sub plugin {
flagsrequired => {editcatalogue => '*'},
debug => 1,
});
my $dateentered = date_entered();
$result = "$dateentered$defaultval" unless $result;
my @f;
for(0,6..17,28,29,31..33,38,39) {
@ -109,15 +107,3 @@ sub plugin {
}
output_html_with_http_headers $input, $cookie, $template->output;
}
sub Field008 {
my $pref= C4::Context->preference(PREF_008);
if(!$pref) {
return FIXLEN_DATA_ELTS;
}
elsif(length($pref)<34) {
warn "marc21_field_008_authorities.pl: Syspref ".PREF_008." should be 34 characters long ";
return FIXLEN_DATA_ELTS;
}
return substr($pref,0,34); #ignore remainder
}

7
t/Koha_Util_FrameworkPlugin.t

@ -1,9 +1,9 @@
#!/usr/bin/perl
use Modern::Perl;
use Test::More tests => 6;
use Test::More tests => 7;
use_ok( 'Koha::Util::FrameworkPlugin', qw(wrapper) );
use_ok( 'Koha::Util::FrameworkPlugin', qw(wrapper date_entered) );
my $char;
is($char=wrapper(' '),'space',"Return space");
@ -11,3 +11,6 @@ is($char=wrapper(' '),'dblspace',"Return dblspace");
is($char=wrapper('|'),'pipe',"Return pipe");
is($char=wrapper('||'),'dblpipe',"Return dblpipe");
is($char=wrapper('somethingelse'),'somethingelse',"Return somethingelse");
my $f008= date_entered();
is( $f008 =~ /^\d{6}$/, 1, 'date_entered gives six digits' );
Loading…
Cancel
Save