From a40b6d538d8e4b808cd9a65bca4f2281895fc186 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 1 Apr 2024 15:00:34 +0000 Subject: [PATCH] Bug 36474: Don't update records when total issues has not changed This patch adds a new check in UpdateTotalIssues to check that we are changing the number of total issues before calling ModBiblio To test: 0 - Enable CataloguingLog 1 - Checkout an item 2 - Run : misc/cronjobs/update_totalissues.pl --use-stats --commit=1000 -v 3 - In report, note all biblios were updated 4 - Check action_logs - note a new entry for every biblio 5 - Apply patch 6 - Repeat 7 - Note no biblios reported updated 8 - Note no new cataloguing log entries 9 - Checkout the item again 10 - Run again 11 - Note biblionumber has updated count in verbose output 12 - Note report only rpeort 1 biblio modified, the rest only processed 13 - Only one line added to action_logs 14 - Run it again 15 - Confirm no updates Signed-off-by: David Nind Signed-off-by: Martin Renvoize (cherry picked from commit d7b36d7f692420a5b67dee88ce78529ce7509413) Signed-off-by: Lucas Gass --- C4/Biblio.pm | 6 ++++-- misc/cronjobs/update_totalissues.pl | 13 ++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 4b32ad43d5..3f48dbb8df 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -3100,19 +3100,21 @@ sub UpdateTotalIssues { $exception->rethrow unless ( $exception->isa('Koha::Exceptions::Metadata::Invalid') ); warn $exception; warn "UpdateTotalIssues could not get bibliographic record for biblionumber $biblionumber"; - return; + return -1; } my $biblioitem = $biblio->biblioitem; my ($totalissuestag, $totalissuessubfield) = GetMarcFromKohaField( 'biblioitems.totalissues' ); unless ($totalissuestag) { - return 1; # There is nothing to do + return 0; # There is nothing to do } + my $current_issues = $biblioitem->totalissues // 0; if (defined $value) { $totalissues = $value; } else { $totalissues = $biblioitem->totalissues + $increase; } + return 0 if $current_issues == $totalissues; # No need to update if no changes my $field = $record->field($totalissuestag); if (defined $field) { diff --git a/misc/cronjobs/update_totalissues.pl b/misc/cronjobs/update_totalissues.pl index 3e3a66b1f2..a5f7a5f528 100755 --- a/misc/cronjobs/update_totalissues.pl +++ b/misc/cronjobs/update_totalissues.pl @@ -98,7 +98,8 @@ my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; my $num_bibs_processed = 0; -my $num_bibs_error = 0; +my $num_bibs_updated = 0; +my $num_bibs_error = 0; my $starttime = time(); @@ -169,13 +170,14 @@ sub process_query { my $ret; if ( $incremental && $totalissues > 0 ) { $ret = UpdateTotalIssues( $biblionumber, $totalissues, undef, 1 ); - } - else { + } else { $ret = UpdateTotalIssues( $biblionumber, 0, $totalissues, 1 ); } - unless ($ret) { + if ( $ret == -1 ) { print "Error while processing bib $biblionumber\n" if $verbose; $num_bibs_error++; + } elsif ( $ret == 1 ) { + $num_bibs_updated++; } } if ( not $test_only and ( $num_bibs_processed % $commit ) == 0 ) { @@ -199,7 +201,8 @@ Update total issues count script report Run started at: $starttime Run ended at: $endtime Total run time: $totaltime ms -Number of bibs modified: $num_bibs_processed +Number of bibs processed: $num_bibs_processed +Number of bibs modified: $num_bibs_updated Number of bibs with error: $num_bibs_error _SUMMARY_ $summary .= "\n**** Ran in test mode only ****\n" if $test_only; -- 2.39.5