From 13129b345abcdc06780a49de33425b69eb703611 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 30 Aug 2024 11:05:59 +0000 Subject: [PATCH] Bug 37790: Add skip indexing and holds queue options and verbosity to update localuse script This patch skips record indexing and real time holds queue updates when updating the localuse field from statistics. A note is added to the script that the user should reindex if the localuse field is mapped. Additionally a verbose option is added to the script, and doubled use of GetOptions is removed. Lastly, a check is added to confirm the items value is being changed before the value is stored. To test: 1 - Enable the real time holds queue 2 - Enable Elasticsearch 3 - perl misc/maintenance/update_localuse_from_statistics.pl --confirm 4 - Note all items are touched and reported 5 - Check the background jobs table - there are many jobs generated 6 - Apply patch 7 - perl misc/maintenance/update_localuse_from_statistics.pl --confirm 8 - Note 0 items are reported updated, no new background jobs 9 - perl misc/maintenance/update_localuse_from_statistics.pl --confirm --verbose 10 - No items reported 11 - Update some items in the DB UPDATE items SET localuse = 99 WHERE itemnumber LIKE '%9'; 12 - perl misc/maintenance/update_localuse_from_statistics.pl --confirm 13 - Only the number of items changed above reported 14 - UPDATE items SET localuse = 99 WHERE itemnumber LIKE '%9'; 15 - perl misc/maintenance/update_localuse_from_statistics.pl --confirm --verbose 16 - Each item changed reported, and the amounts, and the total items updated. Signed-off-by: Lucas Gass --- .../update_localuse_from_statistics.pl | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/misc/maintenance/update_localuse_from_statistics.pl b/misc/maintenance/update_localuse_from_statistics.pl index 7d64c645d1f..17820472764 100755 --- a/misc/maintenance/update_localuse_from_statistics.pl +++ b/misc/maintenance/update_localuse_from_statistics.pl @@ -29,40 +29,47 @@ use Pod::Usage qw( pod2usage ); my ($params); GetOptions( - 'confirm' => \$params->{confirm}, 'help' => \$params->{help}, 'age:i' => \$params->{age}, + 'c|confirm' => \$params->{confirm}, + 'v|verbose' => \$params->{verbose}, + 'help' => \$params->{help}, ); if ( $params->{help} ) { pod2usage( -verbose => 2 ); exit; } +my $updated; + +if ( $params->{confirm} ) { + $updated = update_localuse( { verbose => $params->{verbose} } ); +} + +print "Updated $updated items.\n"; + sub update_localuse { + my $params = shift; + my $verbose = $params->{verbose}; my $dbh = C4::Context->dbh; - my $items = Koha::Items->search(); + my $items = Koha::Items->search(); + my $updated = 0; # Loop through each item and update it with statistics info while ( my $item = $items->next ) { my $itemnumber = $item->itemnumber; my $localuse_count = Koha::Statistics->search( { itemnumber => $itemnumber, type => 'localuse' } )->count; + my $item_localuse = $item->localuse // 0; + next if $item_localuse == $localuse_count; $item->localuse($localuse_count); - $item->store; + $item->store( { skip_record_index => 1, skip_holds_queue => 1 } ); + $updated++; - print "Updated item $itemnumber with localuse statistics info.\n"; + print "Updated item $itemnumber with localuse statistics info. Was $item_localuse, now $localuse_count\n" + if $verbose; } -} - -my ($help); -my $result = GetOptions( - 'help|h' => \$help, -); - -usage() if $help; - -if ( $params->{confirm} ) { - update_localuse(); + return $updated; } =head1 NAME @@ -74,10 +81,12 @@ update_local_use_from_statistics.pl update_localuse_from_statistics.pl update_localuse_from_statistics.pl --help update_localuse_from_statistics.pl --confirm + update_localuse_from_statistics.pl --verbose =head1 DESCRIPTION This script updates the items.localuse column with data from the statistics table to make sure the two tables are congruent. +NOTE: If you have mapped the items.localuse field in your search engine you must reindex your records after running this script. =head1 OPTIONS @@ -91,6 +100,10 @@ Prints this help message Confirm to run the script. +=item B<-v|--verbose> + + Add verbosity to output. + =back =cut -- 2.39.2