From f1f537b3dcfd77d3f95f55913c9bc49f2b2f62e1 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 8 May 2023 07:52:04 +0000 Subject: [PATCH] Bug 33608: Add UpdateStats to item->store Content-Type: text/plain; charset=utf-8 Test plan: Run t/db_dependent/Koha/Item.t Signed-off-by: Marcel de Rooy --- Koha/Item.pm | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 7251a8a094..ec7e2f3459 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -130,6 +130,10 @@ sub store { $self->cn_sort($cn_sort); } + if( $self->itemlost ) { + $self->_add_statistic('item_lost'); # should be quite rare when adding item + } + } else { # ModItem $action = 'modify'; @@ -185,15 +189,12 @@ sub store { $self->permanent_location( $self->location ); } - # If item was lost and has now been found, - # reverse any list item charges if necessary. - if ( exists $updated_columns{itemlost} - and $updated_columns{itemlost} <= 0 - and $pre_mod_item->itemlost > 0 ) - { - $self->_set_found_trigger($pre_mod_item); + if( exists $updated_columns{itemlost} && !$updated_columns{itemlost} && $pre_mod_item->itemlost ) { # item found again + $self->_set_found_trigger($pre_mod_item); # reverse any list item charges if necessary + $self->_add_statistic('item_found'); + } elsif( exists $updated_columns{itemlost} && $updated_columns{itemlost} && !$pre_mod_item->itemlost ) { # item lost + $self->_add_statistic('item_lost'); } - } my $result = $self->SUPER::store; @@ -216,6 +217,20 @@ sub store { return $result; } +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, + }); +} + =head3 delete =cut -- 2.30.2