Lines 27-33
use C4::Charset;
Link Here
|
27 |
use MARC::File::USMARC; |
27 |
use MARC::File::USMARC; |
28 |
use C4::ImportBatch; |
28 |
use C4::ImportBatch; |
29 |
use C4::AuthoritiesMarc; #GuessAuthTypeCode, FindDuplicateAuthority |
29 |
use C4::AuthoritiesMarc; #GuessAuthTypeCode, FindDuplicateAuthority |
|
|
30 |
use C4::Languages; |
30 |
use Koha::Database; |
31 |
use Koha::Database; |
|
|
32 |
use Koha::XSLT_Handler; |
31 |
|
33 |
|
32 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
34 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
33 |
|
35 |
|
Lines 164-169
sub Z3950Search {
Link Here
|
164 |
_translate_query( $server, $squery ))); |
166 |
_translate_query( $server, $squery ))); |
165 |
$s++; |
167 |
$s++; |
166 |
} |
168 |
} |
|
|
169 |
my $xslh = Koha::XSLT_Handler->new; |
167 |
|
170 |
|
168 |
my $nremaining = $s; |
171 |
my $nremaining = $s; |
169 |
while ( $nremaining-- ) { |
172 |
while ( $nremaining-- ) { |
Lines 185-201
sub Z3950Search {
Link Here
|
185 |
else { |
188 |
else { |
186 |
my $numresults = $oResult[$k]->size(); |
189 |
my $numresults = $oResult[$k]->size(); |
187 |
my $i; |
190 |
my $i; |
188 |
my $result = ''; |
191 |
my $res; |
189 |
if ( $numresults > 0 and $numresults >= (($page-1)*20)) { |
192 |
if ( $numresults > 0 and $numresults >= (($page-1)*20)) { |
190 |
$show_next = 1 if $numresults >= ($page*20); |
193 |
$show_next = 1 if $numresults >= ($page*20); |
191 |
$total_pages = int($numresults/20)+1 if $total_pages < ($numresults/20); |
194 |
$total_pages = int($numresults/20)+1 if $total_pages < ($numresults/20); |
192 |
for ($i = ($page-1)*20; $i < (($numresults < ($page*20)) ? $numresults : ($page*20)); $i++) { |
195 |
for ($i = ($page-1)*20; $i < (($numresults < ($page*20)) ? $numresults : ($page*20)); $i++) { |
193 |
if($oResult[$k]->record($i)) { |
196 |
if ( $oResult[$k]->record($i) ) { |
194 |
my $res=_handle_one_result($oResult[$k]->record($i), $servers[$k], ++$imported, $biblionumber); #ignores error in sequence numbering |
197 |
undef $error; |
|
|
198 |
( $res, $error ) = _handle_one_result( $oResult[$k]->record($i), $servers[$k], ++$imported, $biblionumber, $xslh ); #ignores error in sequence numbering |
195 |
push @breeding_loop, $res if $res; |
199 |
push @breeding_loop, $res if $res; |
|
|
200 |
push @errconn, { server => $servers[$k]->{servername}, error => $error, seq => $i+1 } if $error; |
196 |
} |
201 |
} |
197 |
else { |
202 |
else { |
198 |
push(@breeding_loop,{'server'=>$servers[$k]->{servername},'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'biblionumber'=>-1}); |
203 |
push @errconn, { 'server' => $servers[$k]->{servername}, error => ( ( $oConnection[$k]->error_x() )[0] ), seq => $i+1 }; |
199 |
} |
204 |
} |
200 |
} |
205 |
} |
201 |
} #if $numresults |
206 |
} #if $numresults |
Lines 258-264
sub _build_query {
Link Here
|
258 |
} |
263 |
} |
259 |
|
264 |
|
260 |
sub _handle_one_result { |
265 |
sub _handle_one_result { |
261 |
my ($zoomrec, $servhref, $seq, $bib)= @_; |
266 |
my ( $zoomrec, $servhref, $seq, $bib, $xslh )= @_; |
262 |
|
267 |
|
263 |
my $raw= $zoomrec->raw(); |
268 |
my $raw= $zoomrec->raw(); |
264 |
my $marcrecord; |
269 |
my $marcrecord; |
Lines 269-274
sub _handle_one_result {
Link Here
|
269 |
($marcrecord) = MarcToUTF8Record($raw, C4::Context->preference('marcflavour'), $servhref->{encoding} // "iso-5426" ); #ignores charset return values |
274 |
($marcrecord) = MarcToUTF8Record($raw, C4::Context->preference('marcflavour'), $servhref->{encoding} // "iso-5426" ); #ignores charset return values |
270 |
} |
275 |
} |
271 |
SetUTF8Flag($marcrecord); |
276 |
SetUTF8Flag($marcrecord); |
|
|
277 |
my $error; |
278 |
( $marcrecord, $error ) = _do_xslt_proc($marcrecord, $servhref, $xslh); |
272 |
|
279 |
|
273 |
my $batch_id = GetZ3950BatchId($servhref->{servername}); |
280 |
my $batch_id = GetZ3950BatchId($servhref->{servername}); |
274 |
my $breedingid = AddBiblioToBatch($batch_id, $seq, $marcrecord, 'UTF-8', 0, 0); |
281 |
my $breedingid = AddBiblioToBatch($batch_id, $seq, $marcrecord, 'UTF-8', 0, 0); |
Lines 279-290
sub _handle_one_result {
Link Here
|
279 |
|
286 |
|
280 |
#call to TransformMarcToKoha replaced by next call |
287 |
#call to TransformMarcToKoha replaced by next call |
281 |
#we only need six fields from the marc record |
288 |
#we only need six fields from the marc record |
282 |
return _add_rowdata( |
289 |
my $row; |
|
|
290 |
$row = _add_rowdata( |
283 |
{ |
291 |
{ |
284 |
biblionumber => $bib, |
292 |
biblionumber => $bib, |
285 |
server => $servhref->{servername}, |
293 |
server => $servhref->{servername}, |
286 |
breedingid => $breedingid, |
294 |
breedingid => $breedingid, |
287 |
}, $marcrecord) if $breedingid; |
295 |
}, $marcrecord) if $breedingid; |
|
|
296 |
return ( $row, $error ); |
297 |
} |
298 |
|
299 |
sub _do_xslt_proc { |
300 |
my ( $marc, $server, $xslh ) = @_; |
301 |
return $marc if !$server->{add_xslt}; |
302 |
|
303 |
my $htdocs = C4::Context->config('intrahtdocs'); |
304 |
my $theme = C4::Context->preference("template"); #staff |
305 |
my $lang = C4::Languages::getlanguage() || 'en'; |
306 |
|
307 |
my @files= split ',', $server->{add_xslt}; |
308 |
my $xml = $marc->as_xml; |
309 |
foreach my $f ( @files ) { |
310 |
$f =~ s/^\s+//; $f =~ s/\s+$//; next if !$f; |
311 |
$f = C4::XSLT::_get_best_default_xslt_filename( |
312 |
$htdocs, $theme, $lang, $f ) unless $f =~ /^\//; |
313 |
$xml = $xslh->transform( $xml, $f ); |
314 |
last if $xslh->err; #skip other files |
315 |
} |
316 |
if( !$xslh->err ) { |
317 |
return MARC::Record->new_from_xml($xml, 'UTF-8'); |
318 |
} else { |
319 |
return ( $marc, 'xslt_err' ); #original record in case of errors |
320 |
} |
288 |
} |
321 |
} |
289 |
|
322 |
|
290 |
sub _add_rowdata { |
323 |
sub _add_rowdata { |