|
Lines 150-201
sub authorized_heading {
Link Here
|
| 150 |
|
150 |
|
| 151 |
=head2 get_all_authorities_iterator |
151 |
=head2 get_all_authorities_iterator |
| 152 |
|
152 |
|
| 153 |
my $it = Koha::MetadataRecord::Authority->get_all_authorities_iterator(); |
153 |
my $it = Koha::MetadataRecord::Authority->get_all_authorities_iterator(%options); |
| 154 |
|
154 |
|
| 155 |
This will provide an iterator object that will, one by one, provide the |
155 |
This will provide an iterator object that will, one by one, provide the |
| 156 |
Koha::MetadataRecord::Authority of each authority. |
156 |
Koha::MetadataRecord::Authority of each authority. |
| 157 |
|
157 |
|
| 158 |
The iterator is a Koha::MetadataIterator object. |
158 |
The iterator is a Koha::MetadataIterator object. |
| 159 |
|
159 |
|
|
|
160 |
Possible options are: |
| 161 |
|
| 162 |
=over 4 |
| 163 |
|
| 164 |
=item C<slice> |
| 165 |
|
| 166 |
slice may be defined as a hash of two values: index and count. index |
| 167 |
is the slice number to process and count is total number of slices. |
| 168 |
With this information the iterator returns just the given slice of |
| 169 |
records instead of all. |
| 170 |
|
| 160 |
=cut |
171 |
=cut |
| 161 |
|
172 |
|
| 162 |
sub get_all_authorities_iterator { |
173 |
sub get_all_authorities_iterator { |
|
|
174 |
my ($self, %options) = @_; |
| 175 |
|
| 176 |
my ($slice_modulo, $slice_count); |
| 177 |
if ($options{slice}) { |
| 178 |
$slice_count = $options{slice}->{count}; |
| 179 |
$slice_modulo = $options{slice}->{index}; |
| 180 |
$slice_modulo = 0 if ($slice_modulo == $slice_count); |
| 181 |
} |
| 182 |
|
| 163 |
my $database = Koha::Database->new(); |
183 |
my $database = Koha::Database->new(); |
| 164 |
my $schema = $database->schema(); |
184 |
my $schema = $database->schema(); |
| 165 |
my $rs = |
185 |
my $rs = |
| 166 |
$schema->resultset('AuthHeader')->search( { marcxml => { '!=', undef } }, |
186 |
$schema->resultset('AuthHeader')->search( { marcxml => { '!=', undef } }, |
| 167 |
{ columns => [qw/ authid authtypecode marcxml /] } ); |
187 |
{ columns => [qw/ authid authtypecode marcxml /] } ); |
|
|
188 |
|
| 168 |
my $next_func = sub { |
189 |
my $next_func = sub { |
| 169 |
my $row = $rs->next(); |
190 |
while (1) { |
| 170 |
return if !$row; |
191 |
my $row = $rs->next(); |
| 171 |
my $authid = $row->authid; |
192 |
return if !$row; |
| 172 |
my $authtypecode = $row->authtypecode; |
193 |
|
| 173 |
my $marcxml = $row->marcxml; |
194 |
# Check if authid matches our slice definition |
| 174 |
|
195 |
if (defined $slice_count) { |
| 175 |
my $record = eval { |
196 |
next unless $row->authid % $slice_count == $slice_modulo; |
| 176 |
MARC::Record->new_from_xml( |
197 |
} |
| 177 |
StripNonXmlChars($marcxml), |
198 |
|
| 178 |
'UTF-8', |
199 |
my $authid = $row->authid; |
| 179 |
( |
200 |
my $authtypecode = $row->authtypecode; |
| 180 |
C4::Context->preference("marcflavour") eq "UNIMARC" |
201 |
my $marcxml = $row->marcxml; |
| 181 |
? "UNIMARCAUTH" |
202 |
|
| 182 |
: C4::Context->preference("marcflavour") |
203 |
my $record = eval { |
| 183 |
) |
204 |
MARC::Record->new_from_xml( |
| 184 |
); |
205 |
StripNonXmlChars($marcxml), |
| 185 |
}; |
206 |
'UTF-8', |
| 186 |
confess $@ if ($@); |
207 |
( |
| 187 |
$record->encoding('UTF-8'); |
208 |
C4::Context->preference("marcflavour") eq "UNIMARC" |
| 188 |
|
209 |
? "UNIMARCAUTH" |
| 189 |
# I'm not sure why we don't use the authtypecode from the database, |
210 |
: C4::Context->preference("marcflavour") |
| 190 |
# but this is how the original code does it. |
211 |
) |
| 191 |
require C4::AuthoritiesMarc; |
212 |
); |
| 192 |
$authtypecode = C4::AuthoritiesMarc::GuessAuthTypeCode($record); |
213 |
}; |
| 193 |
|
214 |
confess $@ if ($@); |
| 194 |
my $auth = __PACKAGE__->new( $record, { authid => $authid, id => $authid, authtypecode => $authtypecode } ); |
215 |
$record->encoding('UTF-8'); |
| 195 |
|
216 |
|
| 196 |
return $auth; |
217 |
# I'm not sure why we don't use the authtypecode from the database, |
| 197 |
}; |
218 |
# but this is how the original code does it. |
| 198 |
return Koha::MetadataIterator->new($next_func); |
219 |
require C4::AuthoritiesMarc; |
|
|
220 |
$authtypecode = C4::AuthoritiesMarc::GuessAuthTypeCode($record); |
| 221 |
|
| 222 |
my $auth = __PACKAGE__->new( $record, { authid => $authid, id => $authid, authtypecode => $authtypecode } ); |
| 223 |
|
| 224 |
return $auth; |
| 225 |
} |
| 226 |
}; |
| 227 |
return Koha::MetadataIterator->new($next_func); |
| 199 |
} |
228 |
} |
| 200 |
|
229 |
|
| 201 |
1; |
230 |
1; |