Bugzilla – Attachment 95621 Details for
Bug 23924
Add a parameter to the script add_date_fields_to_marc_records.pl to specify a date field
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23924: Add --date-field to add_date_fields_to_marc_records.pl
Bug-23924-Add---date-field-to-adddatefieldstomarcr.patch (text/plain), 4.70 KB, created by
Hugo Agud
on 2019-11-20 17:09:38 UTC
(
hide
)
Description:
Bug 23924: Add --date-field to add_date_fields_to_marc_records.pl
Filename:
MIME Type:
Creator:
Hugo Agud
Created:
2019-11-20 17:09:38 UTC
Size:
4.70 KB
patch
obsolete
>From e373895317b55a28200f215900800ba62ddd71f1 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 30 Oct 2019 09:12:39 +0100 >Subject: [PATCH] Bug 23924: Add --date-field to > add_date_fields_to_marc_records.pl > >The date used in the script will use this parameter, instead of today. > >Test plan: >Use the POD of the script to understand how this flag works. Then use >the script to create fields with a date contained in a specific MARC >field. > >Signed-off-by: Hugo Agud <hagud@orex.es> >--- > misc/add_date_fields_to_marc_records.pl | 55 ++++++++++++++++++++++++++------- > 1 file changed, 43 insertions(+), 12 deletions(-) > >diff --git a/misc/add_date_fields_to_marc_records.pl b/misc/add_date_fields_to_marc_records.pl >index b7ab77c2cb..29dfaf4213 100755 >--- a/misc/add_date_fields_to_marc_records.pl >+++ b/misc/add_date_fields_to_marc_records.pl >@@ -31,7 +31,7 @@ use MARC::Field; > use C4::Biblio; > use Koha::DateUtils qw( dt_from_string ); > >-my ( $verbose, $help, $confirm, $where, @fields, $unless_exists_field ); >+my ( $verbose, $help, $confirm, $where, @fields, $date_field, $unless_exists_field ); > my $dbh = C4::Context->dbh; > > GetOptions( >@@ -40,25 +40,29 @@ GetOptions( > 'confirm|c' => \$confirm, > 'where=s' => \$where, > 'field=s@' => \@fields, >+ 'date-field=s' => \$date_field, > 'unless-exists=s' => \$unless_exists_field, > ) || podusage(1); > > pod2usage(1) if $help; > pod2usage("Parameter field is mandatory") unless @fields; > >+say "Confirm flag not passed, running in dry-run mode..." unless $confirm; >+ > my @fields_to_add; >-my $dt = dt_from_string; # Could be an option of the script >-for my $field (@fields) { >- my ( $f_sf, $value ) = split '=', $field; >- my ( $tag, $subfield ) = split '\$', $f_sf; >- push @fields_to_add, >- MARC::Field->new( $tag, '', '', $subfield => $dt->strftime($value) ); >-} >+unless ( $date_field ) { >+ my $dt = dt_from_string; >+ for my $field (@fields) { >+ my ( $f_sf, $value ) = split '=', $field; >+ my ( $tag, $subfield ) = split '\$', $f_sf; >+ push @fields_to_add, >+ MARC::Field->new( $tag, '', '', $subfield => $dt->strftime($value) ); >+ } > >-say "Confirm flag not passed, running in dry-run mode..." unless $confirm; >-if ($verbose) { >- say "The following MARC fields will be added:"; >- say "\t" . $_->as_formatted for @fields_to_add; >+ if ($verbose) { >+ say "The following MARC fields will be added:"; >+ say "\t" . $_->as_formatted for @fields_to_add; >+ } > } > > $where = $where ? "WHERE $where" : ''; >@@ -74,7 +78,26 @@ while ( my ( $biblionumber, $frameworkcode ) = $sth->fetchrow_array ) { > my ( $tag, $subfield ) = split '\$', $unless_exists_field; > next if $marc_record->subfield($tag, $subfield); > } >+ if ( $date_field ) { >+ my ( $tag, $subfield ) = split '\$', $date_field; >+ my $date = $marc_record->subfield($tag, $subfield); >+ next unless $date; >+ warn $date; >+ my $dt = dt_from_string($date); >+ for my $field (@fields) { >+ my ( $f_sf, $value ) = split '=', $field; >+ my ( $tag, $subfield ) = split '\$', $f_sf; >+ push @fields_to_add, >+ MARC::Field->new( $tag, '', '', $subfield => $dt->strftime($value) ); >+ } >+ if ($verbose) { >+ say sprintf "The following MARC fields will be added to record %s:", $biblionumber; >+ say "\t" . $_->as_formatted for @fields_to_add; >+ } >+ } >+ > $marc_record->append_fields(@fields_to_add); >+ > if ($confirm) { > my $modified = > C4::Biblio::ModBiblio( $marc_record, $biblionumber, $frameworkcode ); >@@ -98,6 +121,8 @@ add_date_fields_to_marc_records.pl > > perl add_date_fields_to_marc_records.pl --field='905$a=0/%Y' --field='905$a=1/%Y/%b-%m' --field='905$a=2/%Y/%b-%m/%d' --unless-exists='905$a' --where "biblionumber=42" --verbose --confirm > >+ perl add_date_fields_to_marc_records.pl --field='905$a=0/%Y' --field='905$a=1/%Y/%b-%m' --field='905$a=2/%Y/%b-%m/%d' --date-field='908$a' --verbose --confirm >+ > =head1 DESCRIPTION > > Add some MARC fields to bibliographic records. >@@ -145,6 +170,12 @@ Will only create the new fields if this field does not exist. > For instance, if --field='905$a=0/%Y' and --unless-exists='905$a' are provided, a 905$a will be created unless there is already one. > If --unless-exists is not passed, a new 905$a will be created in any case. > >+=item B<--date-field> >+ >+The date will be picked from a specific marc field. >+ >+For instance, if the record contains a date formatted YYYY-MM-DD in 908$a, you can pass --date-field='908$a' >+Note that the date format used will be the one defined in the syspref 'dateformat', or iso format. > > =back > >-- >2.11.0
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 23924
:
94860
|
95621
|
98217
|
149739
|
149740
|
150131
|
150132