Lines 25-33
use strict;
Link Here
|
25 |
use warnings; |
25 |
use warnings; |
26 |
|
26 |
|
27 |
use Data::Dumper qw( Dumper ); |
27 |
use Data::Dumper qw( Dumper ); |
28 |
use JSON qw( to_json ); |
|
|
29 |
use Scalar::Util qw( blessed ); |
30 |
use File::Basename qw( basename ); |
28 |
use File::Basename qw( basename ); |
|
|
29 |
use JSON qw( to_json encode_json ); |
30 |
use Scalar::Util qw( blessed ); |
31 |
use Struct::Diff qw( diff ); |
31 |
|
32 |
|
32 |
use C4::Context; |
33 |
use C4::Context; |
33 |
use Koha::Logger; |
34 |
use Koha::Logger; |
Lines 59-65
The functions in this module perform various functions in order to log all the o
Link Here
|
59 |
|
60 |
|
60 |
=item logaction |
61 |
=item logaction |
61 |
|
62 |
|
62 |
&logaction($modulename, $actionname, $objectnumber, $infos, $interface); |
63 |
&logaction($modulename, $actionname, $objectnumber, $infos, $interface, $hashref_of_original); |
63 |
|
64 |
|
64 |
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. |
65 |
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 70-76
number is set to 0, which is the same as the superlibrarian's number.
Link Here
|
70 |
|
71 |
|
71 |
#' |
72 |
#' |
72 |
sub logaction { |
73 |
sub logaction { |
73 |
my ($modulename, $actionname, $objectnumber, $infos, $interface)=@_; |
74 |
my ($modulename, $actionname, $objectnumber, $infos, $interface, $original )=@_; |
|
|
75 |
|
76 |
my $updated; |
77 |
$original //= {}; |
74 |
|
78 |
|
75 |
# Get ID of logged in user. if called from a batch job, |
79 |
# Get ID of logged in user. if called from a batch job, |
76 |
# no user session exists and C4::Context->userenv() returns |
80 |
# no user session exists and C4::Context->userenv() returns |
Lines 82-87
sub logaction {
Link Here
|
82 |
|
86 |
|
83 |
if( blessed($infos) && $infos->isa('Koha::Object') ) { |
87 |
if( blessed($infos) && $infos->isa('Koha::Object') ) { |
84 |
$infos = $infos->get_from_storage if $infos->in_storage; |
88 |
$infos = $infos->get_from_storage if $infos->in_storage; |
|
|
89 |
$updated = $infos; |
85 |
local $Data::Dumper::Sortkeys = 1; |
90 |
local $Data::Dumper::Sortkeys = 1; |
86 |
|
91 |
|
87 |
if ( $infos->isa('Koha::Item') && $modulename eq 'CATALOGUING' && $actionname eq 'MODIFY' ) { |
92 |
if ( $infos->isa('Koha::Item') && $modulename eq 'CATALOGUING' && $actionname eq 'MODIFY' ) { |
Lines 89-94
sub logaction {
Link Here
|
89 |
} else { |
94 |
} else { |
90 |
$infos = Dumper( $infos->unblessed ); |
95 |
$infos = Dumper( $infos->unblessed ); |
91 |
} |
96 |
} |
|
|
97 |
} else { |
98 |
$updated = $infos; |
92 |
} |
99 |
} |
93 |
|
100 |
|
94 |
my $script = ( $interface eq 'cron' or $interface eq 'commandline' ) |
101 |
my $script = ( $interface eq 'cron' or $interface eq 'commandline' ) |
Lines 112-117
sub logaction {
Link Here
|
112 |
} |
119 |
} |
113 |
my $trace = @trace ? to_json( \@trace, { utf8 => 1, pretty => 0 } ) : undef; |
120 |
my $trace = @trace ? to_json( \@trace, { utf8 => 1, pretty => 0 } ) : undef; |
114 |
|
121 |
|
|
|
122 |
$updated = $updated->unblessed if blessed($updated) && $updated->isa('Koha::Object'); |
123 |
my $diff = ref $updated eq 'HASH' ? encode_json( diff( $original, $updated, noU => 1 ) ) : undef; |
124 |
|
115 |
Koha::ActionLog->new( |
125 |
Koha::ActionLog->new( |
116 |
{ |
126 |
{ |
117 |
timestamp => \'NOW()', |
127 |
timestamp => \'NOW()', |
Lines 123-128
sub logaction {
Link Here
|
123 |
interface => $interface, |
133 |
interface => $interface, |
124 |
script => $script, |
134 |
script => $script, |
125 |
trace => $trace, |
135 |
trace => $trace, |
|
|
136 |
diff => $diff, |
126 |
} |
137 |
} |
127 |
)->store(); |
138 |
)->store(); |
128 |
|
139 |
|
Lines 134-140
sub logaction {
Link Here
|
134 |
); |
145 |
); |
135 |
$logger->debug( |
146 |
$logger->debug( |
136 |
sub { |
147 |
sub { |
137 |
"ACTION LOG: " . to_json( |
148 |
"ACTION LOG: " . encode_json( |
138 |
{ |
149 |
{ |
139 |
user => $usernumber, |
150 |
user => $usernumber, |
140 |
module => $modulename, |
151 |
module => $modulename, |