Bug 22690: (QA follow-up) Move adopt_items_from_biblios to Koha::Items
[koha-ffzg.git] / Koha / Items.pm
index 1647983..834ac18 100644 (file)
@@ -19,7 +19,6 @@ package Koha::Items;
 
 use Modern::Perl;
 
-use Carp;
 
 use Koha::Database;
 
@@ -27,6 +26,8 @@ use Koha::Item;
 
 use base qw(Koha::Objects);
 
+use Koha::SearchEngine::Indexer;
+
 =head1 NAME
 
 Koha::Items - Koha Item object set class
@@ -109,6 +110,26 @@ sub filter_out_lost {
     return $self->search( $params );
 }
 
+=head3 move_to_biblio
+
+ $items->move_to_biblio($to_biblio);
+
+Move items to a given biblio.
+
+=cut
+
+sub move_to_biblio {
+    my ( $self, $to_biblio ) = @_;
+
+    while (my $item = $self->next()) {
+        $item->move_to_biblio($to_biblio, { skip_record_index => 1 });
+    }
+    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
+    $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" );
+    $indexer->index_records( $from_biblio->biblionumber, "specialUpdate", "biblioserver" );
+}
+
+
 =head2 Internal methods
 
 =head3 _type