Bug 16500: Catch two warns in TestBuilder.t with warning_like
[koha.git] / Koha / Authority.pm
blobfec63d32dc0ca11f5c36b8e3a71f560ef8f90c97
1 package Koha::Authority;
3 # Copyright 2015 Koha Development Team
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use Modern::Perl;
22 use Carp;
24 use Koha::Database;
25 use C4::Context;
26 use MARC::Record;
28 use base qw(Koha::Object);
30 =head1 NAME
32 Koha::Authority - Koha Authority Object class
34 =head1 API
36 =head2 Class Methods
38 =cut
40 =head3 type
42 =cut
44 sub _type {
45 return 'AuthHeader';
48 =head2 get_all_authorities_iterator
50 my $it = Koha::Authority->get_all_authorities_iterator();
52 This will provide an iterator object that will, one by one, provide the
53 Koha::Authority of each authority.
55 The iterator is a Koha::MetadataIterator object.
57 =cut
59 sub get_all_authorities_iterator {
60 my $database = Koha::Database->new();
61 my $schema = $database->schema();
62 my $rs =
63 $schema->resultset('AuthHeader')->search( { marcxml => { '!=', undef } },
64 { columns => [qw/ authid authtypecode marcxml /] } );
65 my $next_func = sub {
66 my $row = $rs->next();
67 return if !$row;
68 my $authid = $row->authid;
69 my $authtypecode = $row->authtypecode;
70 my $marcxml = $row->marcxml;
72 my $record = eval {
73 MARC::Record->new_from_xml(
74 StripNonXmlChars($marcxml),
75 'UTF-8',
77 C4::Context->preference("marcflavour") eq "UNIMARC"
78 ? "UNIMARCAUTH"
79 : C4::Context->preference("marcflavour")
83 confess $@ if ($@);
84 $record->encoding('UTF-8');
86 # I'm not sure why we don't use the authtypecode from the database,
87 # but this is how the original code does it.
88 require C4::AuthoritiesMarc;
89 $authtypecode = C4::AuthoritiesMarc::GuessAuthTypeCode($record);
91 my $auth = __PACKAGE__->new( $record, $authid, $authtypecode );
93 return $auth;
95 return Koha::MetadataIterator->new($next_func);