Bug 42396: Remove C4::Stats::UpdateStats and delete module

This patch replaces all calls to C4::Stats::UpdateStats with the wrapped
function from the Koha namespace. As this is the last function in C4::Stats, the
module is also deleted.

Several tests depended on transitive includes to Koha::Statistics through
C4::Stats. I've identified uses of that module by searching, and added the
necessary use in each case. I've run `prove -r t xt` with this patch applied and
didn't hit any relevant errors.

Test plan:
1. Inspect the patch, and verify each changed call maintains the same parameters.
2. Apply patch.
3. Prove the following files:
   - t/db_dependent/Accounts.t
   - t/db_dependent/Circulation.t
   - t/db_dependent/Koha/Account.t
   - t/db_dependent/Koha/ILL/Request.t
   - t/db_dependent/Koha/Item.t
   - t/db_dependent/Koha/Pseudonymization.t
   - t/db_dependent/Koha/Recalls.t

Sponsored-by: Open Fifth

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Laura_Escamilla <laura.escamilla@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Olivia Reynolds 2026-06-23 13:24:54 +00:00 committed by Lucas Gass
parent 7412a3e38d
commit 2acaf4360a
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
15 changed files with 31 additions and 92 deletions

View File

@ -28,7 +28,6 @@ BEGIN {
}
use C4::Context;
use C4::Stats;
use C4::Members;
use Koha::Account;
use Koha::Account::Lines;

View File

@ -83,7 +83,6 @@ use Try::Tiny;
use JSON;
use C4::Context;
use C4::Stats qw( UpdateStats );
use C4::Reserves
qw( CheckReserves CanItemBeReserved MoveReserve ModReserve ModReserveMinusPriority IsAvailableForItemLevelRequest );
use C4::Biblio qw( UpdateTotalIssues );
@ -123,6 +122,7 @@ use Koha::SearchEngine::Indexer;
use Koha::Exceptions::Checkout;
use Koha::Plugins;
use Koha::Recalls;
use Koha::Statistic;
use Koha::Library::Hours;
use Koha::Library::FloatLimits;
use Carp qw( carp );
@ -885,7 +885,7 @@ sub CanBookBeIssued {
if ( $patron->category->category_type eq 'X' && ( $item_object->barcode ) ) {
# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1 .
C4::Stats::UpdateStats(
Koha::Statistic->new(
{
branch => C4::Context->userenv->{'branch'},
type => 'localuse',
@ -897,7 +897,7 @@ sub CanBookBeIssued {
location => $item_object->location,
interface => C4::Context->interface,
}
);
)->store();
my $block_lost_return = C4::Context->preference("BlockReturnOfLostItems") ? 1 : 0;
ModDateLastSeen( $item_object->itemnumber, $block_lost_return ); # FIXME Move to Koha::Item
return ( { STATS => 1, }, {} );
@ -1985,7 +1985,7 @@ sub AddIssue {
}
# Record the fact that this book was issued.
C4::Stats::UpdateStats(
Koha::Statistic->new(
{
branch => C4::Context->userenv->{'branch'},
type => ( $onsite_checkout ? 'onsite_checkout' : 'issue' ),
@ -1998,7 +1998,7 @@ sub AddIssue {
ccode => $item_object->ccode,
categorycode => $patron->categorycode
}
);
)->store();
# Send a checkout slip.
my $circulation_alert = 'C4::ItemCirculationAlertPreference';
@ -2717,7 +2717,7 @@ sub AddReturn {
# Record the fact that this book was returned.
my $categorycode = $patron_unblessed ? $patron_unblessed->{categorycode} : undef;
C4::Stats::UpdateStats(
Koha::Statistic->new(
{
branch => $branch,
type => $stat_type,
@ -2729,7 +2729,8 @@ sub AddReturn {
categorycode => $categorycode,
interface => C4::Context->interface,
}
) unless ( $skip_localuse && !$issue );
)->store()
unless ( $skip_localuse && !$issue );
# Send a check-in slip. # NOTE: borrower may be undef. Do not try to send messages then.
if ($patron) {
@ -3743,7 +3744,7 @@ sub AddRenewal {
)->store();
# Add the renewal to stats
C4::Stats::UpdateStats(
Koha::Statistic->new(
{
branch => $item_object->renewal_branchcode( { branch => $branch } ),
type => 'renew',
@ -3756,7 +3757,7 @@ sub AddRenewal {
categorycode => $patron->categorycode,
interface => C4::Context->interface,
}
);
)->store();
#Update borrowers.lastseen
try {

View File

@ -1,66 +0,0 @@
package C4::Stats;
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <https://www.gnu.org/licenses>.
use Modern::Perl;
use base 'Exporter';
BEGIN {
our @EXPORT_OK = qw(
UpdateStats
);
}
use Koha::Statistics;
=head1 NAME
C4::Stats - Update Koha statistics (log)
=head1 SYNOPSIS
use C4::Stats;
=head1 DESCRIPTION
The functions of this module deals with statistics table of Koha database.
=head1 FUNCTIONS
=head2 UpdateStats
C4::Stats::UpdateStats($params);
This is a (legacy) alias for Koha::Statistic->new($params)->store.
Please see Koha::Statistic module.
=cut
sub UpdateStats {
my $params = shift;
Koha::Statistic->new($params)->store;
}
1;
__END__
=head1 AUTHOR
Koha Development Team <https://koha-community.org/>
=cut

View File

@ -25,7 +25,6 @@ use Try::Tiny qw( catch try );
use C4::Letters;
use C4::Log qw( logaction );
use C4::Stats qw( UpdateStats );
use C4::Overdues qw(GetFine);
use C4::Context;
@ -38,6 +37,7 @@ use Koha::Account::DebitTypes;
use Koha::Exceptions;
use Koha::Exceptions::Account;
use Koha::Plugins;
use Koha::Statistic;
=head1 NAME
@ -286,7 +286,7 @@ sub add_credit {
}
)->store();
C4::Stats::UpdateStats(
Koha::Statistic->new(
{
branch => $library_id,
type => lc($credit_type),
@ -294,7 +294,8 @@ sub add_credit {
borrowernumber => $self->{patron_id},
interface => $interface,
}
) if grep { $credit_type eq $_ } ( 'PAYMENT', 'WRITEOFF' );
)->store()
if grep { $credit_type eq $_ } ( 'PAYMENT', 'WRITEOFF' );
Koha::Plugins->call(
'after_account_action',

View File

@ -18,6 +18,7 @@ package Koha::BackgroundJob::PseudonymizeStatistic;
use Modern::Perl;
use Koha::PseudonymizedTransactions;
use Koha::Statistic;
use base 'Koha::BackgroundJob';

View File

@ -45,6 +45,7 @@ use Koha::Items;
use Koha::Libraries;
use Koha::AdditionalContents;
use Koha::Patron;
use Koha::Statistic;
use C4::Circulation qw( CanBookBeIssued AddIssue );
@ -2275,7 +2276,7 @@ Actions to be done after the request has been completed
sub after_completed {
my ($self) = @_;
C4::Stats::UpdateStats(
Koha::Statistic->new(
{
borrowernumber => $self->borrowernumber // undef,
branch => $self->branchcode,
@ -2287,7 +2288,7 @@ sub after_completed {
location => undef,
type => 'illreq_comp',
}
);
)->store();
}
=head3 after_created
@ -2301,7 +2302,7 @@ Actions to be done after the request has been fully created
sub after_created {
my ($self) = @_;
C4::Stats::UpdateStats(
Koha::Statistic->new(
{
borrowernumber => $self->borrowernumber // undef,
branch => $self->branchcode,
@ -2313,7 +2314,7 @@ sub after_created {
location => undef,
type => 'illreq_created',
}
);
)->store();
}
=head3 requested_partners

View File

@ -58,6 +58,7 @@ use Koha::StockRotationItem;
use Koha::StockRotationRotas;
use Koha::TrackedLinks;
use Koha::Policy::Holds;
use Koha::Statistic;
use base qw(Koha::Object);
@ -268,7 +269,7 @@ Record a statistics entry for this item (e.g. on store or delete).
sub _add_statistic {
my ( $self, $type ) = @_;
C4::Stats::UpdateStats(
Koha::Statistic->new(
{
borrowernumber => undef,
branch => C4::Context->userenv ? C4::Context->userenv->{branch} : undef,
@ -279,7 +280,7 @@ sub _add_statistic {
location => $self->location,
type => $type,
}
);
)->store();
}
=head3 delete

View File

@ -24,8 +24,7 @@ use Koha::Database;
use Koha::Recall;
use Koha::DateUtils qw( dt_from_string );
use Koha::Plugins;
use C4::Stats qw( UpdateStats );
use Koha::Statistic;
use base qw(Koha::Objects);
@ -191,7 +190,7 @@ sub add_recall {
$item = Koha::Items->find($itemnumber);
# add to statistics table
C4::Stats::UpdateStats(
Koha::Statistic->new(
{
branch => C4::Context->userenv->{'branch'},
type => 'recall',
@ -202,7 +201,7 @@ sub add_recall {
categorycode => $checkout->patron->categorycode,
interface => $interface,
}
);
)->store();
Koha::Plugins->call(
'after_recall_action',

View File

@ -35,7 +35,6 @@ use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_htt
use CGI qw ( -utf8 );
use C4::Members;
use C4::Accounts;
use C4::Stats;
use C4::Koha;
use C4::Overdues;
use Koha::Patrons;

View File

@ -21,6 +21,7 @@ use Pod::Usage qw( pod2usage );
use Koha::DateUtils qw( dt_from_string format_sqldatetime );
use Koha::Script;
use Koha::Statistic;
use Koha::Statistics;
use Koha::PseudonymizedTransactions;

View File

@ -27,7 +27,6 @@ use C4::Context;
use C4::Accounts;
use C4::Circulation qw( AddOfflineOperation );
use C4::Members;
use C4::Stats;
use Koha::Checkouts;
use Koha::UploadedFiles;
use Koha::Items;

View File

@ -59,6 +59,7 @@ use Koha::Account::Offsets;
use Koha::ActionLogs;
use Koha::Notice::Messages;
use Koha::Cache::Memory::Lite;
use Koha::Statistics;
my $builder = t::lib::TestBuilder->new;

View File

@ -25,12 +25,12 @@ use Test::Warn;
use Try::Tiny;
use C4::Circulation qw( AddIssue AddReturn );
use C4::Stats qw( UpdateStats );
use Koha::Database;
use Koha::DateUtils qw( dt_from_string );
use Koha::Patrons;
use Koha::PseudonymizedTransactions;
use Koha::Statistic;
use Koha::Statistics;
use t::lib::TestBuilder;

View File

@ -23,6 +23,7 @@ use Test::More tests => 3;
use Test::Warn;
use Koha::DateUtils qw(dt_from_string);
use Koha::Statistic;
use Koha::Statistics;
use Koha::Database;

View File

@ -25,6 +25,7 @@ use Test::Exception;
use C4::Context;
use Koha::Database;
use Koha::Statistic;
use Koha::Statistics;
use t::lib::TestBuilder;