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

(-)a/Koha/Illrequest/Logger.pm (-40 / +25 lines)
Lines 49-56 relating to Illrequest to the action log. Link Here
49
49
50
    my $config = Koha::Illrequest::Logger->new();
50
    my $config = Koha::Illrequest::Logger->new();
51
51
52
Create a new Koha::Illrequest::Logger object, with skeleton logging data
52
Create a new Koha::Illrequest::Logger object.
53
We also set up data of what can be logged, how to do it and how to display
53
We also set up what can be logged, how to do it and how to display
54
log entries we get back out
54
log entries we get back out
55
55
56
=cut
56
=cut
Lines 59-68 sub new { Link Here
59
    my ( $class ) = @_;
59
    my ( $class ) = @_;
60
    my $self  = {};
60
    my $self  = {};
61
61
62
    $self->{data} = {
63
        modulename => 'ILL'
64
    };
65
66
    $self->{loggers} = {
62
    $self->{loggers} = {
67
        status => sub {
63
        status => sub {
68
            $self->log_status_change(@_);
64
            $self->log_status_change(@_);
Lines 105-111 sub log_maybe { Link Here
105
101
106
=head3 log_status_change
102
=head3 log_status_change
107
103
108
    Koha::IllRequest::Logger->log_status_change();
104
    Koha::IllRequest::Logger->log_status_change($req, $new_status);
109
105
110
Log a request's status change
106
Log a request's status change
111
107
Lines 114-120 Log a request's status change Link Here
114
sub log_status_change {
110
sub log_status_change {
115
    my ( $self, $req, $new_status ) = @_;
111
    my ( $self, $req, $new_status ) = @_;
116
112
117
    $self->set_data({
113
    $self->log_something({
114
        modulename   => 'ILL',
118
        actionname   => 'STATUS_CHANGE',
115
        actionname   => 'STATUS_CHANGE',
119
        objectnumber => $req->id,
116
        objectnumber => $req->id,
120
        infos        => to_json({
117
        infos        => to_json({
Lines 123-178 sub log_status_change { Link Here
123
            status_after  => $new_status
120
            status_after  => $new_status
124
        })
121
        })
125
    });
122
    });
126
127
    $self->log_something();
128
}
123
}
129
124
130
=head3 log_something
125
=head3 log_something
131
126
132
    Koha::IllRequest::Logger->log_something();
127
    Koha::IllRequest::Logger->log_something({
128
        modulename   => 'ILL',
129
        actionname   => 'STATUS_CHANGE',
130
        objectnumber => $req->id,
131
        infos        => to_json({
132
            log_origin    => 'core',
133
            status_before => $req->{previous_status},
134
            status_after  => $new_status
135
        })
136
    });
133
137
134
If we have the required data set, log an action
138
If we have the required data passed, log an action
135
139
136
=cut
140
=cut
137
141
138
sub log_something {
142
sub log_something {
139
    my ( $self ) = @_;
143
    my ( $self, $to_log ) = @_;
140
144
141
    if (
145
    if (
142
        defined $self->{data}->{modulename} &&
146
        defined $to_log->{modulename} &&
143
        defined $self->{data}->{actionname} &&
147
        defined $to_log->{actionname} &&
144
        defined $self->{data}->{objectnumber} &&
148
        defined $to_log->{objectnumber} &&
145
        defined $self->{data}->{infos} &&
149
        defined $to_log->{infos} &&
146
        C4::Context->preference("IllLog")
150
        C4::Context->preference("IllLog")
147
    ) {
151
    ) {
148
        logaction(
152
        logaction(
149
            $self->{data}->{modulename},
153
            $to_log->{modulename},
150
            $self->{data}->{actionname},
154
            $to_log->{actionname},
151
            $self->{data}->{objectnumber},
155
            $to_log->{objectnumber},
152
            $self->{data}->{infos}
156
            $to_log->{infos}
153
        );
157
        );
154
    }
158
    }
155
}
159
}
156
160
157
=head3 set_data
158
159
    Koha::IllRequest::Logger->set_data({
160
        key  => 'value',
161
        key2 => 'value2'
162
    });
163
164
Set arbitrary data propert(ies) on the logger object
165
166
=cut
167
168
sub set_data {
169
    my ( $self, $data ) = @_;
170
171
    foreach my $key (keys %{ $data }) {
172
        $self->{data}->{$key} = $data->{$key};
173
    }
174
}
175
176
=head3 get_log_template
161
=head3 get_log_template
177
162
178
    $template_path = get_log_template($origin, $action);
163
    $template_path = get_log_template($origin, $action);
(-)a/t/db_dependent/Illrequest/Logger.t (-12 / +2 lines)
Lines 57-63 use_ok('Koha::Illrequest::Logger'); Link Here
57
57
58
subtest 'Basics' => sub {
58
subtest 'Basics' => sub {
59
59
60
    plan tests => 9;
60
    plan tests => 7;
61
61
62
    $schema->storage->txn_begin;
62
    $schema->storage->txn_begin;
63
63
Lines 68-75 subtest 'Basics' => sub { Link Here
68
    ok( defined($logger), 'new() returned something' );
68
    ok( defined($logger), 'new() returned something' );
69
    ok( $logger->isa('Koha::Illrequest::Logger'),
69
    ok( $logger->isa('Koha::Illrequest::Logger'),
70
        'new() returns the correct object' );
70
        'new() returns the correct object' );
71
    is_deeply($logger->{data}, {modulename => 'ILL'},
72
        'new() setting modulename');
73
71
74
    # This is an incomplete data hashref, we use it to
72
    # This is an incomplete data hashref, we use it to
75
    # test validation of the data before logging
73
    # test validation of the data before logging
Lines 79-90 subtest 'Basics' => sub { Link Here
79
        infos        => 'infos'
77
        infos        => 'infos'
80
    };
78
    };
81
79
82
    # set_data()
83
    #
84
    $logger->set_data($log_obj);
85
    is_deeply($logger->{data}->{actionname}, 'actionname',
86
        'set_data() setter works');
87
88
    # log_something()
80
    # log_something()
89
    #
81
    #
90
    # Do we only log when the pref is set (currently unset)
82
    # Do we only log when the pref is set (currently unset)
Lines 100-107 subtest 'Basics' => sub { Link Here
100
92
101
    # Fix the data hashref, then test that logging occurs
93
    # Fix the data hashref, then test that logging occurs
102
    $log_obj->{objectnumber} = 'objectnumber';
94
    $log_obj->{objectnumber} = 'objectnumber';
103
    $logger->set_data($log_obj);
95
    is($logger->log_something($log_obj), 1,
104
    is($logger->log_something(), 1,
105
        'logaction() being called when pref is set and data is complete');
96
        'logaction() being called when pref is set and data is complete');
106
97
107
    # log_maybe()
98
    # log_maybe()
108
- 

Return to bug 20750