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

(-)a/C4/Log.pm (-10 / +14 lines)
Lines 140-157 sub logaction { Link Here
140
    $diff //= encode_json( diff( $original, $updated, noU => 1 ) )
140
    $diff //= encode_json( diff( $original, $updated, noU => 1 ) )
141
        if $original && ref $updated eq 'HASH';
141
        if $original && ref $updated eq 'HASH';
142
142
143
    # Get the IP address from the environment
144
    my $ip_address = $ENV{REMOTE_ADDR} || undef;
145
143
    Koha::ActionLog->new(
146
    Koha::ActionLog->new(
144
        {
147
        {
145
            timestamp => \'NOW()',
148
            timestamp  => \'NOW()',
146
            user      => $usernumber,
149
            user       => $usernumber,
147
            module    => $modulename,
150
            module     => $modulename,
148
            action    => $actionname,
151
            action     => $actionname,
149
            object    => $objectnumber,
152
            object     => $objectnumber,
150
            info      => $infos,
153
            info       => $infos,
151
            interface => $interface,
154
            interface  => $interface,
152
            script    => $script,
155
            script     => $script,
153
            trace     => $trace,
156
            trace      => $trace,
154
            diff      => $diff,
157
            diff       => $diff,
158
            ip_address => $ip_address,
155
        }
159
        }
156
    )->store();
160
    )->store();
157
161
(-)a/Koha/Schema/Result/ActionLog.pm (+10 lines)
Lines 106-111 An optional stack trace enabled by ActionLogsTraceDepth Link Here
106
106
107
Stores a diff of the changed object
107
Stores a diff of the changed object
108
108
109
=head2 ip_address
110
111
  data_type: 'varchar'
112
  is_nullable: 1
113
  size: 45
114
115
IP address of the client that performed the action
116
109
=cut
117
=cut
110
118
111
__PACKAGE__->add_columns(
119
__PACKAGE__->add_columns(
Lines 136-141 __PACKAGE__->add_columns( Link Here
136
  { data_type => "text", is_nullable => 1 },
144
  { data_type => "text", is_nullable => 1 },
137
  "diff",
145
  "diff",
138
  { data_type => "longtext", is_nullable => 1 },
146
  { data_type => "longtext", is_nullable => 1 },
147
  "ip_address",
148
  { data_type => "varchar", is_nullable => 1, size => 45 },
139
);
149
);
140
150
141
=head1 PRIMARY KEY
151
=head1 PRIMARY KEY
(-)a/installer/data/mysql/db_revs/bug_41310.pl (+37 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use C4::Context;
6
use Koha::Database;
7
8
use base 'C4::Installer::DBUpgrade';
9
10
our $db_rev = '41310';
11
12
sub db_rev {
13
    return $db_rev;
14
}
15
16
sub upgrade {
17
    my ($args)          = @_;
18
    my $upgrade_context = $args->{upgrade_context};
19
    my $schema          = $upgrade_context->schema;
20
    my $dbh             = $upgrade_context->dbh;
21
22
    unless ( column_exists( 'action_logs', 'ip_address' ) ) {
23
        $dbh->do(
24
            q{
25
            ALTER TABLE action_logs
26
            ADD COLUMN ip_address VARCHAR(45) NULL DEFAULT NULL
27
            COMMENT 'IP address of the client that performed the action'
28
        }
29
        );
30
31
        say $upgrade_context->output("Added column 'action_logs.ip_address'");
32
    }
33
34
    return 1;
35
}
36
37
1;
(-)a/t/db_dependent/TestIpLogging.t (-1 / +44 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Test script to verify IP address logging in action_logs
4
# This script tests that the IP address is properly stored in action_logs
5
6
use Modern::Perl;
7
use Test::More tests => 5;
8
9
use C4::Context;
10
use C4::Log qw(logaction);
11
use Koha::Database;
12
use Koha::ActionLogs;
13
use t::lib::TestBuilder;
14
use t::lib::Mocks;
15
16
my $schema = Koha::Database->new->schema;
17
$schema->storage->txn_begin;
18
19
my $builder = t::lib::TestBuilder->new;
20
21
# Mock REMOTE_ADDR
22
$ENV{REMOTE_ADDR} = '192.168.1.100';
23
24
# Clear any existing action logs for this test
25
Koha::ActionLogs->search->delete;
26
27
# Perform a test action log
28
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
29
30
# Call logaction which should now capture the IP address
31
logaction( "TESTING", "ADD", $patron->borrowernumber, "Test IP logging", "intranet" );
32
33
# Check that the action log was created with the IP address
34
my $action_log = Koha::ActionLogs->search( { module => 'TESTING', action => 'ADD' } )->next;
35
ok( $action_log, "Action log was created" );
36
is( $action_log->module,     "TESTING",         "Module is correct" );
37
is( $action_log->action,     "ADD",             "Action is correct" );
38
is( $action_log->info,       "Test IP logging", "Info is correct" );
39
is( $action_log->ip_address, "192.168.1.100",   "IP address was captured correctly" );
40
41
# Clean up
42
$schema->storage->txn_rollback;
43
44
done_testing();

Return to bug 41310