Bug 33159: Correctly form thesaurus term for non-subject headings
[koha-ffzg.git] / C4 / Log.pm
index 05a81f1..d16d423 100644 (file)
--- a/C4/Log.pm
+++ b/C4/Log.pm
@@ -31,6 +31,7 @@ use File::Basename qw( basename );
 
 use C4::Context;
 use Koha::Logger;
+use Koha::ActionLogs;
 
 use vars qw(@ISA @EXPORT);
 
@@ -94,10 +95,36 @@ sub logaction {
         ? basename($0)
         : undef;
 
-    my $dbh = C4::Context->dbh;
-    my $sth=$dbh->prepare("Insert into action_logs (timestamp,user,module,action,object,info,interface,script) values (now(),?,?,?,?,?,?,?)");
-    $sth->execute($usernumber,$modulename,$actionname,$objectnumber,$infos,$interface,$script);
-    $sth->finish;
+    my @trace;
+    my $depth = C4::Context->preference('ActionLogsTraceDepth') || 0;
+    for ( my $i = 0 ; $i < $depth ; $i++ ) {
+        my ( $package, $filename, $line, $subroutine ) = caller($i);
+        last unless defined $line;
+        push(
+            @trace,
+            {
+                package    => $package,
+                filename   => $filename,
+                line       => $line,
+                subroutine => $subroutine,
+            }
+        );
+    }
+    my $trace = @trace ? to_json( \@trace, { utf8 => 1, pretty => 0 } ) : undef;
+
+    Koha::ActionLog->new(
+        {
+            timestamp => \'NOW()',
+            user      => $usernumber,
+            module    => $modulename,
+            action    => $actionname,
+            object    => $objectnumber,
+            info      => $infos,
+            interface => $interface,
+            script    => $script,
+            trace     => $trace,
+        }
+    )->store();
 
     my $logger = Koha::Logger->get(
         {
@@ -131,10 +158,13 @@ Logs the path and name of the calling script plus the information privided by pa
 
 #'
 sub cronlogaction {
-    my ($infos)=@_;
+    my $params = shift;
+    my $info = $params->{info};
+    my $action = $params->{action};
+    $action ||= "Run";
     my $loginfo = (caller(0))[1];
-    $loginfo .= ' ' . $infos if $infos;
-    logaction( 'CRONJOBS', 'Run', undef, $loginfo ) if C4::Context->preference('CronjobLog');
+    $loginfo .= ' ' . $info if $info;
+    logaction( 'CRONJOBS', $action, $$, $loginfo ) if C4::Context->preference('CronjobLog');
 }
 
 1;