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

(-)a/C4/Biblio.pm (-6 / +48 lines)
Lines 311-317 sub AddBiblio { Link Here
311
311
312
        _after_biblio_action_hooks( { action => 'create', biblio_id => $biblionumber } );
312
        _after_biblio_action_hooks( { action => 'create', biblio_id => $biblionumber } );
313
        if ( C4::Context->preference("CataloguingLog") ) {
313
        if ( C4::Context->preference("CataloguingLog") ) {
314
            logaction( "CATALOGUING", "ADD", $biblionumber, "biblio", undef, Koha::Biblios->find($biblionumber) );
314
            my $new_biblio   = Koha::Biblios->find($biblionumber);
315
            my $marc_for_log = eval { $new_biblio->metadata->record_strip_nonxml };
316
            logaction(
317
                "CATALOGUING", "ADD", $biblionumber, "biblio", undef,
318
                { %{ $new_biblio->unblessed }, _marc => _marc_record_to_diffable($marc_for_log) }
319
            );
315
        }
320
        }
316
321
317
        # We index now, after the transaction is committed
322
        # We index now, after the transaction is committed
Lines 397-405 sub ModBiblio { Link Here
397
        return 0;
402
        return 0;
398
    }
403
    }
399
404
400
    my $original;
405
    my ( $original, $original_marc );
401
    if ( C4::Context->preference("CataloguingLog") ) {
406
    if ( C4::Context->preference("CataloguingLog") ) {
402
        $original = Koha::Biblios->find($biblionumber)->unblessed;
407
        my $pre_biblio = Koha::Biblios->find($biblionumber);
408
        $original      = $pre_biblio->unblessed;
409
        $original_marc = eval { $pre_biblio->metadata->record_strip_nonxml };
403
    }
410
    }
404
411
405
    if ( !$options->{disable_autolink} && C4::Context->preference('AutoLinkBiblios') ) {
412
    if ( !$options->{disable_autolink} && C4::Context->preference('AutoLinkBiblios') ) {
Lines 463-469 sub ModBiblio { Link Here
463
    _after_biblio_action_hooks( { action => 'modify', biblio_id => $biblionumber } );
470
    _after_biblio_action_hooks( { action => 'modify', biblio_id => $biblionumber } );
464
471
465
    if ( C4::Context->preference("CataloguingLog") ) {
472
    if ( C4::Context->preference("CataloguingLog") ) {
466
        logaction( "CATALOGUING", "MODIFY", $biblionumber, Koha::Biblios->find($biblionumber), undef, $original );
473
        my $updated_biblio   = Koha::Biblios->find($biblionumber);
474
        my $updated_marc_log = eval { $updated_biblio->metadata->record_strip_nonxml };
475
        logaction(
476
            "CATALOGUING", "MODIFY", $biblionumber,
477
            { %{ $updated_biblio->unblessed }, _marc => _marc_record_to_diffable($updated_marc_log) },
478
            undef,
479
            { %{$original}, _marc => _marc_record_to_diffable($original_marc) }
480
        );
467
    }
481
    }
468
482
469
    # update OAI-PMH sets
483
    # update OAI-PMH sets
Lines 487-492 MARC bib. Link Here
487
501
488
=cut
502
=cut
489
503
504
sub _marc_record_to_diffable {
505
    my ($record) = @_;
506
    return {} unless defined $record;
507
    my %marc;
508
    for my $field ( $record->fields ) {
509
        my $tag = $field->tag;
510
        if ( $field->is_control_field ) {
511
            $marc{$tag} = $field->data;
512
        } else {
513
            my $ind1      = $field->indicator(1);
514
            my $ind2      = $field->indicator(2);
515
            my $formatted = "$ind1$ind2";
516
            for my $subfield ( $field->subfields ) {
517
                $formatted .= " \$$subfield->[0] $subfield->[1]";
518
            }
519
            push @{ $marc{$tag} }, $formatted;
520
        }
521
    }
522
    return \%marc;
523
}
524
490
sub _strip_item_fields {
525
sub _strip_item_fields {
491
    my $record        = shift;
526
    my $record        = shift;
492
    my $frameworkcode = shift;
527
    my $frameworkcode = shift;
Lines 533-538 sub DelBiblio { Link Here
533
    my $dbh = C4::Context->dbh;
568
    my $dbh = C4::Context->dbh;
534
    my $error;                # for error handling
569
    my $error;                # for error handling
535
570
571
    my $biblio_marc =
572
        C4::Context->preference("CataloguingLog")
573
        ? eval { $biblio->metadata->record_strip_nonxml }
574
        : undef;
575
536
    # First make sure this biblio has no items attached
576
    # First make sure this biblio has no items attached
537
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber=?");
577
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber=?");
538
    $sth->execute($biblionumber);
578
    $sth->execute($biblionumber);
Lines 585-592 sub DelBiblio { Link Here
585
625
586
    _after_biblio_action_hooks( { action => 'delete', biblio_id => $biblionumber } );
626
    _after_biblio_action_hooks( { action => 'delete', biblio_id => $biblionumber } );
587
627
588
    logaction( "CATALOGUING", "DELETE", $biblionumber, "biblio", undef, $biblio )
628
    logaction(
589
        if C4::Context->preference("CataloguingLog");
629
        "CATALOGUING", "DELETE", $biblionumber, "biblio", undef,
630
        { %{ $biblio->unblessed }, _marc => _marc_record_to_diffable($biblio_marc) }
631
    ) if C4::Context->preference("CataloguingLog");
590
632
591
    Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => [$biblionumber] } )
633
    Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => [$biblionumber] } )
592
        unless $params->{skip_holds_queue}
634
        unless $params->{skip_holds_queue}
(-)a/C4/Log.pm (+4 lines)
Lines 94-99 sub logaction { Link Here
94
        }
94
        }
95
    } else {
95
    } else {
96
        $updated = $infos;
96
        $updated = $infos;
97
        if ( ref $infos eq 'HASH' ) {
98
            local $Data::Dumper::Sortkeys = 1;
99
            $infos = Dumper($updated);
100
        }
97
    }
101
    }
98
102
99
    my $script =
103
    my $script =
(-)a/t/db_dependent/Biblio.t (-2 / +7 lines)
Lines 1205-1211 subtest 'GetFrameworkCode' => sub { Link Here
1205
};
1205
};
1206
1206
1207
subtest 'ModBiblio on invalid record' => sub {
1207
subtest 'ModBiblio on invalid record' => sub {
1208
    plan tests => 2;
1208
    plan tests => 4;
1209
1209
1210
    t::lib::Mocks::mock_preference( "CataloguingLog", 1 );
1210
    t::lib::Mocks::mock_preference( "CataloguingLog", 1 );
1211
1211
Lines 1216-1227 subtest 'ModBiblio on invalid record' => sub { Link Here
1216
1216
1217
    my ($biblionumber) = C4::Biblio::AddBiblio( $record, '' );
1217
    my ($biblionumber) = C4::Biblio::AddBiblio( $record, '' );
1218
1218
1219
    # Modify the record to add a title field so MARC changes are captured in the diff
1220
    my $title_field = MARC::Field->new( '245', '1', '0', 'a' => 'New Title' );
1221
    $record->append_fields($title_field);
1222
1219
    C4::Biblio::ModBiblio( $record, $biblionumber, '' );
1223
    C4::Biblio::ModBiblio( $record, $biblionumber, '' );
1220
    my $action_logs =
1224
    my $action_logs =
1221
        Koha::ActionLogs->search( { object => $biblionumber, module => 'Cataloguing', action => 'MODIFY' } );
1225
        Koha::ActionLogs->search( { object => $biblionumber, module => 'Cataloguing', action => 'MODIFY' } );
1222
    is( $action_logs->count, 1, "Modification of biblio was successful and recorded" );
1226
    is( $action_logs->count, 1, "Modification of biblio was successful and recorded" );
1223
    my $action_log = $action_logs->next;
1227
    my $action_log = $action_logs->next;
1224
    like( $action_log->info, qr/biblionumber/, "Biblio data logged in action log info" );
1228
    like( $action_log->info, qr/biblionumber/, "Biblio data logged in action log info" );
1229
    ok( defined $action_log->diff, "Diff column is populated for MODIFY" );
1230
    like( $action_log->diff, qr/_marc/, "MARC field changes are captured in the diff column" );
1225
};
1231
};
1226
1232
1227
subtest 'UpdateTotalIssues on Invalid record' => sub {
1233
subtest 'UpdateTotalIssues on Invalid record' => sub {
1228
- 

Return to bug 40135