From 250f8232dd051a65fa66e8d51ae3fd4de8190ea4 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Fri, 13 Apr 2018 02:24:08 +0000 Subject: [PATCH] WR: 289187 - Script to loop through catalog removing 998 tag data https://bugs.koha-community.org/show_bug.cgi?id=20577 --- remove_998_datafield.pl | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 remove_998_datafield.pl diff --git a/remove_998_datafield.pl b/remove_998_datafield.pl new file mode 100755 index 0000000..11745bb --- /dev/null +++ b/remove_998_datafield.pl @@ -0,0 +1,70 @@ +#!/usr/bin/perl + +# Loop through all of the biblio records in the biblioitems database table and remove the 998 subfield to prevent indexer bugs. +# +# Copyright (C) 2018 Catalyst IT Ltd. +# +# This program 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. +# +# This program 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 this program. If not, see . + +=head1 NAME + +remove_998_subfield.pl - Remove 998$a subfield of all biblios in the catalog + +=head1 SYNOPSIS + +B + +=head1 DESCRIPTION + +B will loop through all of the biblio records in the biblioitems database table and remove the 998 subfield to prevent indexer bugs. + +=back + +=head1 AUTHOR + +Alex Buckley + +=cut + +use Data::Dumper; + +use autodie; +use Getopt::Long; +use Modern::Perl; +use Pod::Usage; +use Text::CSV_XS; +use C4::Context; +use C4::Biblio; + +my $dbh = C4::Context->dbh; + +my $sth = $dbh->prepare("SELECT biblionumber FROM biblioitem WHERE ExtractValue(marcxml, '//datafield[\@tag=\"440\"]/subfield[\@code>=\"a\"]') != '';"); +$sth->execute(); +my $biblio_records = $sth->fetchall_arrayref({ }); + +foreach my $biblio_record ( @$biblio_records ) { + my $bibnum = $biblio_record->{'biblionumber'}; + my $record = GetMarcBiblio({biblionumber => $bibnum}); + my $framework = $record->{'framework'}; + foreach my $field ($record->field('998')) { + $record->delete_field($field); + } + ModBiblioMarc($record, $bibnum, $framework); + ModZebra( $biblio_record, "specialUpdate", "biblioserver", $record); + warn "Updated biblio $biblio_record->{'biblionumber'}"; +} + +1; + + -- 2.1.4