From 0d512218020109ae13cd0b99a089a0d7332e014e Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Sat, 21 Dec 2024 12:55:14 +0000 Subject: [PATCH] Bug 11530: Add a use-deleted-items option to totalissues.pl Some libraries would like to keep the usage from deleted items when calculating total issues from the items. To test: 0 - Apply patch 1 - Checkout/Check in an item several times 2 - perl misc/cronjobs/update_totalissues.pl --use-items 3 - Note the 942$o in the record has the correct count 4 - Delete the item 5 - perl misc/cronjobs/update_totalissues.pl --use-items 6 - Note record count now goes to 0 8 - perl misc/cronjobs/update_totalissues.pl --use-items --use-deleted-items 9 - Note record count correctly restored --- misc/cronjobs/update_totalissues.pl | 38 ++++++++++++++++++----------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/misc/cronjobs/update_totalissues.pl b/misc/cronjobs/update_totalissues.pl index 10763617d04..56f66dbc21c 100755 --- a/misc/cronjobs/update_totalissues.pl +++ b/misc/cronjobs/update_totalissues.pl @@ -46,24 +46,26 @@ my $test_only = 0; my $want_help = 0; my $since; my $interval; -my $usestats = 0; -my $useitems = 0; -my $incremental = 0; -my $progress = 100; +my $usestats = 0; +my $useitems = 0; +my $include_deleted = 0; +my $incremental = 0; +my $progress = 100; my $unit; my $command_line_options = join( " ", @ARGV ); my $result = GetOptions( - 'v|verbose' => \$verbose, - 't|test' => \$test_only, - 's|since=s' => \$since, - 'i|interval=s' => \$interval, - 'use-stats' => \$usestats, - 'use-items' => \$useitems, - 'incremental' => \$incremental, - 'p|progress=i' => \$progress, - 'h|help' => \$want_help + 'v|verbose' => \$verbose, + 't|test' => \$test_only, + 's|since=s' => \$since, + 'i|interval=s' => \$interval, + 'use-stats' => \$usestats, + 'use-items' => \$useitems, + 'use-deleted-items' => \$include_deleted, + 'incremental' => \$incremental, + 'p|progress=i' => \$progress, + 'h|help' => \$want_help ); binmode( STDOUT, ":encoding(UTF-8)" ); @@ -109,7 +111,10 @@ cronlogaction( { action => 'End', info => "COMPLETED" } ); exit 0; sub process_items { - my $query = "SELECT items.biblionumber, SUM(items.issues) FROM items GROUP BY items.biblionumber;"; + my $query = + $include_deleted + ? "SELECT all_items.biblionumber, SUM(all_items.issues) FROM (SELECT items.biblionumber,items.issues FROM items UNION ALL SELECT deleteditems.biblionumber, deleteditems.issues FROM deleteditems) all_items GROUP BY all_items.biblionumber;" + : "SELECT items.biblionumber, SUM(items.issues) FROM items GROUP BY items.biblionumber;"; process_query($query); } @@ -243,6 +248,11 @@ options, by definition. Also note that if both --use-stats and --use-items are specified, the count of biblios processed will be misleading. +=item B<--use-deleted-items> + +Only applies when using items as above, will include deleted items in the total +count of issues for the bibliographic records. + =item B<-s|--since=DATE> Only process issues recorded in the statistics table since DATE. -- 2.39.5