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;