Bugzilla – Attachment 43337 Details for
Bug 14292
Add --category and --skip-category options to longoverdue.pl to include or exclude borrower categories.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14292: Simplify the category list
Bug-14292-Simplify-the-category-list.patch (text/plain), 3.86 KB, created by
Jonathan Druart
on 2015-10-12 10:41:01 UTC
(
hide
)
Description:
Bug 14292: Simplify the category list
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2015-10-12 10:41:01 UTC
Size:
3.86 KB
patch
obsolete
>From 4e51b0ce17bc2106fe3159d7776d7a3fe9b610a8 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 12 Oct 2015 11:36:31 +0100 >Subject: [PATCH] Bug 14292: Simplify the category list > >Basically we have 3 lists of categories: >1/ The full one, in the DB >2/ The one we want and list with --category >3/ The one we don't want and list with --skip-category > >The list of categories to process is: > * 1 if none --category or --skip-category options are provided > * 2 if --category is provided > * 1 - 3 if --skip-category is provided >--- > misc/cronjobs/longoverdue.pl | 60 +++++++++++++++----------------------------- > 1 file changed, 20 insertions(+), 40 deletions(-) > >diff --git a/misc/cronjobs/longoverdue.pl b/misc/cronjobs/longoverdue.pl >index aa9fc13..6c8b41e 100755 >--- a/misc/cronjobs/longoverdue.pl >+++ b/misc/cronjobs/longoverdue.pl >@@ -251,51 +251,31 @@ sub longoverdue_sth { > return C4::Context->dbh->prepare($query); > } > >-sub check_user_categories { >- >- my $categories = shift; >- my $test_categories = shift; >- my $category_label = shift; >- my %good = map { $_ => 1 } @$categories; >- my @bad_categories = grep { ! $good{ uc $_ } } @$test_categories; >- >- if ( scalar @bad_categories ) { >- my $error = "$category_label: category/categories '" >- . join( ' ', @bad_categories ) >- . "' not in the available borrower cateogories: [ " >- . join( ' ', @$categories ) >- . " ]"; >- pod2usage( '-verbose' => 1 >- , '-exitval' => 1 >- , '-message' => $error >- ); >+my $dbh = C4::Context->dbh; >+my @available_categories = map { uc $_->[0] } @{ $dbh->selectall_arrayref(q|SELECT categorycode FROM categories|) }; >+my %category_to_process; >+for my $cat ( @$borrower_category ) { >+ unless ( grep { /^$cat$/ } @available_categories ) { >+ pod2usage( >+ '-exitval' => 1, >+ '-message' => "The category $cat does not exist in the database", >+ ); > } >+ $category_to_process{$cat} = 1; > } >- >-# returns a hash of borrower category codes to test for long-overdue-ness. >-# The key is the borrower category, upper case. The value is 1. This >-# will make a fast look-up of valid borrower category codes. >-sub get_borrower_categories { >- my ( $borrower_category, $skip_borrower_category ) = ( @_ ); >- >- return () unless ( scalar @$borrower_category || scalar @$skip_borrower_category ); >- >- my $dbh = C4::Context->dbh; >- my @categories = map { uc $_->[0] } @{ $dbh->selectall_arrayref(q|SELECT categorycode FROM categories|) }; >- if( @$borrower_category ) { >- check_user_categories( \@categories, $borrower_category, "--category" ); >- my %borcat = map { ( uc($_) => 1 ) } @$borrower_category; >- @categories = grep { $borcat{$_} } @categories; >- } >- if( @$skip_borrower_category ) { >- check_user_categories( \@categories, $skip_borrower_category, "--skip-category" ); >- my %skip_borcat = map { ( uc($_) => 1 ) } @$skip_borrower_category; >- @categories = grep { ! $skip_borcat{$_} } @categories; >+if ( @$skip_borrower_category ) { >+ for my $cat ( @$skip_borrower_category ) { >+ unless ( grep { /^$cat$/ } @available_categories ) { >+ pod2usage( >+ '-exitval' => 1, >+ '-message' => "The category $cat does not exist in the database", >+ ); >+ } > } >- return map { $_ => 1 } @categories; >+ %category_to_process = map { $_ => 1 } @available_categories; >+ %category_to_process = ( %category_to_process, map { $_ => 0 } @$skip_borrower_category ); > } > >-my %category_to_process = get_borrower_categories( $borrower_category, $skip_borrower_category ); > my $filter_borrower_categories = ( scalar @$borrower_category || scalar @$skip_borrower_category ); > > my $count; >-- >2.1.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14292
:
42125
|
42614
|
42892
|
43304
|
43305
|
43336
|
43337
|
43439
|
43489
|
43490
|
43491
|
43492
|
43493
|
43494
|
45293
|
45296