From af01b62d2f5395c0c47892b5a2c9012e962791d5 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 19 Oct 2023 13:50:59 +0000 Subject: [PATCH] Bug 33608: (QA follow-up) Remove ->insert method Might come back on the subject when resuming with bug 33636. Test plan: Run t/db_dependent/Koha/Statistics.t Signed-off-by: Marcel de Rooy [EDIT] Tidy Koha/Item.pm bit further. Ordered hash keys too. Signed-off-by: Tomas Cohen Arazi --- C4/Stats.pm | 4 ++-- Koha/Item.pm | 22 ++++++++++++---------- Koha/Statistic.pm | 16 ---------------- t/db_dependent/Koha/Statistics.t | 8 ++++---- 4 files changed, 18 insertions(+), 32 deletions(-) diff --git a/C4/Stats.pm b/C4/Stats.pm index bfd2ad52e2..e13d30dafb 100644 --- a/C4/Stats.pm +++ b/C4/Stats.pm @@ -48,14 +48,14 @@ The functions of this module deals with statistics table of Koha database. C4::Stats::UpdateStats($params); - This is a (legacy) alias for Koha::Statistic->insert($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->insert($params); + Koha::Statistic->new($params)->store; } 1; diff --git a/Koha/Item.pm b/Koha/Item.pm index 32310b144c..4d84ab0981 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -231,16 +231,18 @@ sub store { sub _add_statistic { my ( $self, $type ) = @_; - C4::Stats::UpdateStats({ - type => $type, - branch => C4::Context->userenv ? C4::Context->userenv->{branch} : undef, - borrowernumber => undef, - categorycode => undef, - itemnumber => $self->itemnumber, - ccode => $self->ccode, - itemtype => $self->effective_itemtype, - location => $self->location, - }); + C4::Stats::UpdateStats( + { + borrowernumber => undef, + branch => C4::Context->userenv ? C4::Context->userenv->{branch} : undef, + categorycode => undef, + ccode => $self->ccode, + itemnumber => $self->itemnumber, + itemtype => $self->effective_itemtype, + location => $self->location, + type => $type, + } + ); } =head3 delete diff --git a/Koha/Statistic.pm b/Koha/Statistic.pm index 1a0f03834d..c3deb71b2a 100644 --- a/Koha/Statistic.pm +++ b/Koha/Statistic.pm @@ -129,22 +129,6 @@ sub store { return $self; } -=head3 insert - - Koha::Statistic->insert( $params ); - - This is a shorthand for ->new($params)->store. - It is the new equivalent for the legacy C4::Stats::UpdateStats call. - -=cut - -sub insert { - my ( $class, $params ) = @_; - my $statistic = $class->new($params) or return; - $statistic->store; - return $statistic; -} - =head3 item my $item = $statistic->item; diff --git a/t/db_dependent/Koha/Statistics.t b/t/db_dependent/Koha/Statistics.t index d41de56cd5..30b6e571cf 100755 --- a/t/db_dependent/Koha/Statistics.t +++ b/t/db_dependent/Koha/Statistics.t @@ -52,7 +52,7 @@ subtest 'Basic Koha object tests' => sub { my $item = $builder->build_sample_item; my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); - Koha::Statistic->insert( + Koha::Statistic->new( { type => 'issue', branch => $library->branchcode, @@ -63,7 +63,7 @@ subtest 'Basic Koha object tests' => sub { ccode => $item->ccode, interface => C4::Context->interface, } - ); + )->store; my $stat = Koha::Statistics->search( { itemnumber => $item->itemnumber } )->next; is( $stat->borrowernumber, $patron->borrowernumber, 'Patron is there' ); @@ -107,7 +107,7 @@ subtest 'Test exceptions in ->new' => sub { $schema->storage->txn_rollback; }; -subtest 'Test ->insert (fka UpdateStats)' => sub { +subtest 'Test new->store (fka UpdateStats)' => sub { plan tests => 15; $schema->storage->txn_begin; @@ -154,7 +154,7 @@ subtest 'Test ->insert (fka UpdateStats)' => sub { sub insert_and_fetch { my $params = shift; - my $statistic = Koha::Statistic->insert($params); + my $statistic = Koha::Statistic->new($params)->store; return Koha::Statistics->search( { borrowernumber => $test_params->{borrowernumber} } )->last; # FIXME discard_changes would be nicer, but we dont have a PK (yet) -- 2.39.5