diff --git a/C4/Log.pm b/C4/Log.pm index 19e4a57ec1..b38fb9c163 100644 --- a/C4/Log.pm +++ b/C4/Log.pm @@ -27,6 +27,7 @@ use warnings; use Data::Dumper qw( Dumper ); use JSON qw( to_json ); use Scalar::Util qw( blessed ); +use File::Basename qw( basename ); use C4::Context; use Koha::Logger; @@ -89,9 +90,14 @@ sub logaction { } } + my $script = + $interface eq 'cron' ? basename($0) + : $interface eq 'commandline' ? basename($0) + : undef; + my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("Insert into action_logs (timestamp,user,module,action,object,info,interface) values (now(),?,?,?,?,?,?)"); - $sth->execute($usernumber,$modulename,$actionname,$objectnumber,$infos,$interface); + 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 $logger = Koha::Logger->get( diff --git a/installer/data/mysql/atomicupdate/bug_30984.pl b/installer/data/mysql/atomicupdate/bug_30984.pl new file mode 100755 index 0000000000..6947bcf734 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_30984.pl @@ -0,0 +1,17 @@ +use Modern::Perl; + +return { + bug_number => "30984", + description => "Log the cron script that generated an action log if there is one", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + if( !column_exists( 'action_logs', 'script' ) ) { + $dbh->do(q{ + ALTER TABLE action_logs + ADD COLUMN script mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the name of the cron script that caused this change' + AFTER interface + }); + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index aae3551f78..c38ac205d8 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -175,6 +175,7 @@ CREATE TABLE `action_logs` ( `object` int(11) DEFAULT NULL COMMENT 'the object that the action was taken against (could be a borrowernumber, itemnumber, etc)', `info` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'information about the action (usually includes SQL statement)', `interface` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the context this action was taken in', + `script` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the name of the cron script that caused this change', PRIMARY KEY (`action_id`), KEY `timestamp_idx` (`timestamp`), KEY `user_idx` (`user`),