From 0b9483a691af2dc6322f240daee5b754ba214e82 Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Wed, 30 Sep 2015 15:46:18 +1300 Subject: [PATCH] Bug 12478: fix some issues on rebase There were rebase conflicts that it was just easier to postpone until afterwards. Signed-off-by: Nick Clemens Signed-off-by: Jesse Weaver Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall Signed-off-by: Brendan Gallagher --- Koha/BiblioUtils.pm | 113 +++++++++++++----- Koha/{Biblio => BiblioUtils}/Iterator.pm | 10 +- installer/data/mysql/updatedatabase.pl | 2 +- misc/search_tools/rebuild_elastic_search.pl | 6 +- .../Koha/{Biblio.t => BiblioUtils.t} | 0 5 files changed, 89 insertions(+), 42 deletions(-) rename Koha/{Biblio => BiblioUtils}/Iterator.pm (90%) rename t/db_dependent/Koha/{Biblio.t => BiblioUtils.t} (100%) diff --git a/Koha/BiblioUtils.pm b/Koha/BiblioUtils.pm index 58ae55c5dd..a136132c57 100644 --- a/Koha/BiblioUtils.pm +++ b/Koha/BiblioUtils.pm @@ -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 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 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 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; diff --git a/Koha/Biblio/Iterator.pm b/Koha/BiblioUtils/Iterator.pm similarity index 90% rename from Koha/Biblio/Iterator.pm rename to Koha/BiblioUtils/Iterator.pm index fc150f433c..bc0003617f 100644 --- a/Koha/Biblio/Iterator.pm +++ b/Koha/BiblioUtils/Iterator.pm @@ -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 or C 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 ); } diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 0b844d8f9b..f7ca13d4bb 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -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"; diff --git a/misc/search_tools/rebuild_elastic_search.pl b/misc/search_tools/rebuild_elastic_search.pl index 804bb64f68..e8eabc7c5e 100755 --- a/misc/search_tools/rebuild_elastic_search.pl +++ b/misc/search_tools/rebuild_elastic_search.pl @@ -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(); } diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/BiblioUtils.t similarity index 100% rename from t/db_dependent/Koha/Biblio.t rename to t/db_dependent/Koha/BiblioUtils.t -- 2.39.5