From 24483f82f60c98d0df4b435e663ea6490e8eb2c1 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 5 Apr 2012 08:59:14 -0400 Subject: [PATCH] Bug 7901 - Add batch delete borrowers script Simple script that takes a file of borrower cardnumbers and deletes those borrowers. --- misc/batch_delete_borrowers.pl | 91 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 91 insertions(+), 0 deletions(-) create mode 100755 misc/batch_delete_borrowers.pl diff --git a/misc/batch_delete_borrowers.pl b/misc/batch_delete_borrowers.pl new file mode 100755 index 0000000..33653b7 --- /dev/null +++ b/misc/batch_delete_borrowers.pl @@ -0,0 +1,91 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Copyright 2012 Bywater Solutions +# +# 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 this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +BEGIN { + + # find Koha's Perl modules + # test carefully before changing this + use FindBin; + eval { require "$FindBin::Bin/kohalib.pl" }; +} + +use C4::Members; +use C4::VirtualShelves; + +use Getopt::Long; + +my ( $help, $confirm, $file, $verbose, $delete ); +GetOptions( + 'c|confirm' => \$confirm, + 'h|help' => \$help, + 'v|verbose' => \$verbose, + 'd|delete' => \$delete, + 'f|file:s' => \$file, +); + +if ($help) { + print <) { + chomp($_); + + print "Working on cardnumber $_ \n" if ($verbose); + + my $borrower = GetMember( cardnumber => $_ ); + my $borrowernumber = $borrower->{'borrowernumber'}; + + print "Deleting borrower $borrower->{firstname} $borrower->{surname} ( $borrower->{cardnumber} ) ... " if ($verbose); + + if ($confirm) { + MoveMemberToDeleted($borrowernumber) unless ($delete); + C4::VirtualShelves::HandleDelBorrower($borrowernumber); + DelMember($borrowernumber); + + } + + print "deleted.\n\n" if ($verbose); + +} -- 1.7.2.5