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

(-)a/Koha/Illrequest/Logger.pm (-2 / +22 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
use Time::Piece;
22
use Time::Local;
23
23
24
use C4::Context;
24
use C4::Context;
25
use C4::Templates;
25
use C4::Templates;
Lines 197-202 sub get_log_template { Link Here
197
    }
197
    }
198
}
198
}
199
199
200
=head3 get_epoch
201
202
    $epoch = Koha::Illrequest::Logger->get_epoch($timestamp);
203
204
Given a timestamp string returned from GetLogs, get the epoch
205
206
=cut
207
208
sub get_epoch {
209
    my $timestamp = shift;
210
211
    return if !$timestamp=~/\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}/;
212
213
    my ($date, $time) = split(/\s/, $timestamp);
214
    my ($y, $mon, $d) = split(/-/, $date);
215
    my ($h, $min, $s) = split(/:/, $time);
216
217
    return timelocal($s, $min, $h, $d, $mon-1, $y);
218
}
219
200
=head3 get_request_logs
220
=head3 get_request_logs
201
221
202
    $requestlogs = Koha::IllRequest::Logger->get_request_logs($request_id);
222
    $requestlogs = Koha::IllRequest::Logger->get_request_logs($request_id);
Lines 230-236 sub get_request_logs { Link Here
230
    }
250
    }
231
251
232
    my $format = '%Y-%m-%d %H:%M:%S';
252
    my $format = '%Y-%m-%d %H:%M:%S';
233
    my @sorted = sort {Time::Piece->strptime($$b{'timestamp'}, $format)->epoch <=> Time::Piece->strptime($$a{'timestamp'}, $format)->epoch} @{$logs};
253
    my @sorted = sort { get_epoch($$b{'timestamp'}) <=> get_epoch($$a{'timestamp'}) } @{$logs};
234
254
235
    return \@sorted;
255
    return \@sorted;
236
}
256
}
(-)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