Bug 20434: Update UNIMARC framework - auth (TU)
[koha-ffzg.git] / misc / add_date_fields_to_marc_records.pl
index 6368c36..b7ab77c 100755 (executable)
@@ -22,6 +22,8 @@ BEGIN {
     eval { require "$FindBin::Bin/../kohalib.pl" };
 }
 
+use Koha::Script;
+
 use Getopt::Long;
 use Pod::Usage;
 use MARC::Field;
@@ -41,7 +43,8 @@ GetOptions(
     'unless-exists=s' => \$unless_exists_field,
 ) || podusage(1);
 
-pod2usage(0) if $help;
+pod2usage(1) if $help;
+pod2usage("Parameter field is mandatory") unless @fields;
 
 my @fields_to_add;
 my $dt = dt_from_string;    # Could be an option of the script
@@ -58,7 +61,7 @@ if ($verbose) {
     say "\t" . $_->as_formatted for @fields_to_add;
 }
 
-$where ||= "";
+$where = $where ? "WHERE $where" : '';
 my $sth =
   $dbh->prepare("SELECT biblionumber, frameworkcode FROM biblio $where");
 $sth->execute();
@@ -93,12 +96,16 @@ 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' --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' --unless-exists='905$a' --where "biblionumber=42" --verbose --confirm
+
 =head1 DESCRIPTION
 
 Add some MARC fields to bibliographic records.
 
 The replacement tokens are the ones used by strftime.
 
+=head1 OPTIONS
+
 =over 8
 
 =item B<--help>
@@ -112,10 +119,13 @@ Verbose mode.
 =item B<--confirm>
 
 Confirmation flag, the script will be running in dry-run mode if set not.
+
 =item B<--where>
 
 Limits the search on bibliographic records with a user-specified WHERE clause.
 
+Only the columns from the biblio table are available.
+
 =item B<--field>
 
 Fields to add to the bibliographic records.
@@ -130,7 +140,11 @@ For instance:
 
 =item B<--unless-exists>
 
-Will only create the new fields if this field does not exist
+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.
+
 
 =back