From 48edb2947163c1e9a70b11de40a71ebed747952f Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 28 Jul 2020 07:55:18 -0400 Subject: [PATCH] Bug 25958: Allow LongOverdue cron to exclude specified lost values When lost items are not marked as returned, they are still subject to the long overdue cron, so an item that has already been marked Lost may automatically roll to Long Overdue. In some cases, a library may not want that lost value to change. This becomes especially important with the introduction of Claims Returned, which uses a variety of lost. Test Plan: 1) Set up a long overdue item that would be moved to lost by longoverdue.pl 2) Run the cronjob with the new --skip-lost-value option 3) Note the item is not altered 4) Include that value in the new system preference DefaultLongOverdueSkipLostStatuses 5) Run the cronjob *without* the new option 6) Note the item is not altered 7) Run the cronjob again with the new command line option, but set it to a different value so the item will be affected 8) Note the item is altered as it would have been before this patch was applied Signed-off-by: Lisette Scheer Signed-off-by: Rebecca Coert Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- .../data/mysql/atomicupdate/bug_25958.sql | 9 +++ installer/data/mysql/sysprefs.sql | 1 + .../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 diff --git a/installer/data/mysql/atomicupdate/bug_25958.sql b/installer/data/mysql/atomicupdate/bug_25958.sql new file mode 100644 index 0000000000..1c6d1b5385 --- /dev/null +++ b/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"); +} diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 449ad36199..cfb5ba6837 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -151,6 +151,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'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 1e2c4bf1ba..faa7018f06 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -420,6 +420,11 @@ Circulation: -
Leave this field empty if you don't want to charge the user for lost items. -
(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 diff --git a/misc/cronjobs/longoverdue.pl b/misc/cronjobs/longoverdue.pl index 09955ade9c..d1bb9cb98f 100755 --- a/misc/cronjobs/longoverdue.pl +++ b/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 } ); -- 2.39.5