View | Details | Raw Unified | Return to bug 10462
Collapse All | Expand All

(-)a/C4/Breeding.pm (-57 / +71 lines)
Lines 228-239 The second parameter $template is a Template object. The routine uses this param Link Here
228
sub Z3950Search {
228
sub Z3950Search {
229
    my ($pars, $template)= @_;
229
    my ($pars, $template)= @_;
230
230
231
    my $dbh   = C4::Context->dbh;
232
    my @id= @{$pars->{id}};
231
    my @id= @{$pars->{id}};
233
    my $random= $pars->{random};
234
    my $page= $pars->{page};
232
    my $page= $pars->{page};
235
    my $biblionumber= $pars->{biblionumber};
233
    my $biblionumber= $pars->{biblionumber};
236
237
    my $isbn= $pars->{isbn};
234
    my $isbn= $pars->{isbn};
238
    my $issn= $pars->{issn};
235
    my $issn= $pars->{issn};
239
    my $title= $pars->{title};
236
    my $title= $pars->{title};
Lines 248-276 sub Z3950Search { Link Here
248
245
249
    my $show_next       = 0;
246
    my $show_next       = 0;
250
    my $total_pages     = 0;
247
    my $total_pages     = 0;
251
252
    my $attr = '';
253
    my $term;
248
    my $term;
254
    my $host;
255
    my $server;
256
    my $database;
257
    my $port;
258
    my $marcdata;
259
    my @encoding;
260
    my @results;
249
    my @results;
261
    my $count;
262
    my $record;
263
    my $oldbiblio;
264
    my @serverhost;
265
    my @servername;
266
    my @breeding_loop = ();
250
    my @breeding_loop = ();
267
268
    my @oConnection;
251
    my @oConnection;
269
    my @oResult;
252
    my @oResult;
270
    my @errconn;
253
    my @errconn;
271
    my $s = 0;
254
    my $s = 0;
272
    my $query;
255
    my $query;
273
    my $nterms=0;
256
    my $nterms=0;
257
    my $imported=0;
258
    my @serverinfo; #replaces former serverhost, servername, encoding
259
274
    if ($isbn) {
260
    if ($isbn) {
275
        $term=$isbn;
261
        $term=$isbn;
276
        $query .= " \@attr 1=7 \@attr 5=1 \"$term\" ";
262
        $query .= " \@attr 1=7 \@attr 5=1 \"$term\" ";
Lines 321-344 sub Z3950Search { Link Here
321
        $query = "\@and " . $query;
307
        $query = "\@and " . $query;
322
    }
308
    }
323
309
310
    my $dbh   = C4::Context->dbh;
324
    foreach my $servid (@id) {
311
    foreach my $servid (@id) {
325
        my $sth = $dbh->prepare("select * from z3950servers where id=?");
312
        my $sth = $dbh->prepare("select * from z3950servers where id=?");
326
        $sth->execute($servid);
313
        $sth->execute($servid);
327
        while ( $server = $sth->fetchrow_hashref ) {
314
        while (my $server = $sth->fetchrow_hashref) {
328
            my $option1      = new ZOOM::Options();
315
            my $option1= new ZOOM::Options();
329
            $option1->option( 'async' => 1 );
316
            $option1->option( 'async' => 1 );
330
            $option1->option( 'elementSetName', 'F' );
317
            $option1->option( 'elementSetName', 'F' );
331
            $option1->option( 'databaseName',   $server->{db} );
318
            $option1->option( 'databaseName',   $server->{db} );
332
            $option1->option( 'user', $server->{userid} ) if $server->{userid};
319
            $option1->option( 'user', $server->{userid} ) if $server->{userid};
333
            $option1->option( 'password', $server->{password} )
320
            $option1->option( 'password', $server->{password} ) if $server->{password};
334
              if $server->{password};
335
            $option1->option( 'preferredRecordSyntax', $server->{syntax} );
321
            $option1->option( 'preferredRecordSyntax', $server->{syntax} );
336
            $option1->option( 'timeout', $server->{timeout} ) if $server->{timeout};
322
            $option1->option( 'timeout', $server->{timeout} ) if $server->{timeout};
337
            $oConnection[$s] = create ZOOM::Connection($option1);
323
            $oConnection[$s]= create ZOOM::Connection($option1);
338
            $oConnection[$s]->connect( $server->{host}, $server->{port} );
324
            $oConnection[$s]->connect( $server->{host}, $server->{port} );
339
            $serverhost[$s] = $server->{host};
325
            $serverinfo[$s]->{host}= $server->{host};
340
            $servername[$s] = $server->{name};
326
            $serverinfo[$s]->{name}= $server->{name};
341
            $encoding[$s]   = ($server->{encoding}?$server->{encoding}:"iso-5426");
327
            $serverinfo[$s]->{encd}= $server->{encoding} // "iso-5426";
342
            $s++;
328
            $s++;
343
        }    ## while fetch
329
        }    ## while fetch
344
    }    # foreach
330
    }    # foreach
Lines 358-367 sub Z3950Search { Link Here
358
344
359
        if ( $k != 0 ) {
345
        if ( $k != 0 ) {
360
            $k--;
346
            $k--;
361
            my ($error, $errmsg, $addinfo, $diagset)= $oConnection[$k]->error_x();
347
            my ($error)= $oConnection[$k]->error_x(); #ignores errmsg, addinfo, diagset
362
            if ($error) {
348
            if ($error) {
363
                if ($error =~ m/^(10000|10007)$/ ) {
349
                if ($error =~ m/^(10000|10007)$/ ) {
364
                    push(@errconn, {'server' => $serverhost[$k]});
350
                    push(@errconn, { 'server' => $serverinfo[$k]->{host} } );
365
                }
351
                }
366
            }
352
            }
367
            else {
353
            else {
Lines 372-409 sub Z3950Search { Link Here
372
                    $show_next = 1 if $numresults >= ($page*20);
358
                    $show_next = 1 if $numresults >= ($page*20);
373
                    $total_pages = int($numresults/20)+1 if $total_pages < ($numresults/20);
359
                    $total_pages = int($numresults/20)+1 if $total_pages < ($numresults/20);
374
                    for ($i = ($page-1)*20; $i < (($numresults < ($page*20)) ? $numresults : ($page*20)); $i++) {
360
                    for ($i = ($page-1)*20; $i < (($numresults < ($page*20)) ? $numresults : ($page*20)); $i++) {
375
                        my $rec = $oResult[$k]->record($i);
361
                        if($oResult[$k]->record($i)) {
376
                        if ($rec) {
362
                            my $res=_handle_one_result($oResult[$k]->record($i), $serverinfo[$k], ++$imported, $biblionumber); #ignores error in sequence numbering
377
                            my $marcrecord;
363
                            push @breeding_loop, $res if $res;
378
                            $marcdata   = $rec->raw();
379
                            my ($charset_result, $charset_errors);
380
                            ($marcrecord, $charset_result, $charset_errors)= MarcToUTF8Record($marcdata, C4::Context->preference('marcflavour'), $encoding[$k]);
381
                            # Normalize the record so it doesn't have separated diacritics
382
                            SetUTF8Flag($marcrecord);
383
                            my $oldbiblio = TransformMarcToKoha( $dbh, $marcrecord, "" );
384
                            $oldbiblio->{isbn}   =~ s/ |-|\.//g if $oldbiblio->{isbn};
385
                            # pad | and ( with spaces to allow line breaks in the HTML
386
                            $oldbiblio->{isbn} =~ s/\|/ \| /g if $oldbiblio->{isbn};
387
                            $oldbiblio->{isbn} =~ s/\(/ \(/g if $oldbiblio->{isbn};
388
                            $oldbiblio->{issn} =~ s/ |-|\.//g if $oldbiblio->{issn};
389
                            # pad | and ( with spaces to allow line breaks in the HTML
390
                            $oldbiblio->{issn} =~ s/\|/ \| /g if $oldbiblio->{issn};
391
                            $oldbiblio->{issn} =~ s/\(/ \(/g if $oldbiblio->{issn};
392
                            my ($notmarcrecord, $alreadyindb, $alreadyinfarm, $imported, $breedingid)= ImportBreeding( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950' );
393
                            my %row_data;
394
                            $row_data{server}       = $servername[$k];
395
                            $row_data{isbn}         = $oldbiblio->{isbn};
396
                            $row_data{lccn}         = $oldbiblio->{lccn};
397
                            $row_data{title}        = $oldbiblio->{title};
398
                            $row_data{author}       = $oldbiblio->{author};
399
                            $row_data{date}         = $oldbiblio->{copyrightdate};
400
                            $row_data{edition}      = $oldbiblio->{editionstatement};
401
                            $row_data{breedingid}   = $breedingid;
402
                            $row_data{biblionumber} = $biblionumber;
403
                            push( @breeding_loop, \%row_data );
404
                        }
364
                        }
405
                        else {
365
                        else {
406
                            push(@breeding_loop,{'server'=>$servername[$k],'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'biblionumber'=>-1});
366
                            push(@breeding_loop,{'server'=>$serverinfo[$k]->{name},'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'biblionumber'=>-1});
407
                        }
367
                        }
408
                    }
368
                    }
409
                }    #if $numresults
369
                }    #if $numresults
Lines 436-441 sub Z3950Search { Link Here
436
    );
396
    );
437
}
397
}
438
398
399
sub _handle_one_result {
400
    my ($zoomrec, $servhref, $seq, $bib)= @_;
401
402
    my $raw= $zoomrec->raw();
403
    my ($marcrecord) = MarcToUTF8Record($raw, C4::Context->preference('marcflavour'), $servhref->{encd}); #ignores charset return values
404
    SetUTF8Flag($marcrecord);
405
406
    #call to ImportBreeding replaced by next two calls for optimization
407
    my $batch_id = GetZ3950BatchId($servhref->{name});
408
    my $breedingid = AddBiblioToBatch($batch_id, $seq, $marcrecord, 'UTF-8', 0, 0);
409
        #FIXME passing 0 for z3950random
410
        #Will eliminate this unused field in a followup report
411
        #Last zero indicates: no update for batch record counts
412
413
414
    #call to TransformMarcToKoha replaced by next call
415
    #we only need six fields from the marc record
416
    return _add_rowdata(
417
        {
418
            biblionumber => $bib,
419
            server       => $servhref->{name},
420
            breedingid   => $breedingid,
421
        }, $marcrecord) if $breedingid;
422
}
423
424
sub _add_rowdata {
425
    my ($rowref, $marcrecord)=@_;
426
    if(C4::Context->preference("marcflavour") ne 'UNIMARC') { #MARC21, NORMARC
427
        $rowref->{isbn} = _isbn_cleanup($marcrecord->subfield('020','a')||'');
428
        $rowref->{title}= $marcrecord->subfield('245','a')||'';
429
        $rowref->{author}= $marcrecord->subfield('100','a')||'';
430
        $rowref->{date}= $marcrecord->subfield('260','c')||'';
431
        $rowref->{edition}= $marcrecord->subfield('250','a')||'';
432
        $rowref->{lccn}= $marcrecord->subfield('050','a')||'';
433
    }
434
    else { #UNIMARC
435
        $rowref->{isbn}= _isbn_cleanup($marcrecord->subfield('010','a')||'');
436
        $rowref->{title}= $marcrecord->subfield('200','a')||'';
437
        $rowref->{author}= $marcrecord->subfield('200','f')||'';
438
        $rowref->{date}= $marcrecord->subfield('210','d')||'';
439
        $rowref->{edition}= $marcrecord->subfield('205','a')||'';
440
        $rowref->{lccn}= '';
441
    }
442
    return $rowref;
443
}
444
445
sub _isbn_cleanup {
446
    my $isbn= shift;
447
    $isbn=~ s/ |-|\.//g;
448
    $isbn=~ s/\|/ \| /g;
449
    $isbn=~ s/\(/ \(/g;
450
    return $isbn;
451
}
452
439
1;
453
1;
440
__END__
454
__END__
441
455
(-)a/acqui/z3950_search.pl (-1 lines)
Lines 112-118 if (@id==0) { Link Here
112
}
112
}
113
113
114
my $pars= {
114
my $pars= {
115
        random => $input->param('random') || rand(1000000000),
116
        biblionumber => $biblionumber,
115
        biblionumber => $biblionumber,
117
        page => $page,
116
        page => $page,
118
        id => \@id,
117
        id => \@id,
(-)a/cataloguing/z3950_search.pl (-2 lines)
Lines 94-100 if ( @id==0 ) { Link Here
94
}
94
}
95
95
96
my $pars= {
96
my $pars= {
97
        random => $input->param('random') || rand(1000000000),
98
        biblionumber => $biblionumber,
97
        biblionumber => $biblionumber,
99
        page => $page,
98
        page => $page,
100
        id => \@id,
99
        id => \@id,
101
- 

Return to bug 10462