|
Lines 52-64
Create a new Koha::MetadataRecord::Authority object based on the provided record
Link Here
|
| 52 |
=cut |
52 |
=cut |
| 53 |
|
53 |
|
| 54 |
sub new { |
54 |
sub new { |
| 55 |
my $class = shift; |
55 |
my ( $class, $record, $params ) = @_; |
| 56 |
my $record = shift; |
|
|
| 57 |
|
56 |
|
|
|
57 |
$params //= {}; |
| 58 |
my $self = $class->SUPER::new( |
58 |
my $self = $class->SUPER::new( |
| 59 |
{ |
59 |
{ |
| 60 |
'record' => $record, |
60 |
'record' => $record, |
| 61 |
'schema' => lc C4::Context->preference("marcflavour") |
61 |
'schema' => lc C4::Context->preference("marcflavour"), |
|
|
62 |
%$params, |
| 62 |
} |
63 |
} |
| 63 |
); |
64 |
); |
| 64 |
|
65 |
|
|
Lines 154-157
sub authorized_heading {
Link Here
|
| 154 |
return; |
155 |
return; |
| 155 |
} |
156 |
} |
| 156 |
|
157 |
|
|
|
158 |
=head2 get_all_authorities_iterator |
| 159 |
|
| 160 |
my $it = Koha::Authority->get_all_authorities_iterator(); |
| 161 |
|
| 162 |
This will provide an iterator object that will, one by one, provide the |
| 163 |
Koha::Authority of each authority. |
| 164 |
|
| 165 |
The iterator is a Koha::MetadataIterator object. |
| 166 |
|
| 167 |
=cut |
| 168 |
|
| 169 |
sub get_all_authorities_iterator { |
| 170 |
my $database = Koha::Database->new(); |
| 171 |
my $schema = $database->schema(); |
| 172 |
my $rs = |
| 173 |
$schema->resultset('AuthHeader')->search( { marcxml => { '!=', undef } }, |
| 174 |
{ columns => [qw/ authid authtypecode marcxml /] } ); |
| 175 |
my $next_func = sub { |
| 176 |
my $row = $rs->next(); |
| 177 |
return if !$row; |
| 178 |
my $authid = $row->authid; |
| 179 |
my $authtypecode = $row->authtypecode; |
| 180 |
my $marcxml = $row->marcxml; |
| 181 |
|
| 182 |
my $record = eval { |
| 183 |
MARC::Record->new_from_xml( |
| 184 |
StripNonXmlChars($marcxml), |
| 185 |
'UTF-8', |
| 186 |
( |
| 187 |
C4::Context->preference("marcflavour") eq "UNIMARC" |
| 188 |
? "UNIMARCAUTH" |
| 189 |
: C4::Context->preference("marcflavour") |
| 190 |
) |
| 191 |
); |
| 192 |
}; |
| 193 |
confess $@ if ($@); |
| 194 |
$record->encoding('UTF-8'); |
| 195 |
|
| 196 |
# I'm not sure why we don't use the authtypecode from the database, |
| 197 |
# but this is how the original code does it. |
| 198 |
require C4::AuthoritiesMarc; |
| 199 |
$authtypecode = C4::AuthoritiesMarc::GuessAuthTypeCode($record); |
| 200 |
|
| 201 |
my $auth = __PACKAGE__->new( $record, { authid => $authid, id => $authid, authtypecode => $authtypecode } ); |
| 202 |
|
| 203 |
return $auth; |
| 204 |
}; |
| 205 |
return Koha::MetadataIterator->new($next_func); |
| 206 |
} |
| 207 |
|
| 157 |
1; |
208 |
1; |