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

(-)a/C4/Log.pm (-19 / +19 lines)
Lines 2-8 package C4::Log; Link Here
2
2
3
#package to deal with Logging Actions in DB
3
#package to deal with Logging Actions in DB
4
4
5
6
# Copyright 2000-2002 Katipo Communications
5
# Copyright 2000-2002 Katipo Communications
7
# Copyright 2011 MJ Ray and software.coop
6
# Copyright 2011 MJ Ray and software.coop
8
#
7
#
Lines 24-34 package C4::Log; Link Here
24
use strict;
23
use strict;
25
use warnings;
24
use warnings;
26
25
27
use Data::Dumper qw( Dumper );
26
use Data::Dumper   qw( Dumper );
28
use File::Basename qw( basename );
27
use File::Basename qw( basename );
29
use JSON qw( to_json encode_json );
28
use JSON           qw( to_json encode_json );
30
use Scalar::Util qw( blessed );
29
use Scalar::Util   qw( blessed );
31
use Struct::Diff qw( diff );
30
use Struct::Diff   qw( diff );
32
31
33
use C4::Context;
32
use C4::Context;
34
use Koha::Logger;
33
use Koha::Logger;
Lines 37-45 use Koha::ActionLogs; Link Here
37
use vars qw(@ISA @EXPORT);
36
use vars qw(@ISA @EXPORT);
38
37
39
BEGIN {
38
BEGIN {
40
        require Exporter;
39
    require Exporter;
41
        @ISA = qw(Exporter);
40
    @ISA    = qw(Exporter);
42
        @EXPORT = qw(logaction cronlogaction);
41
    @EXPORT = qw(logaction cronlogaction);
43
}
42
}
44
43
45
=head1 NAME
44
=head1 NAME
Lines 71-103 number is set to 0, which is the same as the superlibrarian's number. Link Here
71
70
72
#'
71
#'
73
sub logaction {
72
sub logaction {
74
    my ($modulename, $actionname, $objectnumber, $infos, $interface, $original )=@_;
73
    my ( $modulename, $actionname, $objectnumber, $infos, $interface, $original ) = @_;
75
74
76
    my $updated;
75
    my $updated;
77
76
78
    # Get ID of logged in user.  if called from a batch job,
77
    # Get ID of logged in user.  if called from a batch job,
79
    # no user session exists and C4::Context->userenv() returns
78
    # no user session exists and C4::Context->userenv() returns
80
    # the scalar '0'.
79
    # the scalar '0'.
81
    my $userenv = C4::Context->userenv();
80
    my $userenv    = C4::Context->userenv();
82
    my $usernumber = (ref($userenv) eq 'HASH') ? $userenv->{'number'} : 0;
81
    my $usernumber = ( ref($userenv) eq 'HASH' ) ? $userenv->{'number'} : 0;
83
    $usernumber ||= 0;
82
    $usernumber ||= 0;
84
    $interface //= C4::Context->interface;
83
    $interface //= C4::Context->interface;
85
84
86
    if( blessed($infos) && $infos->isa('Koha::Object') ) {
85
    if ( blessed($infos) && $infos->isa('Koha::Object') ) {
87
        $infos = $infos->get_from_storage if $infos->in_storage;
86
        $infos   = $infos->get_from_storage if $infos->in_storage;
88
        $updated = $infos->unblessed;
87
        $updated = $infos->unblessed;
89
        local $Data::Dumper::Sortkeys = 1;
88
        local $Data::Dumper::Sortkeys = 1;
90
89
91
        if ( $infos->isa('Koha::Item') && $modulename eq 'CATALOGUING' && $actionname eq 'MODIFY' ) {
90
        if ( $infos->isa('Koha::Item') && $modulename eq 'CATALOGUING' && $actionname eq 'MODIFY' ) {
92
            $infos = "item " . Dumper( $updated );
91
            $infos = "item " . Dumper($updated);
93
        } else {
92
        } else {
94
            $infos = Dumper( $updated );
93
            $infos = Dumper($updated);
95
        }
94
        }
96
    } else {
95
    } else {
97
        $updated = $infos;
96
        $updated = $infos;
98
    }
97
    }
99
98
100
    my $script = ( $interface eq 'cron' or $interface eq 'commandline' )
99
    my $script =
100
        ( $interface eq 'cron' or $interface eq 'commandline' )
101
        ? basename($0)
101
        ? basename($0)
102
        : undef;
102
        : undef;
103
103
Lines 172-182 Logs the path and name of the calling script plus the information privided by pa Link Here
172
#'
172
#'
173
sub cronlogaction {
173
sub cronlogaction {
174
    my $params = shift;
174
    my $params = shift;
175
    my $info = $params->{info};
175
    my $info   = $params->{info};
176
    my $action = $params->{action};
176
    my $action = $params->{action};
177
    $action ||= "Run";
177
    $action ||= "Run";
178
    my $loginfo = (caller(0))[1];
178
    my $loginfo = ( caller(0) )[1];
179
    $loginfo .= ' ' . $info if $info;
179
    $loginfo .= ' ' . $info                        if $info;
180
    logaction( 'CRONJOBS', $action, $$, $loginfo ) if C4::Context->preference('CronjobLog');
180
    logaction( 'CRONJOBS', $action, $$, $loginfo ) if C4::Context->preference('CronjobLog');
181
}
181
}
182
182
(-)a/installer/data/mysql/atomicupdate/bug_25159.pl (-3 / +3 lines)
Lines 1-11 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
return {
3
return {
4
    bug_number => "251159",
4
    bug_number  => "251159",
5
    description => "Add action logs should be stored in JSON ( and as a diff of the change )",
5
    description => "Add action logs should be stored in JSON ( and as a diff of the change )",
6
    up => sub {
6
    up          => sub {
7
        my ($args) = @_;
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
9
10
        $dbh->do(q{ALTER TABLE action_logs ADD COLUMN diff LONGTEXT NULL DEFAULT NULL AFTER trace;});
10
        $dbh->do(q{ALTER TABLE action_logs ADD COLUMN diff LONGTEXT NULL DEFAULT NULL AFTER trace;});
11
        say $out "Added column 'action_logs.diff'";
11
        say $out "Added column 'action_logs.diff'";
(-)a/t/db_dependent/Log.t (-6 / +7 lines)
Lines 199-217 subtest 'Reduce log size by unblessing Koha objects' => sub { Link Here
199
subtest 'Test storing diff of objects' => sub {
199
subtest 'Test storing diff of objects' => sub {
200
    plan tests => 2;
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
    my $original_item = $item->get_from_storage();
206
    $item->barcode('_MY_TEST_BARCODE_')->store();
206
    $item->barcode('_MY_TEST_BARCODE_')->store();
207
207
208
    logaction( 'MY_MODULE', 'TEST01', $item->itemnumber, $item, 'opac', $original );
208
    logaction( 'MY_MODULE', 'TEST01', $item->itemnumber, $item, 'opac', $original );
209
    my $logs = Koha::ActionLogs->search({ module => 'MY_MODULE', action => 'TEST01', object => $item->itemnumber })->next;
209
    my $logs =
210
        Koha::ActionLogs->search( { module => 'MY_MODULE', action => 'TEST01', object => $item->itemnumber } )->next;
210
    my $diff = decode_json( $logs->diff );
211
    my $diff = decode_json( $logs->diff );
211
    is( $diff->{D}->{barcode}->{N}, '_MY_TEST_BARCODE_', 'Diff of changes logged successfully' );
212
    is( $diff->{D}->{barcode}->{N}, '_MY_TEST_BARCODE_', 'Diff of changes logged successfully' );
212
213
213
    logaction( 'MY_MODULE', 'TEST02', $item->itemnumber, $item, 'opac', $original_item );
214
    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
    $logs =
216
        Koha::ActionLogs->search( { module => 'MY_MODULE', action => 'TEST02', object => $item->itemnumber } )->next;
215
    $diff = decode_json( $logs->diff );
217
    $diff = decode_json( $logs->diff );
216
    is( $diff->{D}->{barcode}->{N}, '_MY_TEST_BARCODE_', 'Diff of changes logged successfully' );
218
    is( $diff->{D}->{barcode}->{N}, '_MY_TEST_BARCODE_', 'Diff of changes logged successfully' );
217
};
219
};
218
- 

Return to bug 25159