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

(-)a/C4/Breeding.pm (-42 / +24 lines)
Lines 48-54 C4::Breeding : module to add biblios to import_records via Link Here
48
=head1 SYNOPSIS
48
=head1 SYNOPSIS
49
49
50
    Z3950Search($pars, $template);
50
    Z3950Search($pars, $template);
51
    ($count, @results) = &BreedingSearch($title,$isbn,$random);
51
    ($count, @results) = &BreedingSearch($title,$isbn);
52
52
53
=head1 DESCRIPTION
53
=head1 DESCRIPTION
54
54
Lines 57-66 cataloguing reservoir features. Link Here
57
57
58
=head2 BreedingSearch
58
=head2 BreedingSearch
59
59
60
($count, @results) = &BreedingSearch($title,$isbn,$random);
60
($count, @results) = &BreedingSearch($title,$isbn);
61
C<$title> contains the title,
61
C<$title> contains the title,
62
C<$isbn> contains isbn or issn,
62
C<$isbn> contains isbn or issn,
63
C<$random> contains the random seed from a z3950 search.
64
63
65
C<$count> is the number of items in C<@results>. C<@results> is an
64
C<$count> is the number of items in C<@results>. C<@results> is an
66
array of references-to-hash; the keys are the items from the C<import_records> and
65
array of references-to-hash; the keys are the items from the C<import_records> and
Lines 69-75 C<import_biblios> tables of the Koha database. Link Here
69
=cut
68
=cut
70
69
71
sub BreedingSearch {
70
sub BreedingSearch {
72
    my ($search,$isbn,$z3950random) = @_;
71
    my ($search,$isbn) = @_;
73
    my $dbh   = C4::Context->dbh;
72
    my $dbh   = C4::Context->dbh;
74
    my $count = 0;
73
    my $count = 0;
75
    my ($query,@bind);
74
    my ($query,@bind);
Lines 84-108 sub BreedingSearch { Link Here
84
              JOIN import_records USING (import_record_id)
83
              JOIN import_records USING (import_record_id)
85
              JOIN import_batches USING (import_batch_id)
84
              JOIN import_batches USING (import_batch_id)
86
              WHERE ";
85
              WHERE ";
87
    if ($z3950random) {
86
    @bind=();
88
        $query .= "z3950random = ?";
87
    if (defined($search) && length($search)>0) {
89
        @bind=($z3950random);
88
        $search =~ s/(\s+)/\%/g;
90
    } else {
89
        $query .= "title like ? OR author like ?";
91
        @bind=();
90
        push(@bind,"%$search%", "%$search%");
92
        if (defined($search) && length($search)>0) {
93
            $search =~ s/(\s+)/\%/g;
94
            $query .= "title like ? OR author like ?";
95
            push(@bind,"%$search%", "%$search%");
96
        }
97
        if ($#bind!=-1 && defined($isbn) && length($isbn)>0) {
98
            $query .= " and ";
99
        }
100
        if (defined($isbn) && length($isbn)>0) {
101
            $query .= "isbn like ?";
102
            push(@bind,"$isbn%");
103
        }
104
    }
91
    }
105
    $sth   = $dbh->prepare($query);
92
    if ($#bind!=-1 && defined($isbn) && length($isbn)>0) {
93
        $query .= " and ";
94
    }
95
    if (defined($isbn) && length($isbn)>0) {
96
        $query .= "isbn like ?";
97
        push(@bind,"$isbn%");
98
    }
99
    $sth = $dbh->prepare($query);
106
    $sth->execute(@bind);
100
    $sth->execute(@bind);
107
    while (my $data = $sth->fetchrow_hashref) {
101
    while (my $data = $sth->fetchrow_hashref) {
108
            $results[$count] = $data;
102
            $results[$count] = $data;
Lines 307-315 sub _handle_one_result { Link Here
307
    ( $marcrecord, $error ) = _do_xslt_proc($marcrecord, $servhref, $xslh);
301
    ( $marcrecord, $error ) = _do_xslt_proc($marcrecord, $servhref, $xslh);
308
302
309
    my $batch_id = GetZ3950BatchId($servhref->{servername});
303
    my $batch_id = GetZ3950BatchId($servhref->{servername});
310
    my $breedingid = AddBiblioToBatch($batch_id, $seq, $marcrecord, 'UTF-8', 0, 0);
304
    my $breedingid = AddBiblioToBatch($batch_id, $seq, $marcrecord, 'UTF-8', 0);
311
        #FIXME passing 0 for z3950random
312
        #Will eliminate this unused field in a followup report
313
        #Last zero indicates: no update for batch record counts
305
        #Last zero indicates: no update for batch record counts
314
306
315
307
Lines 491-497 sub _translate_query { #SRU query adjusted per server cf. srufields column Link Here
491
483
492
=head2 ImportBreedingAuth
484
=head2 ImportBreedingAuth
493
485
494
ImportBreedingAuth($marcrecords,$overwrite_auth,$filename,$encoding,$z3950random);
486
ImportBreedingAuth($marcrecords,$overwrite_auth,$filename,$encoding);
495
487
496
    ImportBreedingAuth imports MARC records in the reservoir (import_records table).
488
    ImportBreedingAuth imports MARC records in the reservoir (import_records table).
497
    ImportBreedingAuth is based on the ImportBreeding subroutine.
489
    ImportBreedingAuth is based on the ImportBreeding subroutine.
Lines 499-505 ImportBreedingAuth($marcrecords,$overwrite_auth,$filename,$encoding,$z3950random Link Here
499
=cut
491
=cut
500
492
501
sub ImportBreedingAuth {
493
sub ImportBreedingAuth {
502
    my ($marcrecord,$overwrite_auth,$filename,$encoding,$z3950random) = @_;
494
    my ($marcrecord,$overwrite_auth,$filename,$encoding) = @_;
503
    my $dbh = C4::Context->dbh;
495
    my $dbh = C4::Context->dbh;
504
496
505
    my $batch_id = GetZ3950BatchId($filename);
497
    my $batch_id = GetZ3950BatchId($filename);
Lines 550-556 sub ImportBreedingAuth { Link Here
550
                    if ($breedingid && $overwrite_auth eq '1') {
542
                    if ($breedingid && $overwrite_auth eq '1') {
551
                        ModAuthorityInBatch($breedingid, $marcrecord);
543
                        ModAuthorityInBatch($breedingid, $marcrecord);
552
                    } else {
544
                    } else {
553
                        my $import_id = AddAuthToBatch($batch_id, $imported, $marcrecord, $encoding, $z3950random);
545
                        my $import_id = AddAuthToBatch($batch_id, $imported, $marcrecord, $encoding);
554
                        $breedingid = $import_id;
546
                        $breedingid = $import_id;
555
                    }
547
                    }
556
                    $imported++;
548
                    $imported++;
Lines 577-601 sub Z3950SearchAuth { Link Here
577
569
578
    my $dbh   = C4::Context->dbh;
570
    my $dbh   = C4::Context->dbh;
579
    my @id= @{$pars->{id}};
571
    my @id= @{$pars->{id}};
580
    my $random= $pars->{random};
581
    my $page= $pars->{page};
572
    my $page= $pars->{page};
582
573
583
574
584
    my $show_next       = 0;
575
    my $show_next       = 0;
585
    my $total_pages     = 0;
576
    my $total_pages     = 0;
586
    my $attr = '';
587
    my $host;
588
    my $server;
589
    my $database;
590
    my $port;
591
    my $marcdata;
592
    my @encoding;
577
    my @encoding;
593
    my @results;
578
    my @results;
594
    my $count;
595
    my $record;
596
    my @serverhost;
579
    my @serverhost;
597
    my @breeding_loop = ();
580
    my @breeding_loop = ();
598
599
    my @oConnection;
581
    my @oConnection;
600
    my @oResult;
582
    my @oResult;
601
    my @errconn;
583
    my @errconn;
Lines 611-617 sub Z3950SearchAuth { Link Here
611
    foreach my $servid (@id) {
593
    foreach my $servid (@id) {
612
        my $sth = $dbh->prepare("select * from z3950servers where id=?");
594
        my $sth = $dbh->prepare("select * from z3950servers where id=?");
613
        $sth->execute($servid);
595
        $sth->execute($servid);
614
        while ( $server = $sth->fetchrow_hashref ) {
596
        while ( my $server = $sth->fetchrow_hashref ) {
615
            $oConnection[$s] = _create_connection( $server );
597
            $oConnection[$s] = _create_connection( $server );
616
598
617
            $oResult[$s] =
599
            $oResult[$s] =
Lines 619-625 sub Z3950SearchAuth { Link Here
619
                $oConnection[$s]->search_pqf( $zquery ):
601
                $oConnection[$s]->search_pqf( $zquery ):
620
                $oConnection[$s]->search(new ZOOM::Query::CQL(
602
                $oConnection[$s]->search(new ZOOM::Query::CQL(
621
                    _translate_query( $server, $squery )));
603
                    _translate_query( $server, $squery )));
622
            $encoding[$s]   = ($server->{encoding}?$server->{encoding}:"iso-5426");
604
            $encoding[$s]   = $server->{encoding} // "iso-5426";
623
            $servers[$s] = $server;
605
            $servers[$s] = $server;
624
            $s++;
606
            $s++;
625
        }   ## while fetch
607
        }   ## while fetch
Lines 636-642 sub Z3950SearchAuth { Link Here
636
618
637
        if ( $k != 0 ) {
619
        if ( $k != 0 ) {
638
            $k--;
620
            $k--;
639
            my ($error, $errmsg, $addinfo, $diagset)= $oConnection[$k]->error_x();
621
            my ($error )= $oConnection[$k]->error_x(); #ignores errmsg, addinfo, diagset
640
            if ($error) {
622
            if ($error) {
641
                if ($error =~ m/^(10000|10007)$/ ) {
623
                if ($error =~ m/^(10000|10007)$/ ) {
642
                    push(@errconn, {'server' => $serverhost[$k]});
624
                    push(@errconn, {'server' => $serverhost[$k]});
Lines 667-673 sub Z3950SearchAuth { Link Here
667
                            $heading_authtype_code = GuessAuthTypeCode($marcrecord);
649
                            $heading_authtype_code = GuessAuthTypeCode($marcrecord);
668
                            $heading = C4::AuthoritiesMarc::GetAuthorizedHeading({ record => $marcrecord });
650
                            $heading = C4::AuthoritiesMarc::GetAuthorizedHeading({ record => $marcrecord });
669
651
670
                            my ($notmarcrecord, $alreadyindb, $alreadyinfarm, $imported, $breedingid)= ImportBreedingAuth( $marcrecord, 2, $serverhost[$k], $encoding[$k], $random);
652
                            my ($notmarcrecord, $alreadyindb, $alreadyinfarm, $imported, $breedingid)= ImportBreedingAuth( $marcrecord, 2, $serverhost[$k], $encoding[$k]);
671
                            my %row_data;
653
                            my %row_data;
672
                            $row_data{server}       = $servers[$k]->{'servername'};
654
                            $row_data{server}       = $servers[$k]->{'servername'};
673
                            $row_data{breedingid}   = $breedingid;
655
                            $row_data{breedingid}   = $breedingid;
(-)a/C4/ImportBatch.pm (-10 / +8 lines)
Lines 279-285 sub GetImportBatch { Link Here
279
=head2 AddBiblioToBatch 
279
=head2 AddBiblioToBatch 
280
280
281
  my $import_record_id = AddBiblioToBatch($batch_id, $record_sequence, 
281
  my $import_record_id = AddBiblioToBatch($batch_id, $record_sequence, 
282
                $marc_record, $encoding, $z3950random, $update_counts);
282
                $marc_record, $encoding, $update_counts);
283
283
284
=cut
284
=cut
285
285
Lines 288-297 sub AddBiblioToBatch { Link Here
288
    my $record_sequence = shift;
288
    my $record_sequence = shift;
289
    my $marc_record = shift;
289
    my $marc_record = shift;
290
    my $encoding = shift;
290
    my $encoding = shift;
291
    my $z3950random = shift;
292
    my $update_counts = @_ ? shift : 1;
291
    my $update_counts = @_ ? shift : 1;
293
292
294
    my $import_record_id = _create_import_record($batch_id, $record_sequence, $marc_record, 'biblio', $encoding, $z3950random, C4::Context->preference('marcflavour'));
293
    my $import_record_id = _create_import_record($batch_id, $record_sequence, $marc_record, 'biblio', $encoding, C4::Context->preference('marcflavour'));
295
    _add_biblio_fields($import_record_id, $marc_record);
294
    _add_biblio_fields($import_record_id, $marc_record);
296
    _update_batch_record_counts($batch_id) if $update_counts;
295
    _update_batch_record_counts($batch_id) if $update_counts;
297
    return $import_record_id;
296
    return $import_record_id;
Lines 314-320 sub ModBiblioInBatch { Link Here
314
=head2 AddAuthToBatch
313
=head2 AddAuthToBatch
315
314
316
  my $import_record_id = AddAuthToBatch($batch_id, $record_sequence,
315
  my $import_record_id = AddAuthToBatch($batch_id, $record_sequence,
317
                $marc_record, $encoding, $z3950random, $update_counts, [$marc_type]);
316
                $marc_record, $encoding, $update_counts, [$marc_type]);
318
317
319
=cut
318
=cut
320
319
Lines 323-335 sub AddAuthToBatch { Link Here
323
    my $record_sequence = shift;
322
    my $record_sequence = shift;
324
    my $marc_record = shift;
323
    my $marc_record = shift;
325
    my $encoding = shift;
324
    my $encoding = shift;
326
    my $z3950random = shift;
327
    my $update_counts = @_ ? shift : 1;
325
    my $update_counts = @_ ? shift : 1;
328
    my $marc_type = shift || C4::Context->preference('marcflavour');
326
    my $marc_type = shift || C4::Context->preference('marcflavour');
329
327
330
    $marc_type = 'UNIMARCAUTH' if $marc_type eq 'UNIMARC';
328
    $marc_type = 'UNIMARCAUTH' if $marc_type eq 'UNIMARC';
331
329
332
    my $import_record_id = _create_import_record($batch_id, $record_sequence, $marc_record, 'auth', $encoding, $z3950random, $marc_type);
330
    my $import_record_id = _create_import_record($batch_id, $record_sequence, $marc_record, 'auth', $encoding, $marc_type);
333
    _add_auth_fields($import_record_id, $marc_record);
331
    _add_auth_fields($import_record_id, $marc_record);
334
    _update_batch_record_counts($batch_id) if $update_counts;
332
    _update_batch_record_counts($batch_id) if $update_counts;
335
    return $import_record_id;
333
    return $import_record_id;
Lines 1593-1606 sub RecordsFromMarcPlugin { Link Here
1593
# internal functions
1591
# internal functions
1594
1592
1595
sub _create_import_record {
1593
sub _create_import_record {
1596
    my ($batch_id, $record_sequence, $marc_record, $record_type, $encoding, $z3950random, $marc_type) = @_;
1594
    my ($batch_id, $record_sequence, $marc_record, $record_type, $encoding, $marc_type) = @_;
1597
1595
1598
    my $dbh = C4::Context->dbh;
1596
    my $dbh = C4::Context->dbh;
1599
    my $sth = $dbh->prepare("INSERT INTO import_records (import_batch_id, record_sequence, marc, marcxml, marcxml_old,
1597
    my $sth = $dbh->prepare("INSERT INTO import_records (import_batch_id, record_sequence, marc, marcxml, marcxml_old,
1600
                                                         record_type, encoding, z3950random)
1598
                                                         record_type, encoding)
1601
                                    VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
1599
                                    VALUES (?, ?, ?, ?, ?, ?, ?)");
1602
    $sth->execute($batch_id, $record_sequence, $marc_record->as_usmarc(), $marc_record->as_xml($marc_type), '',
1600
    $sth->execute($batch_id, $record_sequence, $marc_record->as_usmarc(), $marc_record->as_xml($marc_type), '',
1603
                  $record_type, $encoding, $z3950random);
1601
                  $record_type, $encoding);
1604
    my $import_record_id = $dbh->{'mysql_insertid'};
1602
    my $import_record_id = $dbh->{'mysql_insertid'};
1605
    $sth->finish();
1603
    $sth->finish();
1606
    return $import_record_id;
1604
    return $import_record_id;
(-)a/cataloguing/z3950_auth_search.pl (-2 lines)
Lines 88-94 if ( @id==0 ) { Link Here
88
}
88
}
89
89
90
my $pars= {
90
my $pars= {
91
        random => scalar $input->param('random') || rand(1000000000),
92
        page => $page,
91
        page => $page,
93
        id => \@id,
92
        id => \@id,
94
        nameany => $nameany,
93
        nameany => $nameany,
95
- 

Return to bug 22532