Bug 32528: Make safe_to_delete exit earlier on error conditions
[koha-ffzg.git] / Koha / BiblioUtils.pm
index 1ece4a8..cb7baed 100644 (file)
@@ -27,12 +27,9 @@ Koha::BiblioUtils - contains fundamental biblio-related functions
 
 This contains functions for normal operations on biblio records.
 
-Note: really, C4::Biblio does the main functions, but the Koha namespace is
-the new thing that should be used.
-
 =cut
 
-use C4::Biblio;
+use Koha::Biblios;
 use Koha::MetadataIterator;
 use Koha::Database;
 use Modern::Perl;
@@ -123,7 +120,7 @@ records instead of all.
 =cut
 
 sub get_all_biblios_iterator {
-    my ($self, %options) = @_;
+    my ($class, %options) = @_;
 
     my $search_terms = {};
     my ($slice_modulo, $slice_count);
@@ -140,8 +137,7 @@ sub get_all_biblios_iterator {
 
     my $database = Koha::Database->new();
     my $schema   = $database->schema();
-    my $rs =
-      $schema->resultset('Biblio')->search(
+    my $rs = Koha::Biblios->search(
         $search_terms,
         $search_options );
     my $next_func = sub {
@@ -149,14 +145,12 @@ sub get_all_biblios_iterator {
         while (1) {
             my $row = $rs->next();
             return if !$row;
-            my $marc = C4::Biblio::GetMarcBiblio({
-                biblionumber => $row->biblionumber,
-                embed_items  => 1 });
             my $next = eval {
-                __PACKAGE__->new($marc, $row->biblionumber);
+                my $marc = $row->metadata->record({ embed_items => 1 });
+                $class->new($marc, $row->biblionumber);
             };
             if ($@) {
-                warn "Something went wrong reading record for biblio $row->biblionumber: $@\n";
+                warn sprintf "Something went wrong reading record for biblio %s: %s\n", $row->biblionumber, $@;
                 next;
             }
             return $next;
@@ -188,9 +182,9 @@ If set to true, item data is embedded in the record. Default is to not do this.
 sub get_marc_biblio {
     my ($class, $bibnum, %options) = @_;
 
-    return C4::Biblio::GetMarcBiblio({
-        biblionumber => $bibnum,
-        embed_items  => ($options{item_data} ? 1 : 0 ) });
+    my $record = Koha::Biblios->find($bibnum)
+      ->metadata->record( { $options{item_data} ? ( embed_items => 1 ) : () } );
+    return $record;
 }
 
 1;