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

(-)a/Koha/Illrequest/Logger.pm (-2 / +23 lines)
Lines 19-25 package Koha::Illrequest::Logger; Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use JSON qw( to_json from_json );
21
use JSON qw( to_json from_json );
22
22
use Time::Local;
23
use C4::Context;
23
use C4::Context;
24
use C4::Templates;
24
use C4::Templates;
25
use C4::Log qw( logaction GetLogs );
25
use C4::Log qw( logaction GetLogs );
Lines 196-201 sub get_log_template { Link Here
196
    }
196
    }
197
}
197
}
198
198
199
=head3 get_epoch
200
201
    $epoch = Koha::Illrequest::Logger->get_epoch($timestamp);
202
203
Given a timestamp string returned from GetLogs, get the epoch
204
205
=cut
206
207
sub get_epoch {
208
    my $timestamp = shift;
209
210
    return if !$timestamp=~/\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}/;
211
212
    my ($date, $time) = split(/\s/, $timestamp);
213
    my ($y, $mon, $d) = split(/-/, $date);
214
    my ($h, $min, $s) = split(/:/, $time);
215
216
    return timelocal($s, $min, $h, $d, $mon-1, $y);
217
}
218
199
=head3 get_request_logs
219
=head3 get_request_logs
200
220
201
    $requestlogs = Koha::IllRequest::Logger->get_request_logs($request_id);
221
    $requestlogs = Koha::IllRequest::Logger->get_request_logs($request_id);
Lines 228-234 sub get_request_logs { Link Here
228
        );
248
        );
229
    }
249
    }
230
250
231
    my @sorted = sort {$$b{'timestamp'} <=> $$a{'timestamp'}} @{$logs};
251
    my $format = '%Y-%m-%d %H:%M:%S';
252
    my @sorted = sort { get_epoch($$b{'timestamp'}) <=> get_epoch($$a{'timestamp'}) } @{$logs};
232
253
233
    return \@sorted;
254
    return \@sorted;
234
}
255
}
(-)a/t/db_dependent/Illrequest/Logger.t (-7 / +6 lines)
Lines 32-48 my $logs = [ Link Here
32
    {
32
    {
33
        info      => '{"log_origin": "core"}',
33
        info      => '{"log_origin": "core"}',
34
        action    => 'STATUS_CHANGE',
34
        action    => 'STATUS_CHANGE',
35
        timestamp => 1538478742
35
        timestamp => '2018-10-02 11:12:22'
36
    },
36
    },
37
    {
37
    {
38
        info      => '{"log_origin": "core"}',
38
        info      => '{"log_origin": "core"}',
39
        action    => 'STATUS_CHANGE',
39
        action    => 'STATUS_CHANGE',
40
        timestamp => 1538478732
40
        timestamp => '2018-10-02 11:12:12'
41
    },
41
    },
42
    {
42
    {
43
        info      => '{"log_origin": "core"}',
43
        info      => '{"log_origin": "core"}',
44
        action    => 'STATUS_CHANGE',
44
        action    => 'STATUS_CHANGE',
45
        timestamp => 1538478752
45
        timestamp => '2018-10-02 11:12:32'
46
    }
46
    }
47
];
47
];
48
# Mock the modules we use
48
# Mock the modules we use
Lines 126-145 subtest 'Basics' => sub { Link Here
126
        {
126
        {
127
            'template' => 'mock',
127
            'template' => 'mock',
128
            'info' => { 'log_origin' => 'core' },
128
            'info' => { 'log_origin' => 'core' },
129
            'timestamp' => 1538478752,
129
            'timestamp' => '2018-10-02 11:12:32',
130
            'action' => 'STATUS_CHANGE'
130
            'action' => 'STATUS_CHANGE'
131
        },
131
        },
132
        {
132
        {
133
            'template' => 'mock',
133
            'template' => 'mock',
134
            'action' => 'STATUS_CHANGE',
134
            'action' => 'STATUS_CHANGE',
135
            'timestamp' => 1538478742,
135
            'timestamp' => '2018-10-02 11:12:22',
136
            'info' => { 'log_origin' => 'core' }
136
            'info' => { 'log_origin' => 'core' }
137
        },
137
        },
138
        {
138
        {
139
            'template' => 'mock',
139
            'template' => 'mock',
140
            'action' => 'STATUS_CHANGE',
140
            'action' => 'STATUS_CHANGE',
141
            'info' => { 'log_origin' => 'core' },
141
            'info' => { 'log_origin' => 'core' },
142
            'timestamp' => 1538478732
142
            'timestamp' => '2018-10-02 11:12:12'
143
        }
143
        }
144
    ];
144
    ];
145
    my $me_mock = Test::MockModule->new('Koha::Illrequest::Logger');
145
    my $me_mock = Test::MockModule->new('Koha::Illrequest::Logger');
146
- 

Return to bug 20750