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 <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Nick Clemens 2024-04-01 15:00:34 +00:00 committed by Martin Renvoize
parent 1c875b0157
commit d7b36d7f69
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F
2 changed files with 12 additions and 7 deletions

View file

@ -3078,19 +3078,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) {

View file

@ -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;