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

(-)a/Koha/Illrequest.pm (-9 / +12 lines)
Lines 212-221 sub status_alias { Link Here
212
        my $val_to_log = $val ? $new_status_alias : scalar $self->status;
212
        my $val_to_log = $val ? $new_status_alias : scalar $self->status;
213
        if ($ret) {
213
        if ($ret) {
214
            my $logger = Koha::Illrequest::Logger->new;
214
            my $logger = Koha::Illrequest::Logger->new;
215
            $logger->log_status_change(
215
            $logger->log_status_change({
216
                $self,
216
                request => $self,
217
                $val_to_log
217
                value   => $val_to_log
218
            );
218
            });
219
        } else {
219
        } else {
220
            delete $self->{previous_status};
220
            delete $self->{previous_status};
221
        }
221
        }
Lines 269-278 sub status { Link Here
269
            $self->status_alias("-1");
269
            $self->status_alias("-1");
270
        } else {
270
        } else {
271
            my $logger = Koha::Illrequest::Logger->new;
271
            my $logger = Koha::Illrequest::Logger->new;
272
            $logger->log_status_change(
272
            $logger->log_status_change({
273
                $self,
273
                request => $self,
274
                $new_status
274
                value   => $new_status
275
            );
275
            });
276
        }
276
        }
277
        delete $self->{previous_status};
277
        delete $self->{previous_status};
278
        return $ret;
278
        return $ret;
Lines 1178-1184 sub store { Link Here
1178
1178
1179
    if ($ret && defined $attrs) {
1179
    if ($ret && defined $attrs) {
1180
        my $logger = Koha::Illrequest::Logger->new;
1180
        my $logger = Koha::Illrequest::Logger->new;
1181
        $logger->log_maybe($self, $attrs);
1181
        $logger->log_maybe({
1182
            request => $self,
1183
            attrs   => $attrs
1184
        });
1182
    }
1185
    }
1183
1186
1184
    return $ret;
1187
    return $ret;
(-)a/Koha/Illrequest/Logger.pm (-32 / +36 lines)
Lines 79-99 sub new { Link Here
79
79
80
=head3 log_maybe
80
=head3 log_maybe
81
81
82
    Koha::IllRequest::Logger->log_maybe($attrs);
82
    Koha::IllRequest::Logger->log_maybe($params);
83
83
84
Receive request object and an attributes hashref (which may or may
84
Receive params hashref, containing a request object and an attrs
85
not be defined) If the hashref contains a key matching our "loggers" hashref
85
hashref (which may or may not be defined) If the attrs hashref contains
86
then we want to log it
86
a key matching our "loggers" hashref then we want to log it
87
87
88
=cut
88
=cut
89
89
90
sub log_maybe {
90
sub log_maybe {
91
    my ($self, $req, $attrs) = @_;
91
    my ($self, $params) = @_;
92
92
93
    if (defined $req && defined $attrs) {
93
    if (defined $params->{request} && defined $params->{attrs}) {
94
        foreach my $key (keys %{ $attrs }) {
94
        foreach my $key (keys %{ $params->{attrs} }) {
95
            if (defined($self->{loggers}->{$key})) {
95
            if (defined($self->{loggers}->{$key})) {
96
                $self->{loggers}->{$key}($req, $attrs->{$key});
96
                $self->{loggers}->{$key}(
97
                    $params->{request},
98
                    $params->{attrs}->{$key}
99
                );
97
            }
100
            }
98
        }
101
        }
99
    }
102
    }
Lines 101-125 sub log_maybe { Link Here
101
104
102
=head3 log_status_change
105
=head3 log_status_change
103
106
104
    Koha::IllRequest::Logger->log_status_change($req, $new_status);
107
    Koha::IllRequest::Logger->log_status_change($params);
105
108
106
Log a request's status change
109
Receive a hashref containing a request object and a status to log,
110
and log it
107
111
108
=cut
112
=cut
109
113
110
sub log_status_change {
114
sub log_status_change {
111
    my ( $self, $req, $new_status ) = @_;
115
    my ( $self, $params ) = @_;
112
116
113
    $self->log_something({
117
    if (defined $params->{request} && defined $params->{value}) {
114
        modulename   => 'ILL',
118
        $self->log_something({
115
        actionname   => 'STATUS_CHANGE',
119
            modulename   => 'ILL',
116
        objectnumber => $req->id,
120
            actionname   => 'STATUS_CHANGE',
117
        infos        => to_json({
121
            objectnumber => $params->{request}->id,
118
            log_origin    => 'core',
122
            infos        => to_json({
119
            status_before => $req->{previous_status},
123
                log_origin    => 'core',
120
            status_after  => $new_status
124
                status_before => $params->{request}->{previous_status},
121
        })
125
                status_after  => $params->{value}
122
    });
126
            })
127
        });
128
    }
123
}
129
}
124
130
125
=head3 log_something
131
=head3 log_something
Lines 160-173 sub log_something { Link Here
160
166
161
=head3 get_log_template
167
=head3 get_log_template
162
168
163
    $template_path = get_log_template($origin, $action);
169
    $template_path = get_log_template($params);
164
170
165
Given a log's origin and action, get the appropriate display template
171
Given a log's origin and action, get the appropriate display template
166
172
167
=cut
173
=cut
168
174
169
sub get_log_template {
175
sub get_log_template {
170
    my ($self, $req, $params) = @_;
176
    my ($self, $params) = @_;
171
177
172
    my $origin = $params->{origin};
178
    my $origin = $params->{origin};
173
    my $action = $params->{action};
179
    my $action = $params->{action};
Lines 179-185 sub get_log_template { Link Here
179
    } else {
185
    } else {
180
        # It's probably a backend log, so we need to get the path to the
186
        # It's probably a backend log, so we need to get the path to the
181
        # template from the backend
187
        # template from the backend
182
        my $backend =$req->{_my_backend};
188
        my $backend =$params->{request}->{_my_backend};
183
        return $backend->get_log_template_path($action);
189
        return $backend->get_log_template_path($action);
184
    }
190
    }
185
}
191
}
Lines 212-224 sub get_request_logs { Link Here
212
    foreach my $log(@{$logs}) {
218
    foreach my $log(@{$logs}) {
213
        $log->{aliases} = $alias_hash;
219
        $log->{aliases} = $alias_hash;
214
        $log->{info} = from_json($log->{info});
220
        $log->{info} = from_json($log->{info});
215
        $log->{template} = $self->get_log_template(
221
        $log->{template} = $self->get_log_template({
216
        $request,
222
            request => $request,
217
            {
223
            origin => $log->{info}->{log_origin},
218
                origin => $log->{info}->{log_origin},
224
            action => $log->{action}
219
                action => $log->{action}
225
        });
220
            }
221
        );
222
    }
226
    }
223
227
224
    return $logs;
228
    return $logs;
(-)a/t/db_dependent/Illrequest/Logger.t (-5 / +5 lines)
Lines 103-112 subtest 'Basics' => sub { Link Here
103
    # get_log_template()
103
    # get_log_template()
104
    #
104
    #
105
    is(
105
    is(
106
        $logger->get_log_template(
106
        $logger->get_log_template({
107
            {},
107
            request => {},
108
            { origin => 'core', 'action' => 'STATUS_CHANGE' }
108
            origin => 'core',
109
        ),
109
            action => 'STATUS_CHANGE'
110
        }),
110
        'base/status_change.tt',
111
        'base/status_change.tt',
111
        'get_log_template() fetches correct core template'
112
        'get_log_template() fetches correct core template'
112
    );
113
    );
113
- 

Return to bug 20750