@@ -, +, @@ --- C4/Log.pm | 38 +++++++++---------- .../data/mysql/atomicupdate/bug_25159.pl | 6 +-- t/db_dependent/Log.t | 12 +++--- 3 files changed, 29 insertions(+), 27 deletions(-) --- a/C4/Log.pm +++ a/C4/Log.pm @@ -2,7 +2,6 @@ package C4::Log; #package to deal with Logging Actions in DB - # Copyright 2000-2002 Katipo Communications # Copyright 2011 MJ Ray and software.coop # @@ -24,11 +23,11 @@ package C4::Log; use strict; use warnings; -use Data::Dumper qw( Dumper ); +use Data::Dumper qw( Dumper ); use File::Basename qw( basename ); -use JSON qw( to_json encode_json ); -use Scalar::Util qw( blessed ); -use Struct::Diff qw( diff ); +use JSON qw( to_json encode_json ); +use Scalar::Util qw( blessed ); +use Struct::Diff qw( diff ); use C4::Context; use Koha::Logger; @@ -37,9 +36,9 @@ use Koha::ActionLogs; use vars qw(@ISA @EXPORT); BEGIN { - require Exporter; - @ISA = qw(Exporter); - @EXPORT = qw(logaction cronlogaction); + require Exporter; + @ISA = qw(Exporter); + @EXPORT = qw(logaction cronlogaction); } =head1 NAME @@ -71,33 +70,34 @@ number is set to 0, which is the same as the superlibrarian's number. #' sub logaction { - my ($modulename, $actionname, $objectnumber, $infos, $interface, $original )=@_; + my ( $modulename, $actionname, $objectnumber, $infos, $interface, $original ) = @_; my $updated; # Get ID of logged in user. if called from a batch job, # no user session exists and C4::Context->userenv() returns # the scalar '0'. - my $userenv = C4::Context->userenv(); - my $usernumber = (ref($userenv) eq 'HASH') ? $userenv->{'number'} : 0; + my $userenv = C4::Context->userenv(); + my $usernumber = ( ref($userenv) eq 'HASH' ) ? $userenv->{'number'} : 0; $usernumber ||= 0; $interface //= C4::Context->interface; - if( blessed($infos) && $infos->isa('Koha::Object') ) { - $infos = $infos->get_from_storage if $infos->in_storage; + if ( blessed($infos) && $infos->isa('Koha::Object') ) { + $infos = $infos->get_from_storage if $infos->in_storage; $updated = $infos->unblessed; local $Data::Dumper::Sortkeys = 1; if ( $infos->isa('Koha::Item') && $modulename eq 'CATALOGUING' && $actionname eq 'MODIFY' ) { - $infos = "item " . Dumper( $updated ); + $infos = "item " . Dumper($updated); } else { - $infos = Dumper( $updated ); + $infos = Dumper($updated); } } else { $updated = $infos; } - my $script = ( $interface eq 'cron' or $interface eq 'commandline' ) + my $script = + ( $interface eq 'cron' or $interface eq 'commandline' ) ? basename($0) : undef; @@ -172,11 +172,11 @@ Logs the path and name of the calling script plus the information privided by pa #' sub cronlogaction { my $params = shift; - my $info = $params->{info}; + my $info = $params->{info}; my $action = $params->{action}; $action ||= "Run"; - my $loginfo = (caller(0))[1]; - $loginfo .= ' ' . $info if $info; + my $loginfo = ( caller(0) )[1]; + $loginfo .= ' ' . $info if $info; logaction( 'CRONJOBS', $action, $$, $loginfo ) if C4::Context->preference('CronjobLog'); } --- a/installer/data/mysql/atomicupdate/bug_25159.pl +++ a/installer/data/mysql/atomicupdate/bug_25159.pl @@ -1,11 +1,11 @@ use Modern::Perl; return { - bug_number => "251159", + bug_number => "251159", description => "Add action logs should be stored in JSON ( and as a diff of the change )", - up => sub { + up => sub { my ($args) = @_; - my ($dbh, $out) = @$args{qw(dbh out)}; + my ( $dbh, $out ) = @$args{qw(dbh out)}; $dbh->do(q{ALTER TABLE action_logs ADD COLUMN diff LONGTEXT NULL DEFAULT NULL AFTER trace;}); say $out "Added column 'action_logs.diff'"; --- a/t/db_dependent/Log.t +++ a/t/db_dependent/Log.t @@ -199,19 +199,21 @@ subtest 'Reduce log size by unblessing Koha objects' => sub { subtest 'Test storing diff of objects' => sub { plan tests => 2; - my $builder = t::lib::TestBuilder->new; - my $item = $builder->build_sample_item; - my $original = $item->unblessed(); + my $builder = t::lib::TestBuilder->new; + my $item = $builder->build_sample_item; + my $original = $item->unblessed(); my $original_item = $item->get_from_storage(); $item->barcode('_MY_TEST_BARCODE_')->store(); logaction( 'MY_MODULE', 'TEST01', $item->itemnumber, $item, 'opac', $original ); - my $logs = Koha::ActionLogs->search({ module => 'MY_MODULE', action => 'TEST01', object => $item->itemnumber })->next; + my $logs = + Koha::ActionLogs->search( { module => 'MY_MODULE', action => 'TEST01', object => $item->itemnumber } )->next; my $diff = decode_json( $logs->diff ); is( $diff->{D}->{barcode}->{N}, '_MY_TEST_BARCODE_', 'Diff of changes logged successfully' ); logaction( 'MY_MODULE', 'TEST02', $item->itemnumber, $item, 'opac', $original_item ); - $logs = Koha::ActionLogs->search({ module => 'MY_MODULE', action => 'TEST02', object => $item->itemnumber })->next; + $logs = + Koha::ActionLogs->search( { module => 'MY_MODULE', action => 'TEST02', object => $item->itemnumber } )->next; $diff = decode_json( $logs->diff ); is( $diff->{D}->{barcode}->{N}, '_MY_TEST_BARCODE_', 'Diff of changes logged successfully' ); }; --