From 0c8d8e867b18b61f39381d2061cd2124fe1c5ed3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 18 Mar 2019 14:41:37 -0300 Subject: [PATCH] Bug 23463: AddItem removing We are done with AddItem, only need to log and index. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- C4/Items.pm | 58 +++----------------------------------------- Koha/Item.pm | 8 ++++++ t/lib/TestBuilder.pm | 9 +++---- 3 files changed, 15 insertions(+), 60 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 9f91ffaaf3..214f071d13 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -159,66 +159,14 @@ sub AddItemFromMarc { my $localitemmarc = MARC::Record->new; $localitemmarc->append_fields( $source_item_marc->field($itemtag) ); -#RMME - my $item = C4::Biblio::TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' ); - my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode ); - return AddItem( $item, $biblionumber, $dbh, $frameworkcode, $unlinked_item_subfields ); - my $item_values = C4::Biblio::TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' ); + my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode ); + $item_values->{more_subfields_xml} = _get_unlinked_subfields_xml($unlinked_item_subfields); $item_values->{biblionumber} = $biblionumber; - # FIXME RM my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode ); - my $item = Koha::Item->new( $item_values ); # FIXME Handle $unlinked_item_subfields + my $item = Koha::Item->new( $item_values )->store; return ( $item->biblionumber, $item->biblioitemnumber, $item->itemnumber ); } -=head2 AddItem - - my ($biblionumber, $biblioitemnumber, $itemnumber) - = AddItem($item, $biblionumber[, $dbh, $frameworkcode, $unlinked_item_subfields]); - -Given a hash containing item column names as keys, -create a new Koha item record. - -The first two optional parameters (C<$dbh> and C<$frameworkcode>) -do not need to be supplied for general use; they exist -simply to allow them to be picked up from AddItemFromMarc. - -The final optional parameter, C<$unlinked_item_subfields>, contains -an arrayref containing subfields present in the original MARC -representation of the item (e.g., from the item editor) that are -not mapped to C columns directly but should instead -be stored in C and included in -the biblio items tag for display and indexing. - -=cut - -sub AddItem { - my $item = shift; - my $biblionumber = shift; - - my $dbh = @_ ? shift : C4::Context->dbh; - my $unlinked_item_subfields; - if (@_) { - $unlinked_item_subfields = shift; - } - - $item->{'more_subfields_xml'} = _get_unlinked_subfields_xml($unlinked_item_subfields); - - my ( $itemnumber, $error ) = _koha_new_item( $item, $item->{barcode} ); - return if $error; - - $item->{'itemnumber'} = $itemnumber; - - C4::Biblio::ModZebra( $item->{biblionumber}, "specialUpdate", "biblioserver" ); - - logaction( "CATALOGUING", "ADD", $itemnumber, "item" ) - if C4::Context->preference("CataloguingLog"); - - _after_item_action_hooks({ action => 'create', item_id => $itemnumber }); - - return ( $item->{biblionumber}, $item->{biblioitemnumber}, $itemnumber ); -} - =head2 AddItemBatchFromMarc ($itemnumber_ref, $error_ref) = AddItemBatchFromMarc($record, diff --git a/Koha/Item.pm b/Koha/Item.pm index b820cc9cab..af1444f204 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -28,7 +28,9 @@ use Koha::DateUtils qw( dt_from_string ); use C4::Context; use C4::Circulation; use C4::Reserves; +use C4::Biblio qw( ModZebra ); # FIXME This is terrible, we should move the indexation code outside of C4::Biblio use C4::ClassSource; # FIXME We would like to avoid that +use C4::Log qw( logaction ); use Koha::Checkouts; use Koha::CirculationRules; @@ -89,6 +91,12 @@ sub store { my $cn_sort = GetClassSort($self->cn_source, $self->itemcallnumber, ""); $self->cn_sort($cn_sort); } + + C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" ); + + logaction( "CATALOGUING", "ADD", $self->itemnumber, "item" ) + if C4::Context->preference("CataloguingLog"); + } unless ( $self->dateaccessioned ) { diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm index f5226fd39e..533f5d4c79 100644 --- a/t/lib/TestBuilder.pm +++ b/t/lib/TestBuilder.pm @@ -187,16 +187,15 @@ sub build_sample_item { my $barcode = delete $args->{barcode} || $self->_gen_text( { info => { size => SIZE_BARCODE } } ); - my ( undef, undef, $itemnumber ) = C4::Items::AddItem( + return Koha::Item->new( { + biblionumber => $biblionumber, homebranch => $library, holdingbranch => $library, barcode => $barcode, %$args, - }, - $biblionumber - ); - return Koha::Items->find($itemnumber); + } + )->store->get_from_storage; } # ------------------------------------------------------------------------------ -- 2.39.5