From e629e37bd7105977ccb229796d0a1a57ca503e23 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Mon, 23 Oct 2023 10:59:57 +0000 Subject: [PATCH] Bug 34587: Fix total added objects in job report Remove obsolete total_records code, this was a leftover from when this code was in UsageDataProvider.pm Add a new job_callback 'added_usage_objects' to handle total objects added (titles, platforms, databases, items) Update job report include file Signed-off-by: Jessica Zairo Signed-off-by: Michaela Sieber Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi --- Koha/BackgroundJob/ErmSushiHarvester.pm | 10 +++---- Koha/ERM/EUsage/CounterFile.pm | 28 ++++++++++++++++--- Koha/ERM/EUsage/SushiCounter.pm | 2 -- .../background_jobs/erm_sushi_harvester.inc | 24 ++++++++-------- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/Koha/BackgroundJob/ErmSushiHarvester.pm b/Koha/BackgroundJob/ErmSushiHarvester.pm index 3a836ee735..8d3e8c11c8 100644 --- a/Koha/BackgroundJob/ErmSushiHarvester.pm +++ b/Koha/BackgroundJob/ErmSushiHarvester.pm @@ -61,10 +61,11 @@ sub process { } $self->{us_report_info} = { - skipped_mus => 0, - skipped_yus => 0, - added_mus => 0, - added_yus => 0 + skipped_mus => 0, + skipped_yus => 0, + added_mus => 0, + added_yus => 0, + added_usage_objects => 0, }; # FIXME If the job has already been started, but started again (worker has been restart for instance) @@ -111,7 +112,6 @@ sub process { # Prepare job report my $report = { report_type => $job_report_report_type, - total_records => $ud_provider->{total_records}, us_report_info => $self->{us_report_info}, ud_provider_id => $ud_provider->erm_usage_data_provider_id, ud_provider_name => $ud_provider->name, diff --git a/Koha/ERM/EUsage/CounterFile.pm b/Koha/ERM/EUsage/CounterFile.pm index 6c0ebfa415..e7c904a756 100644 --- a/Koha/ERM/EUsage/CounterFile.pm +++ b/Koha/ERM/EUsage/CounterFile.pm @@ -546,14 +546,19 @@ sub _add_usage_object_entry { my $specific_fields = Koha::ERM::EUsage::SushiCounter->get_report_type_specific_fields( $self->type ); if ( $self->type =~ /PR/i ) { - return Koha::ERM::EUsage::UsagePlatform->new( + my $new_usage_platform = Koha::ERM::EUsage::UsagePlatform->new( { usage_data_provider_id => $usage_data_provider->erm_usage_data_provider_id, platform => $row->{Platform}, } )->store; + + $self->{job_callbacks}->{report_info_callback}->('added_usage_objects') + if $self->{job_callbacks} && $new_usage_platform; + + return $new_usage_platform; } elsif ( $self->type =~ /DR/i ) { - return Koha::ERM::EUsage::UsageDatabase->new( + my $new_usage_database = Koha::ERM::EUsage::UsageDatabase->new( { database => $row->{Database}, usage_data_provider_id => $usage_data_provider->erm_usage_data_provider_id, @@ -562,8 +567,13 @@ sub _add_usage_object_entry { publisher_id => $row->{Publisher_ID}, } )->store; + + $self->{job_callbacks}->{report_info_callback}->('added_usage_objects') + if $self->{job_callbacks} && $new_usage_database; + + return $new_usage_database; } elsif ( $self->type =~ /IR/i ) { - return Koha::ERM::EUsage::UsageItem->new( + my $new_usage_item = Koha::ERM::EUsage::UsageItem->new( { item => $row->{Item}, usage_data_provider_id => $usage_data_provider->erm_usage_data_provider_id, @@ -571,8 +581,13 @@ sub _add_usage_object_entry { publisher => $row->{Publisher}, } )->store; + + $self->{job_callbacks}->{report_info_callback}->('added_usage_objects') + if $self->{job_callbacks} && $new_usage_item; + + return $new_usage_item; } elsif ( $self->type =~ /TR/i ) { - return Koha::ERM::EUsage::UsageTitle->new( + my $new_usage_title = Koha::ERM::EUsage::UsageTitle->new( { title => $row->{Title}, usage_data_provider_id => $usage_data_provider->erm_usage_data_provider_id, @@ -590,6 +605,11 @@ sub _add_usage_object_entry { : (), } )->store; + + $self->{job_callbacks}->{report_info_callback}->('added_usage_objects') + if $self->{job_callbacks} && $new_usage_title; + + return $new_usage_title; } } diff --git a/Koha/ERM/EUsage/SushiCounter.pm b/Koha/ERM/EUsage/SushiCounter.pm index a685297eb0..67c506260c 100644 --- a/Koha/ERM/EUsage/SushiCounter.pm +++ b/Koha/ERM/EUsage/SushiCounter.pm @@ -347,7 +347,6 @@ sub _COUNTER_report_body { my @report_body = (); - my $total_records = 0; foreach my $report_row ( @{$body} ) { my @metric_types = (); @@ -366,7 +365,6 @@ sub _COUNTER_report_body { foreach my $metric_type (@metric_types) { push( @report_body, $self->_COUNTER_report_row( $report_row, $metric_type ) ); } - $self->{total_records} = ++$total_records; } return @report_body; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/erm_sushi_harvester.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/erm_sushi_harvester.inc index ee86b30c89..9670e8f321 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/erm_sushi_harvester.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/erm_sushi_harvester.inc @@ -18,20 +18,18 @@ Report rows processed [% job.progress %] - [% IF report.total_records %] - - [% IF report.report_type.match( '^PR' ) %] - SUSHI Platforms processed - [% ELSIF report.report_type.match( '^DR' ) %] - SUSHI Databases processed - [% ELSIF report.report_type.match( '^IR' ) %] - SUSHI Items processed - [% ELSIF report.report_type.match( '^TR' ) %] - SUSHI Titles processed - [% END %] - [% report.total_records | html %] - + + [% IF report.report_type.match( '^PR' ) %] + Platforms added + [% ELSIF report.report_type.match( '^DR' ) %] + Databases added + [% ELSIF report.report_type.match( '^IR' ) %] + Items added + [% ELSIF report.report_type.match( '^TR' ) %] + Titles added [% END %] + [% report.us_report_info.added_usage_objects | html %] + Monthly usages skipped [% report.us_report_info.skipped_mus | html %] -- 2.39.5