Bug 18071: (QA follow-up) Add commit parameter, add warning

Addressing points mentioned in comment12:
[1] Commit parameter.
[2] Warning if authid does not exist for -merge.

Test plan:
[1] Run update_authorities.pl -authid X -merge -ref Y -c
    where X does not exist in your db and Y does.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Marcel de Rooy 2017-12-01 12:29:48 +01:00 committed by Jonathan Druart
parent ace03864ba
commit ae48ff6729

View file

@ -25,9 +25,10 @@ use Pod::Usage;
use C4::AuthoritiesMarc qw/AddAuthority DelAuthority GetAuthority merge/;
my ( @authid, $delete, $help, $merge, $reference, $renumber, $verbose );
my ( @authid, $commit, $delete, $help, $merge, $reference, $renumber, $verbose );
GetOptions(
'authid:s' => \@authid,
'commit' => \$commit,
'delete' => \$delete,
'help' => \$help,
'merge' => \$merge,
@ -37,14 +38,17 @@ GetOptions(
);
@authid = map { split /[,]/, $_; } @authid;
if( $delete ) {
if( $help ) {
pod2usage(1);
} elsif( !$commit ) {
print "Please add -commit parameter\n";
exit;
} elsif( $delete ) {
delete_auth( \@authid );
} elsif( $merge ) {
merge_auth( \@authid, $reference );
} elsif( $renumber ) {
renumber( \@authid );
} elsif( $help ) {
pod2usage(1);
} else {
pod2usage(1);
}
@ -71,7 +75,11 @@ sub merge_auth {
my $marc;
foreach my $authid ( uniq(@$auths) ) {
next if $authid == $reference;
$marc = GetAuthority($authid) || next;
$marc = GetAuthority($authid);
if( !$marc ) {
print "Authority id $authid ignored, does not exist.\n";
next;
}
merge({ mergefrom => $authid, MARCfrom => $marc, mergeto => $reference, MARCto => $marc_ref, override_limit => 1 });
DelAuthority({ authid => $authid, skip_merge => 1 });
print "Record $authid merged into reference.\n" if $verbose;
@ -107,21 +115,23 @@ It also allows you to force a renumber, i.e. save the authid into field 001.
=head1 SYNOPSIS
update_authorities.pl -authid 1,2,3 -delete
update_authorities.pl -c -authid 1,2,3 -delete
update_authorities.pl -authid 1 -authid 2 -authid 3 -delete
update_authorities.pl -c -authid 1 -authid 2 -authid 3 -delete
update_authorities.pl -authid 1,2 -merge -reference 3
update_authorities.pl -c -authid 1,2 -merge -reference 3
update_authorities.pl -merge -reference 4
update_authorities.pl -c -merge -reference 4
update_authorities.pl -authid 1,2,3 -renumber
update_authorities.pl -c -authid 1,2,3 -renumber
=head1 OPTIONS
authid: List authority numbers separated by commas or repeat the
parameter.
commit: Needed to commit changes.
delete: Delete the listed authority numbers and remove its references from
linked biblio records.