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

(-)a/C4/Biblio.pm (-7 / +36 lines)
Lines 178-184 The MARC record (in biblio_metadata.metadata) contains the complete marc record, Link Here
178
178
179
=head2 AddBiblio
179
=head2 AddBiblio
180
180
181
  ($biblionumber,$biblioitemnumber) = AddBiblio($record,$frameworkcode);
181
    ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, $frameworkcode, $options );
182
182
183
Exported function (core API) for adding a new biblio to koha.
183
Exported function (core API) for adding a new biblio to koha.
184
184
Lines 199-204 Unless C<disable_autolink> is passed AddBiblio will link record headings Link Here
199
to authorities based on settings in the system preferences. This flag allows
199
to authorities based on settings in the system preferences. This flag allows
200
us to not link records when the authority linker is saving modifications.
200
us to not link records when the authority linker is saving modifications.
201
201
202
=item B<record_source_id>: set as the record source when saving the record
203
202
=back
204
=back
203
205
204
=cut
206
=cut
Lines 293-299 sub AddBiblio { Link Here
293
            }
295
            }
294
296
295
            # now add the record, don't index while we are in the transaction though
297
            # now add the record, don't index while we are in the transaction though
296
            ModBiblioMarc( $record, $biblionumber, { skip_record_index => 1 } );
298
            ModBiblioMarc(
299
                $record, $biblionumber,
300
                {
301
                    skip_record_index => 1,
302
                    record_source_id  => $options->{record_source_id},
303
                }
304
            );
297
305
298
            # update OAI-PMH sets
306
            # update OAI-PMH sets
299
            if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
307
            if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
Lines 360-365 task to rebuild the holds queue for the biblio if I<RealTimeHoldsQueue> is enabl Link Here
360
368
361
Used when the indexing schedulling will be handled by the caller
369
Used when the indexing schedulling will be handled by the caller
362
370
371
=item C<record_source_id>
372
373
Set as the record source when saving the record.
374
363
=back
375
=back
364
376
365
Returns 1 on success 0 on failure
377
Returns 1 on success 0 on failure
Lines 370-376 sub ModBiblio { Link Here
370
    my ( $record, $biblionumber, $frameworkcode, $options ) = @_;
382
    my ( $record, $biblionumber, $frameworkcode, $options ) = @_;
371
383
372
    $options //= {};
384
    $options //= {};
373
    my $mod_biblio_marc_options = { skip_record_index => $options->{'skip_record_index'} // 0 };
385
    my $mod_biblio_marc_options = {
386
        skip_record_index => $options->{'skip_record_index'} // 0,
387
        (
388
              ( exists $options->{record_source_id} )
389
            ? ( record_source_id => $options->{record_source_id} )
390
            : ()
391
        )
392
    };
374
393
375
    if (!$record) {
394
    if (!$record) {
376
        carp 'No record passed to ModBiblio';
395
        carp 'No record passed to ModBiblio';
Lines 2795-2801 sub _koha_delete_biblio_metadata { Link Here
2795
2814
2796
=head2 ModBiblioMarc
2815
=head2 ModBiblioMarc
2797
2816
2798
  ModBiblioMarc($newrec, $biblionumber, $options);
2817
    ModBiblioMarc( $newrec, $biblionumber, $options );
2799
2818
2800
Add MARC XML data for a biblio to koha
2819
Add MARC XML data for a biblio to koha
2801
2820
Lines 2805-2811 The C<$options> argument is a hashref with additional parameters: Link Here
2805
2824
2806
=over 4
2825
=over 4
2807
2826
2808
=item C<skip_record_index>: used when the indexing scheduling will be handled by the caller
2827
=item B<skip_record_index>: used when the indexing scheduling will be handled by the caller
2828
2829
=item B<record_source_id>: set as the record source when saving the record
2809
2830
2810
=back
2831
=back
2811
2832
Lines 2885-2892 sub ModBiblioMarc { Link Here
2885
        Koha::Util::MARC::set_marc_field($record, C4::Context->preference('MarcFieldForModifierName'), $borrowername);
2906
        Koha::Util::MARC::set_marc_field($record, C4::Context->preference('MarcFieldForModifierName'), $borrowername);
2886
    }
2907
    }
2887
2908
2888
    $m_rs->metadata( $record->as_xml_record($encoding) );
2909
    $m_rs->set(
2889
    $m_rs->store;
2910
        {
2911
            metadata => $record->as_xml_record($encoding),
2912
            (
2913
                exists $options->{record_source_id}
2914
                ? ( record_source_id => $options->{record_source_id} )
2915
                : ()
2916
            )
2917
        }
2918
    )->store;
2890
2919
2891
    unless ( $skip_record_index ) {
2920
    unless ( $skip_record_index ) {
2892
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
2921
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
(-)a/t/db_dependent/Biblio.t (-2 / +51 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 20;
20
use Test::More tests => 21;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
use List::MoreUtils qw( uniq );
23
use List::MoreUtils qw( uniq );
Lines 45-51 Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); Link Here
45
my $builder = t::lib::TestBuilder->new;
45
my $builder = t::lib::TestBuilder->new;
46
46
47
subtest 'AddBiblio' => sub {
47
subtest 'AddBiblio' => sub {
48
    plan tests => 9;
48
    plan tests => 10;
49
49
50
    my $marcflavour = 'MARC21';
50
    my $marcflavour = 'MARC21';
51
    t::lib::Mocks::mock_preference( 'marcflavour', $marcflavour );
51
    t::lib::Mocks::mock_preference( 'marcflavour', $marcflavour );
Lines 99-104 subtest 'AddBiblio' => sub { Link Here
99
    warning_like { $builder->build_sample_biblio(); }
99
    warning_like { $builder->build_sample_biblio(); }
100
        qr/My biblionumber is \d+ and my frameworkcode is /, "The biblionumber is correctly passed to BiblioAutoLink";
100
        qr/My biblionumber is \d+ and my frameworkcode is /, "The biblionumber is correctly passed to BiblioAutoLink";
101
101
102
    subtest 'record_source_id param tests' => sub {
103
104
        plan tests => 2;
105
106
        my $source = $builder->build_object( { class => 'Koha::RecordSources' } );
107
108
        my $record = MARC::Record->new;
109
        $record->append_fields( MARC::Field->new( '245', ' ', ' ', a => 'Some title' ) );
110
111
        my ($biblio_id) = C4::Biblio::AddBiblio( $record, '', { record_source_id => undef } );
112
        my $metadata = Koha::Biblios->find($biblio_id)->metadata;
113
114
        is( $metadata->record_source_id, undef, 'Record source is not defined' );
115
116
        ($biblio_id) = C4::Biblio::AddBiblio( $record, '', { record_source_id => $source->id } );
117
        $metadata = Koha::Biblios->find($biblio_id)->metadata;
118
119
        is( $metadata->record_source_id, $source->id, 'Record source is stored as expected' );
120
    };
102
};
121
};
103
122
104
subtest 'GetMarcSubfieldStructureFromKohaField' => sub {
123
subtest 'GetMarcSubfieldStructureFromKohaField' => sub {
Lines 1022-1027 subtest 'ModBiblio on invalid record' => sub { Link Here
1022
    );
1041
    );
1023
};
1042
};
1024
1043
1044
subtest 'ModBiblio - record_source_id param tests' => sub {
1045
1046
    plan tests => 4;
1047
1048
    my $source = $builder->build_object( { class => 'Koha::RecordSources' } );
1049
1050
    my $record = MARC::Record->new;
1051
    $record->append_fields( MARC::Field->new( '245', ' ', ' ', a => 'Some title' ) );
1052
1053
    my ($biblio_id) = C4::Biblio::AddBiblio( $record, '', { record_source_id => undef } );
1054
    my $metadata = Koha::Biblios->find($biblio_id)->metadata;
1055
1056
    is( $metadata->record_source_id, undef, 'Record source is not defined' );
1057
1058
    C4::Biblio::ModBiblio( $record, $biblio_id, '', { record_source_id => $source->id } );
1059
    $metadata->discard_changes;
1060
1061
    is( $metadata->record_source_id, $source->id, 'Record source is stored as expected' );
1062
1063
    C4::Biblio::ModBiblio( $record, $biblio_id, '' );
1064
    $metadata->discard_changes;
1065
1066
    is( $metadata->record_source_id, $source->id, 'Record source not passed, remains untouched' );
1067
1068
    C4::Biblio::ModBiblio( $record, $biblio_id, '', { record_source_id => undef } );
1069
    $metadata->discard_changes;
1070
1071
    is( $metadata->record_source_id, undef, 'Record source is not defined' );
1072
};
1073
1025
# Cleanup
1074
# Cleanup
1026
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
1075
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
1027
$schema->storage->txn_rollback;
1076
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Biblio/ModBiblioMarc.t (-2 / +39 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 2;
20
use Test::More tests => 3;
21
use t::lib::Mocks;
21
use t::lib::Mocks;
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
use MARC::Record;
23
use MARC::Record;
Lines 27-32 use Koha::Database; Link Here
27
use Koha::Biblios;
27
use Koha::Biblios;
28
28
29
my $schema  = Koha::Database->new->schema;
29
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
31
30
$schema->storage->txn_begin;
32
$schema->storage->txn_begin;
31
33
32
subtest "Check MARC field length calculation" => sub {
34
subtest "Check MARC field length calculation" => sub {
Lines 82-84 subtest "StripWhitespaceChars tests" => sub { Link Here
82
};
84
};
83
85
84
$schema->storage->txn_rollback;
86
$schema->storage->txn_rollback;
85
- 
87
88
subtest "record_source_id parameter tests" => sub {
89
90
    plan tests => 5;
91
92
    $schema->storage->txn_begin;
93
94
    my $biblio = $builder->build_sample_biblio;
95
    my $source = $builder->build_object( { class => 'Koha::RecordSources' } );
96
97
    my $metadata = $biblio->metadata;
98
99
    is( $metadata->record_source_id, undef, 'Record source not set for biblio' );
100
101
    C4::Biblio::ModBiblioMarc( $metadata->record, $biblio->id, { record_source_id => undef } );
102
    $metadata->discard_changes;
103
104
    is( $metadata->record_source_id, undef, 'Record source not set for biblio' );
105
106
    C4::Biblio::ModBiblioMarc( $metadata->record, $biblio->id, { record_source_id => $source->id } );
107
    $metadata->discard_changes;
108
109
    is( $metadata->record_source_id, $source->id, 'Record source set for biblio' );
110
111
    C4::Biblio::ModBiblioMarc( $metadata->record, $biblio->id );
112
    $metadata->discard_changes;
113
114
    is( $metadata->record_source_id, $source->id, 'Record source param not passed, no change' );
115
116
    C4::Biblio::ModBiblioMarc( $metadata->record, $biblio->id, { record_source_id => undef } );
117
    $metadata->discard_changes;
118
119
    is( $metadata->record_source_id, undef, 'Record source passed but undef, unset for biblio' );
120
121
    $schema->storage->txn_rollback;
122
};

Return to bug 31791