|
Lines 12-18
use Koha::Patrons;
Link Here
|
| 12 |
use C4::Log; |
12 |
use C4::Log; |
| 13 |
|
13 |
|
| 14 |
my ( $help, $verbose, $not_borrowed_since, $expired_before, $last_seen, |
14 |
my ( $help, $verbose, $not_borrowed_since, $expired_before, $last_seen, |
| 15 |
$category_code, $branchcode, $confirm ); |
15 |
$category_code, $branchcode, $file, $confirm ); |
| 16 |
GetOptions( |
16 |
GetOptions( |
| 17 |
'h|help' => \$help, |
17 |
'h|help' => \$help, |
| 18 |
'v|verbose' => \$verbose, |
18 |
'v|verbose' => \$verbose, |
|
Lines 21-26
GetOptions(
Link Here
|
| 21 |
'last_seen:s' => \$last_seen, |
21 |
'last_seen:s' => \$last_seen, |
| 22 |
'category_code:s' => \$category_code, |
22 |
'category_code:s' => \$category_code, |
| 23 |
'library:s' => \$branchcode, |
23 |
'library:s' => \$branchcode, |
|
|
24 |
'file:s' => \$file, |
| 24 |
'c|confirm' => \$confirm, |
25 |
'c|confirm' => \$confirm, |
| 25 |
) || pod2usage(1); |
26 |
) || pod2usage(1); |
| 26 |
|
27 |
|
|
Lines 38-58
if ( $last_seen and not C4::Context->preference('TrackLastPatronActivity') ) {
Link Here
|
| 38 |
pod2usage(q{The --last_seen option cannot be used with TrackLastPatronActivity turned off}); |
39 |
pod2usage(q{The --last_seen option cannot be used with TrackLastPatronActivity turned off}); |
| 39 |
} |
40 |
} |
| 40 |
|
41 |
|
| 41 |
unless ( $not_borrowed_since or $expired_before or $last_seen or $category_code or $branchcode ) { |
42 |
unless ( $not_borrowed_since or $expired_before or $last_seen or $category_code or $branchcode or $file ) { |
| 42 |
pod2usage(q{At least one filter is mandatory}); |
43 |
pod2usage(q{At least one filter is mandatory}); |
| 43 |
} |
44 |
} |
| 44 |
|
45 |
|
| 45 |
cronlogaction(); |
46 |
cronlogaction(); |
| 46 |
|
47 |
|
| 47 |
my $members = GetBorrowersToExpunge( |
48 |
my @file_members; |
| 48 |
{ |
49 |
if ($file) { |
| 49 |
not_borrowed_since => $not_borrowed_since, |
50 |
open(my $fh, '<:encoding(UTF-8)', $file) or die "Could not open file $file' $!"; |
| 50 |
expired_before => $expired_before, |
51 |
while (my $line = <$fh>) { |
| 51 |
last_seen => $last_seen, |
52 |
chomp($line); |
| 52 |
category_code => $category_code, |
53 |
my %fm = ('borrowernumber' => $line); |
| 53 |
branchcode => $branchcode, |
54 |
my $fm_ref = \%fm; |
|
|
55 |
push @file_members, $fm_ref; |
| 54 |
} |
56 |
} |
| 55 |
); |
57 |
close $fh; |
|
|
58 |
} |
| 59 |
|
| 60 |
my $members; |
| 61 |
if ( $not_borrowed_since or $expired_before or $last_seen or $category_code or $branchcode ) { |
| 62 |
$members = GetBorrowersToExpunge( |
| 63 |
{ |
| 64 |
not_borrowed_since => $not_borrowed_since, |
| 65 |
expired_before => $expired_before, |
| 66 |
last_seen => $last_seen, |
| 67 |
category_code => $category_code, |
| 68 |
branchcode => $branchcode, |
| 69 |
} |
| 70 |
); |
| 71 |
} |
| 72 |
|
| 73 |
if ($members and @file_members) { |
| 74 |
my @filtered_members; |
| 75 |
for my $member (@$members) { |
| 76 |
for my $fm (@file_members) { |
| 77 |
if ($member->{borrowernumber} eq $fm->{borrowernumber}) { |
| 78 |
push @filtered_members, $fm; |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
$members = \@filtered_members; |
| 83 |
} |
| 84 |
|
| 85 |
if (!defined $members and @file_members) { |
| 86 |
$members = \@file_members; |
| 87 |
} |
| 56 |
|
88 |
|
| 57 |
unless ($confirm) { |
89 |
unless ($confirm) { |
| 58 |
say "Doing a dry run; no patron records will actually be deleted."; |
90 |
say "Doing a dry run; no patron records will actually be deleted."; |
|
Lines 102-108
delete_patrons - This script deletes patrons
Link Here
|
| 102 |
|
134 |
|
| 103 |
=head1 SYNOPSIS |
135 |
=head1 SYNOPSIS |
| 104 |
|
136 |
|
| 105 |
delete_patrons.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--not_borrowed_since=DATE] [--expired_before=DATE] [--last-seen=DATE] [--category_code=CAT] [--library=LIBRARY] |
137 |
delete_patrons.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--not_borrowed_since=DATE] [--expired_before=DATE] [--last-seen=DATE] [--category_code=CAT] [--library=LIBRARY] [--file=FILE] |
| 106 |
|
138 |
|
| 107 |
Dates should be in ISO format, e.g., 2013-07-19, and can be generated |
139 |
Dates should be in ISO format, e.g., 2013-07-19, and can be generated |
| 108 |
with `date -d '-3 month' --iso-8601`. |
140 |
with `date -d '-3 month' --iso-8601`. |
|
Lines 141-146
Delete patrons who have this category code.
Link Here
|
| 141 |
|
173 |
|
| 142 |
Delete patrons in this library. |
174 |
Delete patrons in this library. |
| 143 |
|
175 |
|
|
|
176 |
=item B<--file> |
| 177 |
|
| 178 |
Delete patrons whose borrower numbers are in this file. If other criteria are defined |
| 179 |
it will only delete those in the file that match those criteria. |
| 180 |
|
| 144 |
=item B<-c|--confirm> |
181 |
=item B<-c|--confirm> |
| 145 |
|
182 |
|
| 146 |
This flag must be provided in order for the script to actually |
183 |
This flag must be provided in order for the script to actually |
| 147 |
- |
|
|