Bug 12478: fix some issues on rebase
authorRobin Sheat <robin@catalyst.net.nz>
Wed, 30 Sep 2015 02:46:18 +0000 (15:46 +1300)
committerBrendan Gallagher <brendan@bywatersolutions.com>
Tue, 26 Apr 2016 20:20:09 +0000 (20:20 +0000)
There were rebase conflicts that it was just easier to postpone until
afterwards.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>

Koha/BiblioUtils.pm
Koha/BiblioUtils/Iterator.pm [moved from Koha/Biblio/Iterator.pm with 90% similarity]
installer/data/mysql/updatedatabase.pl
misc/search_tools/rebuild_elastic_search.pl
t/db_dependent/Koha/BiblioUtils.t [moved from t/db_dependent/Koha/Biblio.t with 100% similarity]

index 58ae55c..a136132 100644 (file)
@@ -1,4 +1,4 @@
-package Koha::BiblioUtils;
+package Koha::BiblioUtilsUtils;
 
 # This contains functions to do with managing biblio records.
 
@@ -21,36 +21,90 @@ package Koha::BiblioUtils;
 
 =head1 NAME
 
-Koha::BiblioUtils - contains some handy biblio-related functions
+Koha::BiblioUtils - contains fundamental biblio-related functions
 
 =head1 DESCRIPTION
 
-This contains functions for operations on biblio records.
+This contains functions for normal operations on biblio records.
 
-Note: really, C4::Biblio does the main functions, but the Koha namespace is
+Note: really, C4::BiblioUtils does the main functions, but the Koha namespace is
 the new thing that should be used.
 
 =cut
 
-use C4::Biblio; # EmbedItemsInMarcBiblio
-use Koha::Biblio::Iterator;
+use C4::BiblioUtils; # EmbedItemsInMarcBiblio
+use Koha::MetadataIterator;
 use Koha::Database;
 use Modern::Perl;
 
-use base qw(Class::Accessor);
+use base qw(Koha::MetadataRecord);
 
-__PACKAGE__->mk_accessors(qw());
+__PACKAGE__->mk_accessors(qw( record schema idnumber datatype ));
 
 =head1 FUNCTIONS
 
+=head2 new
+
+    my $biblio = Koha::BiblioUtils->new($marc_record, [$biblionumber]);
+
+Creates an instance of C<Koha::BiblioUtils> based on the marc record. If known,
+the biblionumber can be provided too.
+
+=cut
+
+sub new {
+    my $class = shift;
+    my $record = shift;
+    my $biblionumber = shift;
+
+    my $self = $class->SUPER::new(
+        {
+            'record'   => $record,
+            'schema'   => lc C4::Context->preference("marcflavour"),
+            'idnumber' => $biblionumber,
+            'datatype' => 'biblio',
+        }
+    );
+    bless $self, $class;
+    return $self;
+}
+
+=head2 get_from_biblionumber
+
+    my $biblio = Koha::BiblioUtils->get_from_biblionumber($biblionumber, %options);
+
+This will give you an instance of L<Koha::BiblioUtils> that is the biblio that
+you requested.
+
+Options are:
+
+=over 4
+
+=item C<$item_data>
+
+If true, then the item data will be merged into the record when it's loaded.
+
+=back
+
+It will return C<undef> if the biblio doesn't exist.
+
+=cut
+
+sub get_from_biblionumber {
+    my ($class, $bibnum, %options) = @_;
+
+    my $marc = $class->get_marc_biblio($bibnum, %options);
+    return $class->new($marc, $bibnum);
+}
+
 =head2 get_all_biblios_iterator
 
-    my $it = get_all_biblios_iterator();
+    my $it = Koha::BiblioUtils->get_all_biblios_iterator();
 
 This will provide an iterator object that will, one by one, provide the
-MARC::Record of each biblio. This will include the item data.
+Koha::BiblioUtils of each biblio. This will include the item data.
 
-The iterator is a Koha::Biblio::Iterator object.
+The iterator is a Koha::MetadataIterator object.
 
 =cut
 
@@ -58,17 +112,24 @@ sub get_all_biblios_iterator {
     my $database = Koha::Database->new();
     my $schema   = $database->schema();
     my $rs =
-      $schema->resultset('Biblioitem')->search( { marc => { '!=', undef } },
-        { columns => [qw/ biblionumber marc /] } );
-    return Koha::Biblio::Iterator->new($rs, items => 1);
+      $schema->resultset('Biblio')->search( {},
+        { columns => [qw/ biblionumber /] } );
+    my $next_func = sub {
+        my $row = $rs->next();
+        return undef if !$row;
+        my $marc = C4::Biblio::GetMarcBiblio( $row->biblionumber, 1 );
+        return __PACKAGE__->new($marc, $row->biblionumber);
+    };
+    return Koha::MetadataIterator->new($next_func);
 }
 
 =head2 get_marc_biblio
 
-    my $marc = get_marc_biblio($bibnum, %options);
+    my $marc = Koha::BiblioUtils->get_marc_biblio($bibnum, %options);
 
-This fetches the MARC::Record for the given biblio number. Nothing is returned
-if the biblionumber couldn't be found (or it somehow has no MARC data.)
+This non-class function fetches the MARC::Record for the given biblio number.
+Nothing is returned if the biblionumber couldn't be found (or it somehow has no
+MARC data.)
 
 Options are:
 
@@ -83,23 +144,9 @@ If set to true, item data is embedded in the record. Default is to not do this.
 =cut
 
 sub get_marc_biblio {
-    my ($class,$bibnum, %options) = @_;
-
-    my $database = Koha::Database->new();
-    my $schema   = $database->schema();
-    my $rs =
-      $schema->resultset('Biblioitem')
-      ->search( { marc => { '!=', undef }, biblionumber => $bibnum },
-        { columns => [qw/ marc /] } );
-
-    my $row = $rs->next();
-    return unless $row;
-    my $marc = MARC::Record->new_from_usmarc($row->marc);
-
-    # TODO implement this in this module
-    C4::Biblio::EmbedItemsInMarcBiblio($marc, $bibnum) if $options{item_data};
+    my ($class, $bibnum, %options) = @_;
 
-    return $marc;
+    return C4::Biblio::GetMarcBiblio( $bibnum, ($options{item_data} ? 1 : 0 ) );
 }
 
 1;
similarity index 90%
rename from Koha/Biblio/Iterator.pm
rename to Koha/BiblioUtils/Iterator.pm
index fc150f4..bc00036 100644 (file)
@@ -1,4 +1,4 @@
-package Koha::Biblio::Iterator;
+package Koha::BiblioUtils::Iterator;
 
 # This contains an iterator over biblio records
 
@@ -21,7 +21,7 @@ package Koha::Biblio::Iterator;
 
 =head1 NAME
 
-Koha::Biblio::Iterator - iterates over biblios provided by a DBIx::Class::ResultSet
+Koha::BiblioUtils::Iterator - iterates over biblios provided by a DBIx::Class::ResultSet
 
 =head1 DESCRIPTION
 
@@ -31,9 +31,9 @@ C<marc> or C<marcxml> column from the biblioitems table.
 
 =head1 SYNOPSIS
 
-  use Koha::Biblio::Iterator;
+  use Koha::BiblioUtils::Iterator;
   my $rs = $schema->resultset('biblioitems');
-  my $iterator = Koha::Biblio::Iterator->new($rs);
+  my $iterator = Koha::BiblioUtils::Iterator->new($rs);
   while (my $record = $iterator->next()) {
       // do something with $record
   }
@@ -108,7 +108,7 @@ sub next {
         confess "No biblionumber column returned in the request."
           if ( !defined($bibnum) );
 
-        # TODO this should really be in Koha::Biblio or something similar.
+        # TODO this should really be in Koha::BiblioUtils or something similar.
         C4::Biblio::EmbedItemsInMarcBiblio( $marc, $bibnum );
     }
 
index 0b844d8..f7ca13d 100755 (executable)
@@ -10355,7 +10355,7 @@ if ( CheckVersion($DBversion) ) {
     |);
 
     print "Upgrade to $DBversion done (Bug 8007: Add System Preferences useDischarge, the discharge notice and the new table discharges)\n";
-    SetVersion ($DBversion);
+    SetVersion($DBversion);
 }
 
 $DBversion = "3.19.00.036";
index 804bb64..e8eabc7 100755 (executable)
@@ -84,7 +84,7 @@ Full documentation.
 use autodie;
 use Getopt::Long;
 use Koha::Authority;
-use Koha::Biblio;
+use Koha::BiblioUtils;
 use Koha::ElasticSearch::Indexer;
 use MARC::Field;
 use MARC::Record;
@@ -125,10 +125,10 @@ if ($index_biblios) {
         $next = sub {
             my $r = shift @biblionumbers;
             return () unless defined $r;
-            return ($r, Koha::Biblio->get_from_biblionumber($r, item_data => 1 ));
+            return ($r, Koha::BiblioUtils->get_from_biblionumber($r, item_data => 1 ));
         };
     } else {
-        my $records = Koha::Biblio->get_all_biblios_iterator();
+        my $records = Koha::BiblioUtils->get_all_biblios_iterator();
         $next = sub {
             $records->next();
         }