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

(-)a/misc/cronjobs/delete_patrons.pl (-1 / +125 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Pod::Usage;
6
use Getopt::Long;
7
8
use C4::Members;
9
use Koha::DateUtils;
10
11
my ( $help, $verbose, $not_borrowered_since, $expired_before, $category_code,
12
    $dryrun );
13
GetOptions(
14
    'h|help'                 => \$help,
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
    'dry-run'                => \$dryrun,
20
) || pod2usage(1);
21
22
if ($help) {
23
    pod2usage(1);
24
}
25
26
$not_borrowered_since = dt_from_string( $not_borrowered_since, 'iso' )
27
  if $not_borrowered_since;
28
29
$expired_before = dt_from_string( $expired_before, 'iso' )
30
  if $expired_before;
31
32
unless ( $not_borrowered_since or $expired_before or $category_code ) {
33
    pod2usage(q{At least one filter is mandatory});
34
    exit;
35
}
36
37
my $members = GetBorrowersToExpunge(
38
    {
39
        not_borrowered_since => $not_borrowered_since,
40
        expired_before       => $expired_before,
41
        category_code        => $category_code,
42
    }
43
);
44
45
say "I found " . scalar(@$members) . " patrons to delete";
46
for my $member (@$members) {
47
    print "Trying delete patron " . $member->{borrowernumber} . "... ";
48
    eval {
49
        C4::Members::MoveMemberToDeleted( $member->{borrowernumber} )
50
          unless $dryrun;
51
    };
52
    unless ($@) {
53
        eval {
54
            C4::Members::DelMember( $member->{borrowernumber} )
55
              unless $dryrun;
56
        };
57
        unless ($@) {
58
            say "OK";
59
            next;
60
        }
61
        say "Failed, I cannot delete this patron ($@)";
62
    }
63
    say "Failed, I cannot move this patron ($@)";
64
}
65
66
=head1 NAME
67
68
delete_patrons - This script deletes patrons
69
70
=head1 SYNOPSIS
71
72
delete_patrons.pl [-h -v] --not_borrowered_since=`date -d '-3 month' "+%Y-%m-%d"` --expired_before=`date -d '-3 month' "+%Y-%m-%d"` --category_code=CAT
73
74
Options are cumulatives.
75
76
=head1 OPTIONS
77
78
=over
79
80
=item B<-h|--help>
81
82
Print a brief help message
83
84
=item B<--not_borrowered_since>
85
86
Delete patrons who have not borrowered since this date.
87
88
=item B<--expired_date>
89
90
Delete patrons with an account expired before this date.
91
92
=item B<--category_code>
93
94
Delete patrons who have this category code.
95
96
=item B<--dry-run>
97
98
Dry run mode. To use with the verbose mode.
99
100
=item B<-v|--verbose>
101
102
Verbose mode.
103
104
=back
105
106
=head1 AUTHOR
107
108
Jonathan Druart <jonathan.druart@biblibre.com>
109
110
=head1 COPYRIGHT
111
112
Copyright 2013 BibLibre
113
114
=head1 LICENSE
115
116
This file is part of Koha.
117
118
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
119
Foundation; either version 2 of the License, or (at your option) any later version.
120
121
You should have received a copy of the GNU General Public License along
122
with Koha; if not, write to the Free Software Foundation, Inc.,
123
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
124
125
=cut

Return to bug 10419