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

(-)a/C4/Biblio.pm (-5 / +7 lines)
Lines 240-246 sub AddBiblio { Link Here
240
240
241
=head2 ModBiblio
241
=head2 ModBiblio
242
242
243
  ModBiblio( $record,$biblionumber,$frameworkcode);
243
  ModBiblio( $record,$biblionumber,$frameworkcode, $disable_autolink);
244
244
245
Replace an existing bib record identified by C<$biblionumber>
245
Replace an existing bib record identified by C<$biblionumber>
246
with one supplied by the MARC::Record object C<$record>.  The embedded
246
with one supplied by the MARC::Record object C<$record>.  The embedded
Lines 256-267 in the C<biblio> and C<biblioitems> tables, as well as Link Here
256
which fields are used to store embedded item, biblioitem,
256
which fields are used to store embedded item, biblioitem,
257
and biblionumber data for indexing.
257
and biblionumber data for indexing.
258
258
259
Unless C<$disable_autolink> is passed ModBiblio will relink record headings
260
to authorities based on settings in the system preferences. This flag allows
261
us to not relink records when the authority linker is saving modifications.
262
259
Returns 1 on success 0 on failure
263
Returns 1 on success 0 on failure
260
264
261
=cut
265
=cut
262
266
263
sub ModBiblio {
267
sub ModBiblio {
264
    my ( $record, $biblionumber, $frameworkcode ) = @_;
268
    my ( $record, $biblionumber, $frameworkcode, $disable_autolink ) = @_;
265
    if (!$record) {
269
    if (!$record) {
266
        carp 'No record passed to ModBiblio';
270
        carp 'No record passed to ModBiblio';
267
        return 0;
271
        return 0;
Lines 272-278 sub ModBiblio { Link Here
272
        logaction( "CATALOGUING", "MODIFY", $biblionumber, "biblio BEFORE=>" . $newrecord->as_formatted );
276
        logaction( "CATALOGUING", "MODIFY", $biblionumber, "biblio BEFORE=>" . $newrecord->as_formatted );
273
    }
277
    }
274
278
275
    if (C4::Context->preference('BiblioAddsAuthorities')) {
279
    if ( !$disable_autolink && C4::Context->preference('BiblioAddsAuthorities') ) {
276
        BiblioAutoLink( $record, $frameworkcode );
280
        BiblioAutoLink( $record, $frameworkcode );
277
    }
281
    }
278
282
Lines 624-635 safest place. Link Here
624
628
625
sub _check_valid_auth_link {
629
sub _check_valid_auth_link {
626
    my ( $authid, $field ) = @_;
630
    my ( $authid, $field ) = @_;
627
628
    require C4::AuthoritiesMarc;
631
    require C4::AuthoritiesMarc;
629
632
630
    my $authorized_heading =
633
    my $authorized_heading =
631
      C4::AuthoritiesMarc::GetAuthorizedHeading( { 'authid' => $authid } ) || '';
634
      C4::AuthoritiesMarc::GetAuthorizedHeading( { 'authid' => $authid } ) || '';
632
633
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
635
   return ($field->as_string('abcdefghijklmnopqrstuvwxyz') eq $authorized_heading);
634
}
636
}
635
637
(-)a/misc/link_bibs_to_authorities.pl (-1 / +2 lines)
Lines 221-227 sub process_bib { Link Here
221
            );
221
            );
222
        }
222
        }
223
        if ( not $test_only ) {
223
        if ( not $test_only ) {
224
            ModBiblio( $bib, $biblionumber, $frameworkcode );
224
            ModBiblio( $bib, $biblionumber, $frameworkcode, 1 );
225
            #Last param is to note ModBiblio was called from linking script and bib should not be linked again
225
            $num_bibs_modified++;
226
            $num_bibs_modified++;
226
        }
227
        }
227
    }
228
    }
(-)a/t/db_dependent/Biblio.t (-2 / +18 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 11;
20
use Test::More tests => 12;
21
use Test::MockModule;
21
use Test::MockModule;
22
use List::MoreUtils qw( uniq );
22
use List::MoreUtils qw( uniq );
23
use MARC::Record;
23
use MARC::Record;
Lines 570-575 subtest 'MarcFieldForCreatorAndModifier' => sub { Link Here
570
    is($record->subfield('998', 'd'), 'Jane Doe', '998$d = Jane Doe');
570
    is($record->subfield('998', 'd'), 'Jane Doe', '998$d = Jane Doe');
571
};
571
};
572
572
573
subtest 'ModBiblio called from linker test' => sub {
574
    plan tests => 2;
575
    my $called = 0;
576
    t::lib::Mocks::mock_preference('BiblioAddsAuthorities', 1);
577
    my $biblio_mod = Test::MockModule->new( 'C4::Biblio' );
578
    $biblio_mod->mock( 'LinkBibHeadingsToAuthorities', sub {
579
        $called = 1;
580
    });
581
    my $record = MARC::Record->new();
582
    my ($biblionumber) = C4::Biblio::AddBiblio($record,'');
583
    C4::Biblio::ModBiblio($record,$biblionumber,'');
584
    is($called,1,"We called to link bibs because not from linker");
585
    $called = 0;
586
    C4::Biblio::ModBiblio($record,$biblionumber,'',1);
587
    is($called,0,"We didn't call to link bibs because from linker");
588
};
589
573
# Cleanup
590
# Cleanup
574
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
591
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
575
$schema->storage->txn_rollback;
592
$schema->storage->txn_rollback;
576
- 

Return to bug 21957