From 36d1f18bd57796c0200ca0de0495a6720d2bbfcc Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 25 Jul 2022 10:07:48 +0200 Subject: [PATCH] Bug 30392: Set deleted_on when an item is (marked as) deleted We could like to track down when an item has been moved to the deleteditems table. Test plan: Created a new item, delete it Not that the deleteditems.deleted_on value is set correctly Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- Koha/Item.pm | 1 + t/db_dependent/Koha/Item.t | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 23a66dc534..4dc41b9d78 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -337,6 +337,7 @@ sub move_to_deleted { my ($self) = @_; my $item_infos = $self->unblessed; delete $item_infos->{timestamp}; #This ensures the timestamp date in deleteditems will be set to the current timestamp + $item_infos->{deleted_on} = dt_from_string; return Koha::Database->new->schema->resultset('Deleteditem')->create($item_infos); } diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index b13fe57e68..55cface4cf 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -37,6 +37,7 @@ use List::MoreUtils qw(all); use t::lib::TestBuilder; use t::lib::Mocks; +use t::lib::Dates; my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new; @@ -765,7 +766,7 @@ subtest 'request_transfer' => sub { }; subtest 'deletion' => sub { - plan tests => 13; + plan tests => 15; $schema->storage->txn_begin; @@ -776,9 +777,13 @@ subtest 'deletion' => sub { biblionumber => $biblio->biblionumber, } ); + is( $item->deleted_on, undef, 'deleted_on not set for new item' ); - is( ref( $item->move_to_deleted ), 'Koha::Schema::Result::Deleteditem', 'Koha::Item->move_to_deleted should return the Deleted item' ) + my $deleted_item = $item->move_to_deleted; + is( ref( $deleted_item ), 'Koha::Schema::Result::Deleteditem', 'Koha::Item->move_to_deleted should return the Deleted item' ) ; # FIXME This should be Koha::Deleted::Item + is( t::lib::Dates::compare( $deleted_item->deleted_on, dt_from_string() ), 0 ); + is( Koha::Old::Items->search({itemnumber => $item->itemnumber})->count, 1, '->move_to_deleted must have moved the item to deleteditem' ); $item = $builder->build_sample_item( { -- 2.39.5