View | Details | Raw Unified | Return to bug 7901
Collapse All | Expand All

(-)a/misc/batch_delete_borrowers.pl (-1 / +91 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2012 Bywater Solutions
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with this program; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
BEGIN {
23
24
    # find Koha's Perl modules
25
    # test carefully before changing this
26
    use FindBin;
27
    eval { require "$FindBin::Bin/kohalib.pl" };
28
}
29
30
use C4::Members;
31
use C4::VirtualShelves;
32
33
use Getopt::Long;
34
35
my ( $help, $confirm, $file, $verbose, $delete );
36
GetOptions(
37
    'c|confirm' => \$confirm,
38
    'h|help'    => \$help,
39
    'v|verbose' => \$verbose,
40
    'd|delete'  => \$delete,
41
    'f|file:s'  => \$file,
42
);
43
44
if ($help) {
45
    print <<EOF
46
This script is used to batch delete borrowers from Koha.
47
It accepts a file with a list of borrower cardnumbers to
48
be deleted, one per line.
49
50
Example: batch_delete_borrowers.pl -c -v --file borrowers.list
51
52
Options:
53
  --confirm -c If this option is not passed, nothing will be deleted
54
55
  --verbose -v Verbose, print output
56
57
  --help -h    Display help
58
59
  --delete -d  Delete the borrower completely, rather than moving
60
               the borrower to the deletedborrowers table
61
62
  --file -f    File of borrower cardnumbers to be deleted
63
EOF
64
      ;
65
    exit;
66
}
67
68
print "\nRunning in test mode, no borrowers will be deleted\n\n"
69
  unless ($confirm);
70
71
open( FILE, $file ) or die "Couldn't open file: $!";
72
while (<FILE>) {
73
    chomp($_);
74
75
    print "Working on cardnumber $_ \n" if ($verbose);
76
77
    my $borrower = GetMember( cardnumber => $_ );
78
    my $borrowernumber = $borrower->{'borrowernumber'};
79
80
    print "Deleting borrower $borrower->{firstname} $borrower->{surname} ( $borrower->{cardnumber} ) ... " if ($verbose);
81
82
    if ($confirm) {
83
        MoveMemberToDeleted($borrowernumber) unless ($delete);
84
        C4::VirtualShelves::HandleDelBorrower($borrowernumber);
85
        DelMember($borrowernumber);
86
87
    }
88
89
    print "deleted.\n\n" if ($verbose);
90
91
}

Return to bug 7901