From 00a4775c22a30f8e692f604efa032702472b4ece Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 24 Jul 2023 14:30:11 +0000 Subject: [PATCH] Bug 34359: Remove unneeded module Koha/BiblioUtils/Iterator.pm with test Content-Type: text/plain; charset=utf-8 Test plan: git grep BiblioUtils::Iterator Signed-off-by: Marcel de Rooy --- Koha/BiblioUtils/Iterator.pm | 131 --------------------- t/db_dependent/Koha/BiblioUtils/Iterator.t | 70 ----------- 2 files changed, 201 deletions(-) delete mode 100644 Koha/BiblioUtils/Iterator.pm delete mode 100755 t/db_dependent/Koha/BiblioUtils/Iterator.t diff --git a/Koha/BiblioUtils/Iterator.pm b/Koha/BiblioUtils/Iterator.pm deleted file mode 100644 index e82f69fd73..0000000000 --- a/Koha/BiblioUtils/Iterator.pm +++ /dev/null @@ -1,131 +0,0 @@ -package Koha::BiblioUtils::Iterator; - -# This contains an iterator over biblio records - -# Copyright 2014 Catalyst IT -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - -=head1 NAME - -Koha::BiblioUtils::Iterator - iterates over biblios provided by a DBIx::Class::ResultSet - -=head1 DESCRIPTION - -This provides an iterator over a L that contains a -biblionumber column. -Returns a MARC::Record in scalar context. -Returns biblionumber and marc in list context. - -=head1 SYNOPSIS - - use Koha::BiblioUtils::Iterator; - my $rs = $schema->resultset('biblioitems'); - my $iterator = Koha::BiblioUtils::Iterator->new($rs); - while (my $record = $iterator->next()) { - // do something with $record - } - -=head1 METHODS - -=cut - -use C4::Biblio; -use Koha::Biblio::Metadata; - -use Carp qw( confess ); -use MARC::Record; -use MARC::File::XML; -use Modern::Perl; - -=head2 new - - my $it = new($sth, option => $value, ...); - -Takes a ResultSet to iterate over, and gives you an iterator on it. Optional -options may be specified. - -=head3 Options - -=over 4 - -=item items - -Set to true to include item data in the resulting MARC record. - -=back - -=cut - -sub new { - my ( $class, $rs, %options ) = @_; - - bless { - rs => $rs, - %options, - }, $class; -} - -=head2 next() - -In a scalar context, provides the next MARC::Record from the ResultSet, or -C if there are no more. - -In a list context it will provide ($biblionumber, $record). - -=cut - -sub next { - my ($self) = @_; - - my $marc; - my $row = $self->{rs}->next(); - return if !$row; - my $marcxml = C4::Biblio::GetXmlBiblio( $row->get_column('biblionumber') ); - if ( $marcxml ) { - $marc = MARC::Record->new_from_xml( $marcxml, 'UTF-8' ); - } - else { - confess "No marcxml column returned in the request."; - } - - my $bibnum; - if ( $self->{items} ) { - $bibnum = $row->get_column('biblionumber'); - confess "No biblionumber column returned in the request." - if ( !defined($bibnum) ); - - $marc = Koha::Biblio::Metadata->record( - { - record => $marc, - embed_items => 1, - biblionumber => $bibnum, - } - ); - } - - if (wantarray) { - $bibnum //= $row->get_column('biblionumber'); - confess "No biblionumber column returned in the request." - if ( !defined($bibnum) ); - return ( $bibnum, $marc ); - } - else { - return $marc; - } -} - -1; diff --git a/t/db_dependent/Koha/BiblioUtils/Iterator.t b/t/db_dependent/Koha/BiblioUtils/Iterator.t deleted file mode 100755 index 9b35954123..0000000000 --- a/t/db_dependent/Koha/BiblioUtils/Iterator.t +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/perl -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - -use Modern::Perl; - -use Test::More tests => 7; - -use_ok('Koha::BiblioUtils'); -use_ok('Koha::BiblioUtils::Iterator'); - -use Koha::Database; -use t::lib::TestBuilder; -use t::lib::Mocks; - -my $schema = Koha::Database->new()->schema(); -$schema->storage->txn_begin(); - -# Delete issues to prevent foreign constraint failures. -# blank all biblios, biblioitems, and items. -$schema->resultset('Issue')->delete(); -$schema->resultset('Biblio')->delete(); - -my $location = 'My Location'; -my $builder = t::lib::TestBuilder->new; -my $library = $builder->build({ - source => 'Branch', -}); -my $itemtype = $builder->build({ - source => 'Itemtype', -}); - -# Create a biblio instance for testing -t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); -my $biblio = $builder->build_sample_biblio(); - -# Add an item. -$builder->build_sample_item({ biblionumber => $biblio->biblionumber }); - -my $rs = $schema->resultset('Biblioitem')->search({}); -my $iterator = Koha::BiblioUtils::Iterator->new($rs, items => 1 ); -my $record = $iterator->next(); -my $expected_tags = [ 100, 245, 942, 952, 999 ]; -my @result_tags = map { $_->tag() } $record->field('...'); -my @sorted_tags = sort @result_tags; -is_deeply(\@sorted_tags,$expected_tags, "Got the same tags as expected"); - - -my $biblio_2 = $builder->build_sample_biblio(); -my $biblio_3 = $builder->build_sample_biblio(); -my $records = Koha::BiblioUtils->get_all_biblios_iterator(); -is( $records->next->id, $biblio->biblionumber ); -is( $records->next->id, $biblio_2->biblionumber ); -is( $records->next->id, $biblio_3->biblionumber ); -is( $records->next, undef, 'no more record' ); - -$schema->storage->txn_rollback(); -- 2.30.2