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

(-)a/C4/Biblio.pm (-88 / +91 lines)
Lines 212-218 sub AddBiblio { Link Here
212
    my $skip_record_index = $options->{'skip_record_index'} // 0;
212
    my $skip_record_index = $options->{'skip_record_index'} // 0;
213
    my $disable_autolink  = $options->{disable_autolink}    // 0;
213
    my $disable_autolink  = $options->{disable_autolink}    // 0;
214
214
215
    if (!$record) {
215
    if ( !$record ) {
216
        carp('AddBiblio called with undefined record');
216
        carp('AddBiblio called with undefined record');
217
        return;
217
        return;
218
    }
218
    }
Lines 220-321 sub AddBiblio { Link Here
220
    my $schema = Koha::Database->schema;
220
    my $schema = Koha::Database->schema;
221
    my ( $biblionumber, $biblioitemnumber );
221
    my ( $biblionumber, $biblioitemnumber );
222
    try {
222
    try {
223
        $schema->txn_do(sub {
223
        $schema->txn_do(
224
224
            sub {
225
            # transform the data into koha-table style data
225
226
            SetUTF8Flag($record);
226
                # transform the data into koha-table style data
227
            my $olddata = TransformMarcToKoha({ record => $record, limit_table => 'no_items' });
227
                SetUTF8Flag($record);
228
228
                my $olddata = TransformMarcToKoha( { record => $record, limit_table => 'no_items' } );
229
            my $biblio = Koha::Biblio->new(
230
                {
231
                    frameworkcode => $frameworkcode,
232
                    author        => $olddata->{author},
233
                    title         => $olddata->{title},
234
                    subtitle      => $olddata->{subtitle},
235
                    medium        => $olddata->{medium},
236
                    part_number   => $olddata->{part_number},
237
                    part_name     => $olddata->{part_name},
238
                    unititle      => $olddata->{unititle},
239
                    notes         => $olddata->{notes},
240
                    serial        => $olddata->{serial},
241
                    seriestitle   => $olddata->{seriestitle},
242
                    copyrightdate => $olddata->{copyrightdate},
243
                    datecreated   => \'NOW()',
244
                    abstract      => $olddata->{abstract},
245
                }
246
            )->store;
247
            $biblionumber = $biblio->biblionumber;
248
            Koha::Exceptions::ObjectNotCreated->throw unless $biblio;
249
250
            my ($cn_sort) = GetClassSort( $olddata->{'biblioitems.cn_source'}, $olddata->{'cn_class'}, $olddata->{'cn_item'} );
251
            my $biblioitem = Koha::Biblioitem->new(
252
                {
253
                    biblionumber          => $biblionumber,
254
                    volume                => $olddata->{volume},
255
                    number                => $olddata->{number},
256
                    itemtype              => $olddata->{itemtype},
257
                    isbn                  => $olddata->{isbn},
258
                    issn                  => $olddata->{issn},
259
                    publicationyear       => $olddata->{publicationyear},
260
                    publishercode         => $olddata->{publishercode},
261
                    volumedate            => $olddata->{volumedate},
262
                    volumedesc            => $olddata->{volumedesc},
263
                    collectiontitle       => $olddata->{collectiontitle},
264
                    collectionissn        => $olddata->{collectionissn},
265
                    collectionvolume      => $olddata->{collectionvolume},
266
                    editionstatement      => $olddata->{editionstatement},
267
                    editionresponsibility => $olddata->{editionresponsibility},
268
                    illus                 => $olddata->{illus},
269
                    pages                 => $olddata->{pages},
270
                    notes                 => $olddata->{bnotes},
271
                    size                  => $olddata->{size},
272
                    place                 => $olddata->{place},
273
                    lccn                  => $olddata->{lccn},
274
                    url                   => $olddata->{url},
275
                    cn_source      => $olddata->{'biblioitems.cn_source'},
276
                    cn_class       => $olddata->{cn_class},
277
                    cn_item        => $olddata->{cn_item},
278
                    cn_suffix      => $olddata->{cn_suff},
279
                    cn_sort        => $cn_sort,
280
                    totalissues    => $olddata->{totalissues},
281
                    ean            => $olddata->{ean},
282
                    agerestriction => $olddata->{agerestriction},
283
                }
284
            )->store;
285
            Koha::Exceptions::ObjectNotCreated->throw unless $biblioitem;
286
            $biblioitemnumber = $biblioitem->biblioitemnumber;
287
229
288
            _koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber, $biblioitemnumber );
230
                my $biblio = Koha::Biblio->new(
231
                    {
232
                        frameworkcode => $frameworkcode,
233
                        author        => $olddata->{author},
234
                        title         => $olddata->{title},
235
                        subtitle      => $olddata->{subtitle},
236
                        medium        => $olddata->{medium},
237
                        part_number   => $olddata->{part_number},
238
                        part_name     => $olddata->{part_name},
239
                        unititle      => $olddata->{unititle},
240
                        notes         => $olddata->{notes},
241
                        serial        => $olddata->{serial},
242
                        seriestitle   => $olddata->{seriestitle},
243
                        copyrightdate => $olddata->{copyrightdate},
244
                        datecreated   => \'NOW()',
245
                        abstract      => $olddata->{abstract},
246
                    }
247
                )->store;
248
                $biblionumber = $biblio->biblionumber;
249
                Koha::Exceptions::ObjectNotCreated->throw unless $biblio;
289
250
290
            # update MARC subfield that stores biblioitems.cn_sort
251
                my ($cn_sort) =
291
            _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode );
252
                    GetClassSort( $olddata->{'biblioitems.cn_source'}, $olddata->{'cn_class'}, $olddata->{'cn_item'} );
253
                my $biblioitem = Koha::Biblioitem->new(
254
                    {
255
                        biblionumber          => $biblionumber,
256
                        volume                => $olddata->{volume},
257
                        number                => $olddata->{number},
258
                        itemtype              => $olddata->{itemtype},
259
                        isbn                  => $olddata->{isbn},
260
                        issn                  => $olddata->{issn},
261
                        publicationyear       => $olddata->{publicationyear},
262
                        publishercode         => $olddata->{publishercode},
263
                        volumedate            => $olddata->{volumedate},
264
                        volumedesc            => $olddata->{volumedesc},
265
                        collectiontitle       => $olddata->{collectiontitle},
266
                        collectionissn        => $olddata->{collectionissn},
267
                        collectionvolume      => $olddata->{collectionvolume},
268
                        editionstatement      => $olddata->{editionstatement},
269
                        editionresponsibility => $olddata->{editionresponsibility},
270
                        illus                 => $olddata->{illus},
271
                        pages                 => $olddata->{pages},
272
                        notes                 => $olddata->{bnotes},
273
                        size                  => $olddata->{size},
274
                        place                 => $olddata->{place},
275
                        lccn                  => $olddata->{lccn},
276
                        url                   => $olddata->{url},
277
                        cn_source             => $olddata->{'biblioitems.cn_source'},
278
                        cn_class              => $olddata->{cn_class},
279
                        cn_item               => $olddata->{cn_item},
280
                        cn_suffix             => $olddata->{cn_suff},
281
                        cn_sort               => $cn_sort,
282
                        totalissues           => $olddata->{totalissues},
283
                        ean                   => $olddata->{ean},
284
                        agerestriction        => $olddata->{agerestriction},
285
                    }
286
                )->store;
287
                Koha::Exceptions::ObjectNotCreated->throw unless $biblioitem;
288
                $biblioitemnumber = $biblioitem->biblioitemnumber;
292
289
293
            if (!$disable_autolink && C4::Context->preference('AutoLinkBiblios')) {
290
                _koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber, $biblioitemnumber );
294
                BiblioAutoLink( $record, $frameworkcode );
295
            }
296
291
297
            # now add the record, don't index while we are in the transaction though
292
                # update MARC subfield that stores biblioitems.cn_sort
298
            ModBiblioMarc(
293
                _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode );
299
                $record, $biblionumber,
294
300
                {
295
                if ( !$disable_autolink && C4::Context->preference('AutoLinkBiblios') ) {
301
                    skip_record_index => 1,
296
                    BiblioAutoLink( $record, $frameworkcode );
302
                    record_source_id  => $options->{record_source_id},
303
                }
297
                }
304
            );
305
298
306
            # update OAI-PMH sets
299
                # now add the record, don't index while we are in the transaction though
307
            if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
300
                ModBiblioMarc(
308
                C4::OAI::Sets::UpdateOAISetsBiblio($biblionumber, $record);
301
                    $record, $biblionumber,
309
            }
302
                    {
303
                        skip_record_index => 1,
304
                        record_source_id  => $options->{record_source_id},
305
                    }
306
                );
310
307
311
            _after_biblio_action_hooks({ action => 'create', biblio_id => $biblionumber });
308
                # update OAI-PMH sets
309
                if ( C4::Context->preference("OAI-PMH:AutoUpdateSets") ) {
310
                    C4::OAI::Sets::UpdateOAISetsBiblio( $biblionumber, $record );
311
                }
312
313
                _after_biblio_action_hooks( { action => 'create', biblio_id => $biblionumber } );
314
315
                logaction( "CATALOGUING", "ADD", $biblionumber, "biblio" ) if C4::Context->preference("CataloguingLog");
312
316
313
            logaction( "CATALOGUING", "ADD", $biblionumber, "biblio" ) if C4::Context->preference("CataloguingLog");
317
            }
318
        );
314
319
315
        });
316
        # We index now, after the transaction is committed
320
        # We index now, after the transaction is committed
317
        unless ( $skip_record_index ) {
321
        unless ($skip_record_index) {
318
            my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
322
            my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
319
            $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" );
323
            $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" );
320
        }
324
        }
321
    } catch {
325
    } catch {
322
- 

Return to bug 31791