use Modern::Perl;
-BEGIN {
- use FindBin;
- eval { require "$FindBin::Bin/../kohalib.pl" };
-}
+use Koha::Script;
-use Getopt::Long;
-use Pod::Usage;
+use Getopt::Long qw( GetOptions );
+use Pod::Usage qw( pod2usage );
use MARC::Field;
use C4::Biblio;
+use Koha::Biblios;
use Koha::DateUtils qw( dt_from_string );
my ( $verbose, $help, $confirm, $where, @fields, $unless_exists_field );
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();
while ( my ( $biblionumber, $frameworkcode ) = $sth->fetchrow_array ) {
- my $marc_record =
- C4::Biblio::GetMarcBiblio( { biblionumber => $biblionumber } );
+ my $biblio = Koha::Biblios->find($biblionumber);
+ my $marc_record = $biblio->metadata->record;
next unless $marc_record;
if ( $unless_exists_field ) {
my ( $tag, $subfield ) = split '\$', $unless_exists_field;
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.
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.
=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