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

(-)a/misc/cronjobs/longoverdue.pl (-41 / +20 lines)
Lines 251-301 sub longoverdue_sth { Link Here
251
    return C4::Context->dbh->prepare($query);
251
    return C4::Context->dbh->prepare($query);
252
}
252
}
253
253
254
sub check_user_categories {
254
my $dbh = C4::Context->dbh;
255
255
my @available_categories = map { uc $_->[0] } @{ $dbh->selectall_arrayref(q|SELECT categorycode FROM categories|) };
256
    my $categories      = shift;
256
my %category_to_process;
257
    my $test_categories = shift;
257
for my $cat ( @$borrower_category ) {
258
    my $category_label  = shift;
258
    unless ( grep { /^$cat$/ } @available_categories ) {
259
    my %good            = map { $_ => 1 } @$categories;
259
        pod2usage(
260
    my @bad_categories  = grep { ! $good{ uc $_ } } @$test_categories;
260
            '-exitval' => 1,
261
261
            '-message' => "The category $cat does not exist in the database",
262
    if ( scalar @bad_categories ) {
262
        );
263
        my $error = "$category_label: category/categories '"
264
                    . join( ' ',  @bad_categories )
265
                    . "' not in the available borrower cateogories: [ "
266
                    . join( ' ', @$categories )
267
                    . " ]";
268
        pod2usage(  '-verbose' => 1
269
                  , '-exitval' => 1
270
                  , '-message' => $error
271
                 );
272
    }
263
    }
264
    $category_to_process{$cat} = 1;
273
}
265
}
274
266
if ( @$skip_borrower_category ) {
275
# returns a hash of borrower category codes to test for long-overdue-ness.
267
    for my $cat ( @$skip_borrower_category ) {
276
# The key is the borrower category, upper case. The value is 1. This
268
        unless ( grep { /^$cat$/ } @available_categories ) {
277
# will make a fast look-up of valid borrower category codes.
269
            pod2usage(
278
sub get_borrower_categories {
270
                '-exitval' => 1,
279
    my ( $borrower_category, $skip_borrower_category ) = ( @_ );
271
                '-message' => "The category $cat does not exist in the database",
280
272
            );
281
    return () unless ( scalar @$borrower_category || scalar @$skip_borrower_category );
273
        }
282
283
    my $dbh = C4::Context->dbh;
284
    my @categories = map { uc $_->[0] } @{ $dbh->selectall_arrayref(q|SELECT categorycode FROM categories|) };
285
    if( @$borrower_category ) {
286
        check_user_categories( \@categories, $borrower_category, "--category" );
287
        my %borcat  = map { ( uc($_) => 1 ) } @$borrower_category;
288
        @categories = grep { $borcat{$_} } @categories;
289
    }
290
    if( @$skip_borrower_category ) {
291
        check_user_categories( \@categories, $skip_borrower_category, "--skip-category" );
292
        my %skip_borcat  = map { ( uc($_) => 1 ) } @$skip_borrower_category;
293
        @categories = grep { ! $skip_borcat{$_} } @categories;
294
    }
274
    }
295
    return map { $_ => 1 } @categories;
275
    %category_to_process = map { $_ => 1 } @available_categories;
276
    %category_to_process = ( %category_to_process, map { $_ => 0 } @$skip_borrower_category );
296
}
277
}
297
278
298
my %category_to_process = get_borrower_categories( $borrower_category, $skip_borrower_category );
299
my $filter_borrower_categories = ( scalar @$borrower_category || scalar @$skip_borrower_category );
279
my $filter_borrower_categories = ( scalar @$borrower_category || scalar @$skip_borrower_category );
300
280
301
my $count;
281
my $count;
302
- 

Return to bug 14292