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

(-)a/C4/Breeding.pm (-1 / +11 lines)
Lines 477-488 sub ImportBreedingAuth { Link Here
477
    my $batch_id = GetZ3950BatchId($filename);
477
    my $batch_id = GetZ3950BatchId($filename);
478
    my $searchbreeding = $dbh->prepare("select import_record_id from import_auths where control_number=? and authorized_heading=?");
478
    my $searchbreeding = $dbh->prepare("select import_record_id from import_auths where control_number=? and authorized_heading=?");
479
479
480
    my $marc_type = C4::Context->preference('marcflavour');
480
    my $controlnumber = $marcrecord->field('001')->data;
481
    my $controlnumber = $marcrecord->field('001')->data;
481
482
482
    $searchbreeding->execute($controlnumber,$heading);
483
    $searchbreeding->execute($controlnumber,$heading);
483
    my ($breedingid) = $searchbreeding->fetchrow;
484
    my ($breedingid) = $searchbreeding->fetchrow;
484
485
485
    return $breedingid if $breedingid;
486
    if ($breedingid) {
487
        my $updbrd = $dbh->prepare("update import_records set marc=?,marcxml=? where import_record_id=?");
488
        $updbrd->execute( $marcrecord->as_usmarc(), $marcrecord->as_xml($marc_type), $breedingid );
489
        $updbrd->finish();
490
        return $breedingid;
491
    }
486
    $breedingid = AddAuthToBatch($batch_id, 0, $marcrecord, $encoding);
492
    $breedingid = AddAuthToBatch($batch_id, 0, $marcrecord, $encoding);
487
    return $breedingid;
493
    return $breedingid;
488
}
494
}
Lines 520-525 sub Z3950SearchAuth { Link Here
520
    my $query;
526
    my $query;
521
    my $nterms=0;
527
    my $nterms=0;
522
528
529
    my $xslh = Koha::XSLT::Base->new;
523
    my $marcflavour = C4::Context->preference('marcflavour');
530
    my $marcflavour = C4::Context->preference('marcflavour');
524
    my $marc_type = $marcflavour eq 'UNIMARC' ? 'UNIMARCAUTH' : $marcflavour;
531
    my $marc_type = $marcflavour eq 'UNIMARC' ? 'UNIMARCAUTH' : $marcflavour;
525
    my $authid= $pars->{authid};
532
    my $authid= $pars->{authid};
Lines 594-599 sub Z3950SearchAuth { Link Here
594
                            $marcrecord->encoding('UTF-8');
601
                            $marcrecord->encoding('UTF-8');
595
                            SetUTF8Flag($marcrecord);
602
                            SetUTF8Flag($marcrecord);
596
603
604
                            my $error;
605
                            ( $marcrecord, $error ) = _do_xslt_proc( $marcrecord, $servers[$k], $xslh );
606
597
                            my $heading_authtype_code = GuessAuthTypeCode($marcrecord) or next;
607
                            my $heading_authtype_code = GuessAuthTypeCode($marcrecord) or next;
598
                            my $heading = GetAuthorizedHeading({ record => $marcrecord });
608
                            my $heading = GetAuthorizedHeading({ record => $marcrecord });
599
                            my $breedingid = ImportBreedingAuth( $marcrecord, $servers[$k]->{host}, 'UTF-8', $heading );
609
                            my $breedingid = ImportBreedingAuth( $marcrecord, $servers[$k]->{host}, 'UTF-8', $heading );
(-)a/t/db_dependent/Breeding_Auth.t (-2 / +22 lines)
Lines 91-97 sub mock_objects { Link Here
91
$schema->storage->txn_begin;
91
$schema->storage->txn_begin;
92
92
93
subtest ImportBreedingAuth => sub {
93
subtest ImportBreedingAuth => sub {
94
    plan tests => 4;
94
    plan tests => 6;
95
    my $dbh = C4::Context->dbh;
95
96
96
    my $record = MARC::Record->new();
97
    my $record = MARC::Record->new();
97
    $record->append_fields(
98
    $record->append_fields(
Lines 101-108 subtest ImportBreedingAuth => sub { Link Here
101
102
102
    my $breedingid = C4::Breeding::ImportBreedingAuth( $record, "kidclamp", "UTF-8", 'Jansson, Tove' );
103
    my $breedingid = C4::Breeding::ImportBreedingAuth( $record, "kidclamp", "UTF-8", 'Jansson, Tove' );
103
    ok( $breedingid, "We got a breeding id back" );
104
    ok( $breedingid, "We got a breeding id back" );
105
104
    my $breedingid_1 = C4::Breeding::ImportBreedingAuth( $record, "kidclamp", "UTF-8", 'Jansson, Tove' );
106
    my $breedingid_1 = C4::Breeding::ImportBreedingAuth( $record, "kidclamp", "UTF-8", 'Jansson, Tove' );
105
    is( $breedingid, $breedingid_1, "For the same record, we get the same id" );
107
    is( $breedingid, $breedingid_1, "For the same record, we get the same id" );
108
109
    # Bug 19220: In case of XSLT transformation, we make sure to have the new version of the record
110
    $record->append_fields(
111
        MARC::Field->new( '999', ' ', ' ', a => 'Added field' ),
112
    );
113
114
    $breedingid_1 = C4::Breeding::ImportBreedingAuth( $record, "kidclamp", "UTF-8", 'Jansson, Tove' );
115
    is( $breedingid, $breedingid_1, "For the same record, modified, we get the same id" );
116
117
    my $sth = $dbh->prepare('SELECT * FROM import_records WHERE import_record_id = ?');
118
    $sth->execute($breedingid);
119
    my $imported_records_record = $sth->fetchrow_hashref();
120
    my $imported_record         = MARC::Record::new_from_xml( $imported_records_record->{marcxml} );
121
    is(
122
        $imported_record->subfield( '999', 'a' ), $record->subfield( '999', 'a' ),
123
        'We also get the new the version of the record'
124
    );
125
    # End Bug 19220
126
106
    $breedingid_1 = C4::Breeding::ImportBreedingAuth( $record, "marcelr", "UTF-8", 'Jansson, Tove' );
127
    $breedingid_1 = C4::Breeding::ImportBreedingAuth( $record, "marcelr", "UTF-8", 'Jansson, Tove' );
107
    is( $breedingid, $breedingid_1, "For the same record in a different file, we get a new id" );
128
    is( $breedingid, $breedingid_1, "For the same record in a different file, we get a new id" );
108
    my $record_1 = MARC::Record->new();
129
    my $record_1 = MARC::Record->new();
109
- 

Return to bug 19220