@@ -, +, @@ values --- installer/data/mysql/atomicupdate/bug_25958.sql | 9 +++ installer/data/mysql/sysprefs.sql | 1 + .../en/modules/admin/preferences/circulation.pref | 5 ++ misc/cronjobs/longoverdue.pl | 66 ++++++++++++++-------- 4 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_25958.sql --- a/installer/data/mysql/atomicupdate/bug_25958.sql +++ a/installer/data/mysql/atomicupdate/bug_25958.sql @@ -0,0 +1,9 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + $dbh->do(q{ + INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES + ('DefaultLongOverdueSkipLostStatuses', '', NULL, 'Skip these lost statuses by default in longoverdue.pl', 'Free'), + }); + + NewVersion( $DBversion, 25958, "Allow LongOverdue cron to exclude specified lost values"); +} --- a/installer/data/mysql/sysprefs.sql +++ a/installer/data/mysql/sysprefs.sql @@ -149,6 +149,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('DefaultClassificationSource','ddc',NULL,'Default classification scheme used by the collection. E.g., Dewey, LCC, etc.','ClassSources'), ('DefaultCountryField008','','','Fill in the default country code for field 008 Range 15-17 of MARC21 - Place of publication, production, or execution. See MARC Code List for Countries','Free'), ('DefaultLanguageField008','','','Fill in the default language for field 008 Range 35-37 of MARC21 records (e.g. eng, nor, ger, see MARC Code List for Languages)','Free'), +('DefaultLongOverdueSkipLostStatuses', '', NULL, 'Skip these lost statuses by default in longoverdue.pl', 'Free'), ('DefaultLongOverdueChargeValue', '', NULL, "Charge a lost item to the borrower's account when the LOST value of the item changes to n.", 'integer'), ('DefaultLongOverdueDays', '', NULL, "Set the LOST value of an item when the item has been overdue for more than n days.", 'integer'), ('DefaultLongOverdueLostValue', '', NULL, "Set the LOST value of an item to n when the item has been overdue for more than defaultlongoverduedays days.", 'integer'), --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -421,6 +421,11 @@ Circulation: -
(Used when the longoverdue.pl script is called without the --charge parameter) - "
NOTE: This system preference requires the misc/cronjobs/longoverdue.pl cronjob. Ask your system administrator to schedule it." - + - When using the automatic item loss process, skip items with lost values matching any of + - pref: DefaultLongOverdueSkipLostStatuses + -
Leave this field empty if you don't want to skip any lost statuses + -
Set to a list of comma separated values, e.g. 5,6,7 + - - "When issuing an item that has been marked as lost, " - pref: IssueLostItem choices: --- a/misc/cronjobs/longoverdue.pl +++ a/misc/cronjobs/longoverdue.pl @@ -34,16 +34,18 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } -use Koha::Script -cron; +use Getopt::Long; +use Pod::Usage; +use List::Util qw/ any /; + +use C4::Circulation qw/LostItem MarkIssueReturned/; use C4::Context; use C4::Items; -use C4::Circulation qw/LostItem MarkIssueReturned/; -use Getopt::Long; use C4::Log; -use Pod::Usage; -use Koha::Patrons; -use Koha::Patron::Categories; use Koha::ItemTypes; +use Koha::Patron::Categories; +use Koha::Patrons; +use Koha::Script -cron; my $lost; # key=lost value, value=num days. my ($charge, $verbose, $confirm, $quiet); @@ -57,23 +59,25 @@ my $help=0; my $man=0; my $list_categories = 0; my $list_itemtypes = 0; +my @skip_lost_values; GetOptions( - 'l|lost=s%' => \$lost, - 'c|charge=s' => \$charge, - 'confirm' => \$confirm, - 'v|verbose' => \$verbose, - 'quiet' => \$quiet, - 'maxdays=s' => \$endrange, - 'mark-returned' => \$mark_returned, - 'h|help' => \$help, - 'man|manual' => \$man, - 'category=s' => $borrower_category, - 'skip-category=s' => $skip_borrower_category, - 'list-categories' => \$list_categories, - 'itemtype=s' => $itemtype, - 'skip-itemtype=s' => $skip_itemtype, - 'list-itemtypes' => \$list_itemtypes, + 'l|lost=s%' => \$lost, + 'c|charge=s' => \$charge, + 'confirm' => \$confirm, + 'v|verbose' => \$verbose, + 'quiet' => \$quiet, + 'maxdays=s' => \$endrange, + 'mark-returned' => \$mark_returned, + 'h|help' => \$help, + 'man|manual' => \$man, + 'category=s' => $borrower_category, + 'skip-category=s' => $skip_borrower_category, + 'list-categories' => \$list_categories, + 'itemtype=s' => $itemtype, + 'skip-itemtype=s' => $skip_itemtype, + 'list-itemtypes' => \$list_itemtypes, + 'skip-lost-value=s' => \@skip_lost_values, ); if ( $man ) { @@ -98,7 +102,7 @@ if ( scalar @$borrower_category && scalar @$skip_borrower_category) { if ( scalar @$itemtype && scalar @$skip_itemtype) { pod2usage( -verbose => 1, - -message => "The options --itemtype and --skip-itemtype are mually exclusive.\n" + -message => "The options --itemtype and --skip-itemtype are mutually exclusive.\n" . "Use one or the other.", -exitval => 1 ); @@ -123,6 +127,7 @@ if ( $list_itemtypes ) { longoverdue.pl --lost | -l DAYS=LOST_CODE [ --charge | -c CHARGE_CODE ] [ --verbose | -v ] [ --quiet ] [ --maxdays MAX_DAYS ] [ --mark-returned ] [ --category BORROWER_CATEGORY ] ... [ --skip-category BORROWER_CATEGORY ] ... + [ --skip-lost-value LOST_VALUE [ --skip-lost-value LOST_VALUE ] ] [ --commit ] @@ -198,6 +203,11 @@ Act on all available itemtype codes, except those listed. This may be specified multiple times, to exclude multiple itemtypes. May not be used with B<--itemtype> +=item B<--skip-lost-value> + +Act on all available lost values, except those listed. +This may be specified multiple times, to exclude multiple lost values. + =item B<--list-itemtypes> List itemtypes available for use by B<--itemtype> or @@ -246,6 +256,12 @@ near-term release, so this script is not intended to have a long lifetime. # FIXME: do checks on --lost ranges to make sure the authorized values exist. # FIXME: do checks on --lost ranges to make sure don't go past endrange. # + +unless ( scalar @skip_lost_values ) { + my $preference = C4::Context->preference( 'DefaultLongOverdueSkipLostStatuses' ); + @skip_lost_values = split( ',', $preference ); +} + if ( ! defined($lost) ) { my $longoverdue_value = C4::Context->preference('DefaultLongOverdueLostValue'); my $longoverdue_days = C4::Context->preference('DefaultLongOverdueDays'); @@ -283,7 +299,7 @@ sub bounds { # FIXME - This sql should be inside the API. sub longoverdue_sth { my $query = " - SELECT items.itemnumber, borrowernumber, date_due + SELECT items.itemnumber, borrowernumber, date_due, itemlost FROM issues, items WHERE items.itemnumber = issues.itemnumber AND DATE_SUB(CURDATE(), INTERVAL ? DAY) > date_due @@ -373,6 +389,10 @@ foreach my $startrange (sort keys %$lost) { $sth_items->execute($startrange, $endrange, $lostvalue); $count=0; ITEM: while (my $row=$sth_items->fetchrow_hashref) { + if ( @skip_lost_values ) { + next ITEM if any { $_ eq $row->{itemlost} } @skip_lost_values; + } + if( $filter_borrower_categories ) { my $category = uc Koha::Patrons->find( $row->{borrowernumber} )->categorycode(); next ITEM unless ( $category_to_process{ $category } ); --