11 my ( $help, $verbose, $not_borrowered_since, $expired_before, $category_code,
12 $branchcode, $confirm );
15 'v|verbose' => \$verbose,
16 'not_borrowered_since:s' => \$not_borrowered_since,
17 'expired_before:s' => \$expired_before,
18 'category_code:s' => \$category_code,
19 'branchcode:s' => \$branchcode,
20 'c|confirm' => \$confirm,
27 $not_borrowered_since = dt_from_string( $not_borrowered_since, 'iso' )
28 if $not_borrowered_since;
30 $expired_before = dt_from_string( $expired_before, 'iso' )
33 unless ( $not_borrowered_since or $expired_before or $category_code or $branchcode ) {
34 pod2usage(q{At least one filter is mandatory});
38 my $members = GetBorrowersToExpunge(
40 not_borrowered_since => $not_borrowered_since,
41 expired_before => $expired_before,
42 category_code => $category_code,
43 branchcode => $branchcode,
47 say scalar(@$members) . " patrons to delete";
49 my $dbh = C4::Context->dbh;
50 $dbh->{RaiseError} = 1;
51 $dbh->{PrintError} = 0;
53 for my $member (@$members) {
54 print "Trying to delete patron " . $member->{borrowernumber} . "... ";
56 C4::Members::MoveMemberToDeleted( $member->{borrowernumber} )
60 say "Failed, cannot move this patron ($@)";
63 eval { C4::Members::DelMember( $member->{borrowernumber} ) if $confirm; };
65 say "Failed, cannot delete this patron ($@)";
73 delete_patrons - This script deletes patrons
77 delete_patrons.pl [-h -v -c] --not_borrowered_since=2013-07-21 --expired_before=2013-07-21 --category_code=CAT --branchcode=CPL
79 dates can be generated with `date -d '-3 month' "+%Y-%m-%d"`
81 Options are cumulatives.
89 Print a brief help message
91 =item B<--not_borrowered_since>
93 Delete patrons who have not borrowered since this date.
95 =item B<--expired_date>
97 Delete patrons with an account expired before this date.
99 =item B<--category_code>
101 Delete patrons who have this category code.
103 =item B<--branchcode>
105 Delete patrons in this library.
107 =item B<-c|--confirm>
109 Without this flag set, this script will do nothing.
111 =item B<-v|--verbose>
119 Jonathan Druart <jonathan.druart@biblibre.com>
123 Copyright 2013 BibLibre
127 This file is part of Koha.
129 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
130 Foundation; either version 2 of the License, or (at your option) any later version.
132 You should have received a copy of the GNU General Public License along
133 with Koha; if not, write to the Free Software Foundation, Inc.,
134 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.