From ea9395e538d48e9ac454a6a06951237f23ad75a4 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Tue, 7 Feb 2017 13:59:33 +0100 Subject: [PATCH] Bug 18070: Add script for clean removal of authorities Content-Type: text/plain; charset=utf-8 This script now supports clean removal of authority records that still have linked biblio records. On BZ report 18071, we will extend its functionality to include updating 001 fields, triggering a merge (refresh biblio records), etc. Test plan: [1] Look for one or two authority records with linked biblio records. [2] Pass their authority id's to the script: perl misc/maintenance/update_authorities.pl -authid X,Y -del [3] Verify that authority record is gone and biblio records are clean. Signed-off-by: Marcel de Rooy --- misc/maintenance/update_authorities.pl | 78 ++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 misc/maintenance/update_authorities.pl diff --git a/misc/maintenance/update_authorities.pl b/misc/maintenance/update_authorities.pl new file mode 100644 index 0000000..8029271 --- /dev/null +++ b/misc/maintenance/update_authorities.pl @@ -0,0 +1,78 @@ +#!/usr/bin/perl + +# Copyright Rijksmuseum 2017 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Getopt::Long; +use List::MoreUtils qw/uniq/; +use Pod::Usage; + +use C4::AuthoritiesMarc qw/DelAuthority merge/; + +my ( @authid, $delete, $help, $verbose ); +GetOptions( + 'authid:s' => \@authid, + 'delete' => \$delete, + 'help' => \$help, + 'verbose' => \$verbose, + # TODO Add more options under BZ 18071 +); + +if( $delete ) { + @authid = map { split /[,]/, $_; } @authid; + foreach my $authid ( uniq(@authid) ) { + DelAuthority( $authid ); # triggers a merge (read: cleanup) + print "Removing $authid\n" if $verbose; + } +} elsif( $help ) { + pod2usage(1); +} else { + pod2usage(1); +} + +=head1 NAME + +update_authorities.pl + +=head1 DESCRIPTION + +Script to perform various authority related maintenance tasks. +This version supports deleting an authority record and updating all linked +biblio records. +On BZ report 18071 we will add functions like: updating 001, triggering merge. + +=head1 SYNOPSIS + +update_authorities.pl -authid 1,2,3 -delete + +update_authorities.pl -authid 1 -authid 2 -authid 3 -delete + +=head1 OPTIONS + +authid: List authority numbers separated by commas or repeat the +parameter. + +delete: Delete the listed authority numbers and remove its references from +linked biblio records. + +=head1 AUTHOR + +Marcel de Rooy, Rijksmuseum Amsterdam, The Netherlands + +=cut -- 2.1.4