3 # Copyright Rijksmuseum 2017
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use List
::MoreUtils qw
/uniq/;
27 use C4
::AuthoritiesMarc qw
/AddAuthority DelAuthority GetAuthority merge/;
29 my ( @authid, $confirm, $delete, $help, $merge, $reference, $renumber, $verbose );
31 'authid:s' => \
@authid,
32 'confirm' => \
$confirm,
36 'reference:i' => \
$reference,
37 'renumber' => \
$renumber,
38 'verbose' => \
$verbose,
41 @authid = map { split /[,]/, $_; } @authid;
42 print "No changes will be made\n" unless $confirm;
43 pod2usage
(1) if $help;
45 if ( $delete and $merge and $renumber ) {
46 pod2usage
(q
|Only one action parameter can be passed
(delete, merge
or renumber
)|);
50 delete_auth
( \
@authid );
52 pod2usage
(q
|Reference parameter is missing
|) unless $reference;
53 merge_auth
( \
@authid, $reference );
54 } elsif( $renumber ) {
62 foreach my $authid ( uniq
(@
$auths) ) {
64 DelAuthority
({ authid
=> $authid }); # triggers a merge (read: cleanup)
65 print "Removing $authid\n" if $verbose;
67 print "Would have removed $authid\n" if $verbose;
73 my ( $auths, $reference ) = @_;
75 return unless $reference;
77 my $marc_ref = GetAuthority
( $reference ) || die "Reference record $reference not found\n";
78 # First update all linked biblios of reference
79 merge
({ mergefrom
=> $reference, MARCfrom
=> $marc_ref, mergeto
=> $reference, MARCto
=> $marc_ref, override_limit
=> 1 }) if $confirm;
81 # Merge all authid's into reference
83 foreach my $authid ( uniq
(@
$auths) ) {
84 next if $authid == $reference;
85 $marc = GetAuthority
($authid);
87 print "Authority id $authid ignored, does not exist.\n";
94 mergeto
=> $reference,
98 DelAuthority
({ authid
=> $authid, skip_merge
=> 1 });
99 print "Record $authid merged into reference $reference.\n" if $verbose;
101 print "Would have merged record $authid into reference $reference.\n" if $verbose;
108 foreach my $authid ( uniq
(@
$auths) ) {
109 if( my $authority = Koha
::Authorities
->find($authid) ) {
110 my $marc = GetAuthority
( $authid );
112 AddAuthority
( $marc, $authid, $authority->authtypecode );
113 # AddAuthority contains an update of 001, 005 etc.
114 print "Renumbered $authid\n" if $verbose;
116 print "Would have renumbered $authid\n" if $verbose;
119 print "Record $authid not found!\n" if $verbose;
126 update_authorities.pl
130 Script to perform various authority related maintenance tasks.
131 This version supports deleting an authority record and updating all linked
133 Furthermore it supports merging authority records with one reference record,
134 and updating all linked biblio records.
135 It also allows you to force a renumber, i.e. save the authid into field 001.
139 update_authorities.pl -c -authid 1,2,3 -delete
141 update_authorities.pl -c -authid 1 -authid 2 -authid 3 -delete
143 update_authorities.pl -c -authid 1,2 -merge -reference 3
145 update_authorities.pl -c -merge -reference 4
147 update_authorities.pl -c -authid 1,2,3 -renumber
151 authid: List authority numbers separated by commas or repeat the
154 confirm: Needed to commit changes.
156 delete: Delete the listed authority numbers and remove its references from
157 linked biblio records.
159 merge: Merge the passed authid's into reference and update all linked biblio
160 records. If you do not pass authid's, the linked biblio records of reference
161 will be updated only.
163 renumber: Save authid into field 001.
167 Marcel de Rooy, Rijksmuseum Amsterdam, The Netherlands