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

(-)a/C4/Members.pm (-3 / +6 lines)
Lines 362-368 sub get_cardnumber_length { Link Here
362
  $borrowers = &GetBorrowersToExpunge(
362
  $borrowers = &GetBorrowersToExpunge(
363
      not_borrowed_since => $not_borrowed_since,
363
      not_borrowed_since => $not_borrowed_since,
364
      expired_before       => $expired_before,
364
      expired_before       => $expired_before,
365
      category_code        => $category_code,
365
      category_code        => \@category_code,
366
      patron_list_id       => $patron_list_id,
366
      patron_list_id       => $patron_list_id,
367
      branchcode           => $branchcode
367
      branchcode           => $branchcode
368
  );
368
  );
Lines 424-431 sub GetBorrowersToExpunge { Link Here
424
        push @query_params, $filterlastseen;
424
        push @query_params, $filterlastseen;
425
    }
425
    }
426
    if ( $filtercategory ) {
426
    if ( $filtercategory ) {
427
        $query .= " AND categorycode = ? ";
427
        if (ref($filtercategory) ne 'ARRAY' ) {
428
        push( @query_params, $filtercategory );
428
            $filtercategory = [ $filtercategory ];
429
        }
430
        $query .= " AND categorycode IN (" . join(',', ('?') x @$filtercategory) . ") ";
431
        push( @query_params, @$filtercategory );
429
    }
432
    }
430
    if ( $filterpatronlist ){
433
    if ( $filterpatronlist ){
431
        $query.=" AND patron_list_id = ? ";
434
        $query.=" AND patron_list_id = ? ";
(-)a/misc/cronjobs/delete_patrons.pl (-6 / +9 lines)
Lines 12-25 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, $file, $confirm );
15
    @category_code, $branchcode, $file, $confirm );
16
16
GetOptions(
17
GetOptions(
17
    'h|help'                 => \$help,
18
    'h|help'                 => \$help,
18
    'v|verbose'              => \$verbose,
19
    'v|verbose'              => \$verbose,
19
    'not_borrowed_since:s'   => \$not_borrowed_since,
20
    'not_borrowed_since:s'   => \$not_borrowed_since,
20
    'expired_before:s'       => \$expired_before,
21
    'expired_before:s'       => \$expired_before,
21
    'last_seen:s'            => \$last_seen,
22
    'last_seen:s'            => \$last_seen,
22
    'category_code:s'        => \$category_code,
23
    'category_code:s'        => \@category_code,
23
    'library:s'              => \$branchcode,
24
    'library:s'              => \$branchcode,
24
    'file:s'                 => \$file,
25
    'file:s'                 => \$file,
25
    'c|confirm'              => \$confirm,
26
    'c|confirm'              => \$confirm,
Lines 39-45 if ( $last_seen and not C4::Context->preference('TrackLastPatronActivity') ) { Link Here
39
    pod2usage(q{The --last_seen option cannot be used with TrackLastPatronActivity turned off});
40
    pod2usage(q{The --last_seen option cannot be used with TrackLastPatronActivity turned off});
40
}
41
}
41
42
42
unless ( $not_borrowed_since or $expired_before or $last_seen or $category_code or $branchcode or $file ) {
43
unless ( $not_borrowed_since or $expired_before or $last_seen or @category_code or $branchcode or $file ) {
43
    pod2usage(q{At least one filter is mandatory});
44
    pod2usage(q{At least one filter is mandatory});
44
}
45
}
45
46
Lines 58-70 if ($file) { Link Here
58
}
59
}
59
60
60
my $members;
61
my $members;
61
if ( $not_borrowed_since or $expired_before or $last_seen or $category_code or $branchcode ) {
62
if ( $not_borrowed_since or $expired_before or $last_seen or @category_code or $branchcode ) {
62
    $members = GetBorrowersToExpunge(
63
    $members = GetBorrowersToExpunge(
63
        {
64
        {
64
            not_borrowed_since   => $not_borrowed_since,
65
            not_borrowed_since   => $not_borrowed_since,
65
            expired_before       => $expired_before,
66
            expired_before       => $expired_before,
66
            last_seen            => $last_seen,
67
            last_seen            => $last_seen,
67
            category_code        => $category_code,
68
            category_code        => \@category_code,
68
            branchcode           => $branchcode,
69
            branchcode           => $branchcode,
69
        }
70
        }
70
    );
71
    );
Lines 143-149 delete_patrons - This script deletes patrons Link Here
143
144
144
=head1 SYNOPSIS
145
=head1 SYNOPSIS
145
146
146
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]
147
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]
147
148
148
Dates should be in ISO format, e.g., 2013-07-19, and can be generated
149
Dates should be in ISO format, e.g., 2013-07-19, and can be generated
149
with `date -d '-3 month' --iso-8601`.
150
with `date -d '-3 month' --iso-8601`.
Lines 178-183 The system preference TrackLastPatronActivity must be enabled to use this option Link Here
178
179
179
Delete patrons who have this category code.
180
Delete patrons who have this category code.
180
181
182
Can be used multiple times for additional category codes.
183
181
=item B<--library>
184
=item B<--library>
182
185
183
Delete patrons in this library.
186
Delete patrons in this library.
(-)a/t/db_dependent/Members.t (-2 / +5 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 48;
20
use Test::More tests => 50;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Exception;
22
use Test::Exception;
23
23
Lines 300-305 $patstodel = GetBorrowersToExpunge( {branchcode => $library3->{branchcode},patro Link Here
300
is( scalar(@$patstodel),1,'Borrower with issue not deleted by branchcode and list');
300
is( scalar(@$patstodel),1,'Borrower with issue not deleted by branchcode and list');
301
$patstodel = GetBorrowersToExpunge( {category_code => 'CIVILIAN',patron_list_id => $list1->patron_list_id() } );
301
$patstodel = GetBorrowersToExpunge( {category_code => 'CIVILIAN',patron_list_id => $list1->patron_list_id() } );
302
is( scalar(@$patstodel),1,'Borrower with issue not deleted by category_code and list');
302
is( scalar(@$patstodel),1,'Borrower with issue not deleted by category_code and list');
303
$patstodel = GetBorrowersToExpunge( {category_code => ['CIVILIAN','STAFFER'],patron_list_id => $list1->patron_list_id() } );
304
is( scalar(@$patstodel),1,'Borrower with issue not deleted by multiple category_code and list');
303
$patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02',patron_list_id => $list1->patron_list_id() } );
305
$patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02',patron_list_id => $list1->patron_list_id() } );
304
is( scalar(@$patstodel),1,'Borrower with issue not deleted by expiration_date and list');
306
is( scalar(@$patstodel),1,'Borrower with issue not deleted by expiration_date and list');
305
$builder->schema->resultset( 'Issue' )->delete_all;
307
$builder->schema->resultset( 'Issue' )->delete_all;
Lines 307-312 $patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} Link Here
307
ok( scalar(@$patstodel)== 2,'Borrowers without issue deleted from list');
309
ok( scalar(@$patstodel)== 2,'Borrowers without issue deleted from list');
308
$patstodel = GetBorrowersToExpunge( {category_code => 'CIVILIAN',patron_list_id => $list1->patron_list_id() } );
310
$patstodel = GetBorrowersToExpunge( {category_code => 'CIVILIAN',patron_list_id => $list1->patron_list_id() } );
309
is( scalar(@$patstodel),2,'Borrowers without issues deleted by category_code and list');
311
is( scalar(@$patstodel),2,'Borrowers without issues deleted by category_code and list');
312
$patstodel = GetBorrowersToExpunge( {category_code => ['CIVILIAN','STAFFER'],patron_list_id => $list1->patron_list_id() } );
313
is( scalar(@$patstodel),2,'Borrowers without issues deleted by multiple category_code and list');
310
$patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02',patron_list_id => $list1->patron_list_id() } );
314
$patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02',patron_list_id => $list1->patron_list_id() } );
311
is( scalar(@$patstodel),2,'Borrowers without issues deleted by expiration_date and list');
315
is( scalar(@$patstodel),2,'Borrowers without issues deleted by expiration_date and list');
312
$patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
316
$patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
313
- 

Return to bug 27050