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

(-)a/C4/Log.pm (-2 / +6 lines)
Lines 60-66 The functions in this module perform various functions in order to log all the o Link Here
60
60
61
=item logaction
61
=item logaction
62
62
63
  &logaction($modulename, $actionname, $objectnumber, $infos, $interface, $hashref_of_original);
63
  &logaction($modulename, $actionname, $objectnumber, $infos, $interface, $original_as_hashref_or_object);
64
64
65
Adds a record into action_logs table to report the different changes upon the database.
65
Adds a record into action_logs table to report the different changes upon the database.
66
Each log entry includes the number of the user currently logged in.  For batch
66
Each log entry includes the number of the user currently logged in.  For batch
Lines 118-124 sub logaction { Link Here
118
    }
118
    }
119
    my $trace = @trace ? to_json( \@trace, { utf8 => 1, pretty => 0 } ) : undef;
119
    my $trace = @trace ? to_json( \@trace, { utf8 => 1, pretty => 0 } ) : undef;
120
120
121
    my $diff = ( $original && ref $updated eq 'HASH' ) ? encode_json( diff( $original, $updated, noU => 1 ) ) : undef;
121
    my $diff = undef;
122
    $diff = encode_json( diff( $original->unblessed, $updated, noU => 1 ) )
123
        if blessed($original) && $original->isa('Koha::Object');
124
    $diff //= encode_json( diff( $original, $updated, noU => 1 ) )
125
        if $original && ref $updated eq 'HASH';
122
126
123
    Koha::ActionLog->new(
127
    Koha::ActionLog->new(
124
        {
128
        {
(-)a/t/db_dependent/Log.t (-2 / +8 lines)
Lines 197-212 subtest 'Reduce log size by unblessing Koha objects' => sub { Link Here
197
};
197
};
198
198
199
subtest 'Test storing diff of objects' => sub {
199
subtest 'Test storing diff of objects' => sub {
200
    plan tests => 1;
200
    plan tests => 2;
201
201
202
    my $builder = t::lib::TestBuilder->new;
202
    my $builder = t::lib::TestBuilder->new;
203
    my $item = $builder->build_sample_item;
203
    my $item = $builder->build_sample_item;
204
    my $original = $item->unblessed();
204
    my $original = $item->unblessed();
205
    my $original_item = $item->get_from_storage();
205
    $item->barcode('_MY_TEST_BARCODE_')->store();
206
    $item->barcode('_MY_TEST_BARCODE_')->store();
207
206
    logaction( 'MY_MODULE', 'TEST01', $item->itemnumber, $item, 'opac', $original );
208
    logaction( 'MY_MODULE', 'TEST01', $item->itemnumber, $item, 'opac', $original );
207
    my $logs = Koha::ActionLogs->search({ module => 'MY_MODULE', action => 'TEST01', object => $item->itemnumber })->next;
209
    my $logs = Koha::ActionLogs->search({ module => 'MY_MODULE', action => 'TEST01', object => $item->itemnumber })->next;
208
    my $diff = decode_json( $logs->diff );
210
    my $diff = decode_json( $logs->diff );
209
    is( $diff->{D}->{barcode}->{N}, '_MY_TEST_BARCODE_', 'Diff of changes logged successfully' );
211
    is( $diff->{D}->{barcode}->{N}, '_MY_TEST_BARCODE_', 'Diff of changes logged successfully' );
212
213
    logaction( 'MY_MODULE', 'TEST02', $item->itemnumber, $item, 'opac', $original_item );
214
    $logs = Koha::ActionLogs->search({ module => 'MY_MODULE', action => 'TEST02', object => $item->itemnumber })->next;
215
    $diff = decode_json( $logs->diff );
216
    is( $diff->{D}->{barcode}->{N}, '_MY_TEST_BARCODE_', 'Diff of changes logged successfully' );
210
};
217
};
211
218
212
$schema->storage->txn_rollback;
219
$schema->storage->txn_rollback;
213
- 

Return to bug 25159