From edc49a55bb724a973cdb78bda83d9f95d0f81835 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 Test plan: Run t/db_dependent/Koha/Item.t Signed-off-by: Marcel de Rooy Signed-off-by: Owen Leonard Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- Koha/Item.pm | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 854b6cfd58..59dd937f4c 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -131,6 +131,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'; @@ -186,15 +190,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; @@ -217,6 +218,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.39.5