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

(-)a/C4/Breeding.pm (-1 / +11 lines)
Lines 503-514 sub ImportBreedingAuth { Link Here
503
    my $searchbreeding =
503
    my $searchbreeding =
504
        $dbh->prepare("select import_record_id from import_auths where control_number=? and authorized_heading=?");
504
        $dbh->prepare("select import_record_id from import_auths where control_number=? and authorized_heading=?");
505
505
506
    my $marc_type     = C4::Context->preference('marcflavour');
506
    my $controlnumber = $marcrecord->field('001')->data;
507
    my $controlnumber = $marcrecord->field('001')->data;
507
508
508
    $searchbreeding->execute( $controlnumber, $heading );
509
    $searchbreeding->execute( $controlnumber, $heading );
509
    my ($breedingid) = $searchbreeding->fetchrow;
510
    my ($breedingid) = $searchbreeding->fetchrow;
510
511
511
    return $breedingid if $breedingid;
512
    if ($breedingid) {
513
        my $updbrd = $dbh->prepare("update import_records set marc=?,marcxml=? where import_record_id=?");
514
        $updbrd->execute( $marcrecord->as_usmarc(), $marcrecord->as_xml($marc_type), $breedingid );
515
        $updbrd->finish();
516
        return $breedingid;
517
    }
512
    $breedingid = AddAuthToBatch( $batch_id, 0, $marcrecord, $encoding );
518
    $breedingid = AddAuthToBatch( $batch_id, 0, $marcrecord, $encoding );
513
    return $breedingid;
519
    return $breedingid;
514
}
520
}
Lines 545-550 sub Z3950SearchAuth { Link Here
545
    my $query;
551
    my $query;
546
    my $nterms = 0;
552
    my $nterms = 0;
547
553
554
    my $xslh        = Koha::XSLT::Base->new;
548
    my $marcflavour = C4::Context->preference('marcflavour');
555
    my $marcflavour = C4::Context->preference('marcflavour');
549
    my $marc_type   = $marcflavour eq 'UNIMARC' ? 'UNIMARCAUTH' : $marcflavour;
556
    my $marc_type   = $marcflavour eq 'UNIMARC' ? 'UNIMARCAUTH' : $marcflavour;
550
    my $authid      = $pars->{authid};
557
    my $authid      = $pars->{authid};
Lines 626-631 sub Z3950SearchAuth { Link Here
626
                            $marcrecord->encoding('UTF-8');
633
                            $marcrecord->encoding('UTF-8');
627
                            SetUTF8Flag($marcrecord);
634
                            SetUTF8Flag($marcrecord);
628
635
636
                            my $error;
637
                            ( $marcrecord, $error ) = _do_xslt_proc( $marcrecord, $servers[$k], $xslh );
638
629
                            my $heading_authtype_code = GuessAuthTypeCode($marcrecord) or next;
639
                            my $heading_authtype_code = GuessAuthTypeCode($marcrecord) or next;
630
                            my $heading               = GetAuthorizedHeading( { record => $marcrecord } );
640
                            my $heading               = GetAuthorizedHeading( { record => $marcrecord } );
631
                            my $breedingid = ImportBreedingAuth( $marcrecord, $servers[$k]->{host}, 'UTF-8', $heading );
641
                            my $breedingid = ImportBreedingAuth( $marcrecord, $servers[$k]->{host}, 'UTF-8', $heading );
(-)a/t/db_dependent/Breeding_Auth.t (-4 / +24 lines)
Lines 22-29 Link Here
22
use Modern::Perl;
22
use Modern::Perl;
23
use utf8;
23
use utf8;
24
24
25
use Test::NoWarnings;
25
use Test::More tests => 2;
26
use Test::More tests => 3;
27
use Test::MockModule;
26
use Test::MockModule;
28
use Test::MockObject;
27
use Test::MockObject;
29
use Test::Warn;
28
use Test::Warn;
Lines 92-98 sub mock_objects { Link Here
92
$schema->storage->txn_begin;
91
$schema->storage->txn_begin;
93
92
94
subtest ImportBreedingAuth => sub {
93
subtest ImportBreedingAuth => sub {
95
    plan tests => 4;
94
    plan tests => 6;
95
    my $dbh = C4::Context->dbh;
96
96
97
    my $record = MARC::Record->new();
97
    my $record = MARC::Record->new();
98
    $record->append_fields(
98
    $record->append_fields(
Lines 102-109 subtest ImportBreedingAuth => sub { Link Here
102
102
103
    my $breedingid = C4::Breeding::ImportBreedingAuth( $record, "kidclamp", "UTF-8", 'Jansson, Tove' );
103
    my $breedingid = C4::Breeding::ImportBreedingAuth( $record, "kidclamp", "UTF-8", 'Jansson, Tove' );
104
    ok( $breedingid, "We got a breeding id back" );
104
    ok( $breedingid, "We got a breeding id back" );
105
105
    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' );
106
    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
126
    # End Bug 19220
127
107
    $breedingid_1 = C4::Breeding::ImportBreedingAuth( $record, "marcelr", "UTF-8", 'Jansson, Tove' );
128
    $breedingid_1 = C4::Breeding::ImportBreedingAuth( $record, "marcelr", "UTF-8", 'Jansson, Tove' );
108
    is( $breedingid, $breedingid_1, "For the same record in a different file, we get a new id" );
129
    is( $breedingid, $breedingid_1, "For the same record in a different file, we get a new id" );
109
    my $record_1 = MARC::Record->new();
130
    my $record_1 = MARC::Record->new();
110
- 

Return to bug 19220