|
Lines 29-35
use MARC::Field;
Link Here
|
| 29 |
use C4::Biblio; |
29 |
use C4::Biblio; |
| 30 |
use Koha::DateUtils qw( dt_from_string ); |
30 |
use Koha::DateUtils qw( dt_from_string ); |
| 31 |
|
31 |
|
| 32 |
my ( $verbose, $help, $confirm, $where, @fields ); |
32 |
my ( $verbose, $help, $confirm, $where, @fields, $unless_exists_field ); |
| 33 |
my $dbh = C4::Context->dbh; |
33 |
my $dbh = C4::Context->dbh; |
| 34 |
|
34 |
|
| 35 |
GetOptions( |
35 |
GetOptions( |
|
Lines 38-43
GetOptions(
Link Here
|
| 38 |
'confirm|c' => \$confirm, |
38 |
'confirm|c' => \$confirm, |
| 39 |
'where=s' => \$where, |
39 |
'where=s' => \$where, |
| 40 |
'field=s@' => \@fields, |
40 |
'field=s@' => \@fields, |
|
|
41 |
'unless-exists=s' => \$unless_exists_field, |
| 41 |
) || podusage(1); |
42 |
) || podusage(1); |
| 42 |
|
43 |
|
| 43 |
pod2usage(0) if $help; |
44 |
pod2usage(0) if $help; |
|
Lines 51-57
for my $field (@fields) {
Link Here
|
| 51 |
MARC::Field->new( $tag, '', '', $subfield => $dt->strftime($value) ); |
52 |
MARC::Field->new( $tag, '', '', $subfield => $dt->strftime($value) ); |
| 52 |
} |
53 |
} |
| 53 |
|
54 |
|
| 54 |
say "Confirm flag not passed, running in dry-run mode..."; |
55 |
say "Confirm flag not passed, running in dry-run mode..." unless $confirm; |
| 55 |
if ($verbose) { |
56 |
if ($verbose) { |
| 56 |
say "The following MARC fields will be added:"; |
57 |
say "The following MARC fields will be added:"; |
| 57 |
say "\t" . $_->as_formatted for @fields_to_add; |
58 |
say "\t" . $_->as_formatted for @fields_to_add; |
|
Lines 66-71
while ( my ( $biblionumber, $frameworkcode ) = $sth->fetchrow_array ) {
Link Here
|
| 66 |
my $marc_record = |
67 |
my $marc_record = |
| 67 |
C4::Biblio::GetMarcBiblio( { biblionumber => $biblionumber } ); |
68 |
C4::Biblio::GetMarcBiblio( { biblionumber => $biblionumber } ); |
| 68 |
next unless $marc_record; |
69 |
next unless $marc_record; |
|
|
70 |
if ( $unless_exists_field ) { |
| 71 |
my ( $tag, $subfield ) = split '\$', $unless_exists_field; |
| 72 |
next if $marc_record->subfield($tag, $subfield); |
| 73 |
} |
| 69 |
$marc_record->append_fields(@fields_to_add); |
74 |
$marc_record->append_fields(@fields_to_add); |
| 70 |
if ($confirm) { |
75 |
if ($confirm) { |
| 71 |
my $modified = |
76 |
my $modified = |
|
Lines 86-92
add_date_fields_to_marc_records.pl
Link Here
|
| 86 |
|
91 |
|
| 87 |
perl add_date_fields_to_marc_records.pl --help |
92 |
perl add_date_fields_to_marc_records.pl --help |
| 88 |
|
93 |
|
| 89 |
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' --verbose --confirm |
94 |
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' --verbose --confirm |
| 90 |
|
95 |
|
| 91 |
=head1 DESCRIPTION |
96 |
=head1 DESCRIPTION |
| 92 |
|
97 |
|
|
Lines 123-128
For instance:
Link Here
|
| 123 |
|
128 |
|
| 124 |
905$a=2/%Y/%b-%m/%d'will a a new field 905$a with the value '2/2019/Mar-03/13' if run on March 13th 2019 |
129 |
905$a=2/%Y/%b-%m/%d'will a a new field 905$a with the value '2/2019/Mar-03/13' if run on March 13th 2019 |
| 125 |
|
130 |
|
|
|
131 |
=item B<--unless-exists> |
| 132 |
|
| 133 |
Will only create the new fields if this field does not exist |
| 134 |
|
| 126 |
=back |
135 |
=back |
| 127 |
|
136 |
|
| 128 |
=cut |
137 |
=cut |
| 129 |
- |
|
|