From c34933672576eae6b10665aab8b756dd529a7b69 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 23 Aug 2012 14:28:42 +0200 Subject: [PATCH] Bug 8674: Adds script batchdeletebiblios This script batch deletes biblios which contain a biblionumber present in file passed in parameter. If one biblio has items, it is not deleted. http://bugs.koha-community.org/show_bug.cgi?id=8674 Signed-off-by: Kyle M Hall Created file with biblionumbers for bibs with and without items. Only the bibs without items were deleted. --- misc/batchdeletebiblios.pl | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 misc/batchdeletebiblios.pl diff --git a/misc/batchdeletebiblios.pl b/misc/batchdeletebiblios.pl new file mode 100755 index 0000000000..52170f6373 --- /dev/null +++ b/misc/batchdeletebiblios.pl @@ -0,0 +1,52 @@ +#!/usr/bin/perl + +# Copyright 2012 BibLibre +# 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 2 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., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA + +=head1 batchdeletebiblios.pl + + This script batch deletes biblios which contain a biblionumber present in file passed in parameter. + If one biblio has items, it is not deleted. + +=cut + +use Modern::Perl; +use C4::Biblio; + +use IO::File; + +for my $file ( @ARGV ) { + say "Find biblionumber in file $file"; + open(FD, $file) or say "Error: '$file' $!" and next; + + while ( ) { + my $biblionumber = $_; + $biblionumber =~ s/$1/\n/g if $biblionumber =~ m/(\r\n?|\n\r?)/; + chomp $biblionumber; + my $dbh = C4::Context->dbh; + next if not $biblionumber =~ /^\d*$/; + print "Delete biblionumber $biblionumber "; + my $error; + eval { + $error = DelBiblio $biblionumber; + }; + if ( $@ or $error) { + say "KO $@ ($! | $error)"; + } else { + say "OK"; + } + } +} -- 2.39.5