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

(-)a/C4/Members.pm (+14 lines)
Lines 251-256 sub GetBorrowersToExpunge { Link Here
251
                         ? C4::Context->userenv->{branch}
251
                         ? C4::Context->userenv->{branch}
252
                         : "");
252
                         : "");
253
    my $filterpatronlist = $params->{'patron_list_id'};
253
    my $filterpatronlist = $params->{'patron_list_id'};
254
    my $without_restriction_types = $params->{'without_restriction_types'};
254
255
255
    my $dbh   = C4::Context->dbh;
256
    my $dbh   = C4::Context->dbh;
256
    my $query = q|
257
    my $query = q|
Lines 310-315 sub GetBorrowersToExpunge { Link Here
310
        $query.=" AND ( latestissue < ? OR latestissue IS NULL ) ";
311
        $query.=" AND ( latestissue < ? OR latestissue IS NULL ) ";
311
        push @query_params,$filterdate;
312
        push @query_params,$filterdate;
312
    }
313
    }
314
    if ( ref($without_restriction_types) ne 'ARRAY' ) {
315
        $without_restriction_types = [$without_restriction_types];
316
    }
317
    if ( @$without_restriction_types > 0 ) {
318
        $query .= q|
319
            AND NOT EXISTS (
320
                SELECT 1
321
                FROM borrower_debarments
322
                WHERE borrower_debarments.borrowernumber = xxx.borrowernumber
323
                    AND borrower_debarments.type IN (|
324
            . join( ',', ('?') x @$without_restriction_types ) . "))";
325
        push @query_params, @$without_restriction_types;
326
    }
313
327
314
    if ( my $anonymous_patron = C4::Context->preference("AnonymousPatron") ) {
328
    if ( my $anonymous_patron = C4::Context->preference("AnonymousPatron") ) {
315
        $query .= q{ AND borrowernumber != ? };
329
        $query .= q{ AND borrowernumber != ? };
(-)a/misc/cronjobs/delete_patrons.pl (-17 / +39 lines)
Lines 12-31 use Koha::Patrons; Link Here
12
use C4::Log qw( cronlogaction );
12
use C4::Log qw( cronlogaction );
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, $file, $confirm );
15
    @category_code, $branchcode, $file, @without_restriction_types, $confirm );
16
16
17
my $command_line_options = join(" ",@ARGV);
17
my $command_line_options = join(" ",@ARGV);
18
18
19
GetOptions(
19
GetOptions(
20
    'h|help'                 => \$help,
20
    'h|help'                     => \$help,
21
    'v|verbose'              => \$verbose,
21
    'v|verbose'                  => \$verbose,
22
    'not_borrowed_since:s'   => \$not_borrowed_since,
22
    'not_borrowed_since:s'       => \$not_borrowed_since,
23
    'expired_before:s'       => \$expired_before,
23
    'expired_before:s'           => \$expired_before,
24
    'last_seen:s'            => \$last_seen,
24
    'last_seen:s'                => \$last_seen,
25
    'category_code:s'        => \@category_code,
25
    'category_code:s'            => \@category_code,
26
    'library:s'              => \$branchcode,
26
    'library:s'                  => \$branchcode,
27
    'file:s'                 => \$file,
27
    'file:s'                     => \$file,
28
    'c|confirm'              => \$confirm,
28
    'without_restriction_type:s' => \@without_restriction_types,
29
    'c|confirm'                  => \$confirm,
29
) || pod2usage(1);
30
) || pod2usage(1);
30
31
31
if ($help) {
32
if ($help) {
Lines 46-51 unless ( $not_borrowed_since or $expired_before or $last_seen or @category_code Link Here
46
    pod2usage(q{At least one filter is mandatory});
47
    pod2usage(q{At least one filter is mandatory});
47
}
48
}
48
49
50
if ( @without_restriction_types > 0 ) {
51
    my %restriction_types;
52
    @restriction_types{ map { $_->code() } Koha::Patron::Restriction::Types->search()->as_list } = ();
53
54
    my @invalid_restriction_types;
55
    foreach my $restriction_type (@without_restriction_types) {
56
        if ( !exists $restriction_types{$restriction_type} ) {
57
            push @invalid_restriction_types, $restriction_type;
58
        }
59
    }
60
    if ( @invalid_restriction_types > 0 ) {
61
        die 'Invalid restriction type(s): ' . join ', ', @invalid_restriction_types;
62
    }
63
}
64
49
cronlogaction({ info => $command_line_options });
65
cronlogaction({ info => $command_line_options });
50
66
51
my @file_members;
67
my @file_members;
Lines 64-74 my $members; Link Here
64
if ( $not_borrowed_since or $expired_before or $last_seen or @category_code or $branchcode ) {
80
if ( $not_borrowed_since or $expired_before or $last_seen or @category_code or $branchcode ) {
65
    $members = GetBorrowersToExpunge(
81
    $members = GetBorrowersToExpunge(
66
        {
82
        {
67
            not_borrowed_since   => $not_borrowed_since,
83
            not_borrowed_since        => $not_borrowed_since,
68
            expired_before       => $expired_before,
84
            expired_before            => $expired_before,
69
            last_seen            => $last_seen,
85
            last_seen                 => $last_seen,
70
            category_code        => \@category_code,
86
            category_code             => \@category_code,
71
            branchcode           => $branchcode,
87
            branchcode                => $branchcode,
88
            without_restriction_types => \@without_restriction_types
72
        }
89
        }
73
    );
90
    );
74
}
91
}
Lines 149-155 delete_patrons - This script deletes patrons Link Here
149
166
150
=head1 SYNOPSIS
167
=head1 SYNOPSIS
151
168
152
delete_patrons.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--not_borrowed_since=DATE] [--expired_before=DATE] [--last-seen=DATE] [--category_code=CAT] [--category_code=CAT ...] [--library=LIBRARY] [--file=FILE]
169
delete_patrons.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--not_borrowed_since=DATE] [--expired_before=DATE] [--last-seen=DATE] [--category_code=CAT] [--category_code=CAT ...] [--library=LIBRARY] [--file=FILE] [--without_restriction_type=TYPE] [--without_restriction_type=TYPE ...]
153
170
154
Dates should be in ISO format, e.g., 2013-07-19, and can be generated
171
Dates should be in ISO format, e.g., 2013-07-19, and can be generated
155
with `date -d '-3 month' --iso-8601`.
172
with `date -d '-3 month' --iso-8601`.
Lines 202-207 Delete patrons in this library. Link Here
202
Delete patrons whose borrower numbers are in this file.  If other criteria are defined
219
Delete patrons whose borrower numbers are in this file.  If other criteria are defined
203
it will only delete those in the file that match those criteria.
220
it will only delete those in the file that match those criteria.
204
221
222
=item B<--without_restriction_type>
223
224
Delete patrons who DO NOT have a debarment with this restriction type.
225
226
Can be used multiple times for additional restriction types.
227
205
=item B<-c|--confirm>
228
=item B<-c|--confirm>
206
229
207
This flag must be provided in order for the script to actually
230
This flag must be provided in order for the script to actually
208
- 

Return to bug 37418