11 my ( $help, $verbose, $not_borrowered_since, $expired_before, $category_code,
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 'c|confirm' => \$confirm,
26 $not_borrowered_since = dt_from_string( $not_borrowered_since, 'iso' )
27 if $not_borrowered_since;
29 $expired_before = dt_from_string( $expired_before, 'iso' )
32 unless ( $not_borrowered_since or $expired_before or $category_code ) {
33 pod2usage(q{At least one filter is mandatory});
37 my $members = GetBorrowersToExpunge(
39 not_borrowered_since => $not_borrowered_since,
40 expired_before => $expired_before,
41 category_code => $category_code,
45 say scalar(@$members) . " patrons to delete";
47 my $dbh = C4::Context->dbh;
48 $dbh->{RaiseError} = 1;
49 $dbh->{PrintError} = 0;
51 for my $member (@$members) {
52 print "Trying to delete patron " . $member->{borrowernumber} . "... ";
54 C4::Members::MoveMemberToDeleted( $member->{borrowernumber} )
58 say "Failed, cannot move this patron ($@)";
61 eval { C4::Members::DelMember( $member->{borrowernumber} ) if $confirm; };
63 say "Failed, cannot delete this patron ($@)";
71 delete_patrons - This script deletes patrons
75 delete_patrons.pl [-h -v -c] --not_borrowered_since=2013-07-21 --expired_before=2013-07-21 --category_code=CAT
77 dates can be generated with `date -d '-3 month' "+%Y-%m-%d"`
79 Options are cumulatives.
87 Print a brief help message
89 =item B<--not_borrowered_since>
91 Delete patrons who have not borrowered since this date.
93 =item B<--expired_date>
95 Delete patrons with an account expired before this date.
97 =item B<--category_code>
99 Delete patrons who have this category code.
101 =item B<-c|--confirm>
103 Without this flag set, this script will do nothing.
105 =item B<-v|--verbose>
113 Jonathan Druart <jonathan.druart@biblibre.com>
117 Copyright 2013 BibLibre
121 This file is part of Koha.
123 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
124 Foundation; either version 2 of the License, or (at your option) any later version.
126 You should have received a copy of the GNU General Public License along
127 with Koha; if not, write to the Free Software Foundation, Inc.,
128 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.