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

(-)a/Koha/Illbatch.pm (+85 lines)
Lines 19-24 package Koha::Illbatch; Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Koha::Database;
21
use Koha::Database;
22
use Koha::Illrequest::Logger;
23
use JSON qw( to_json );
22
use base qw(Koha::Object);
24
use base qw(Koha::Object);
23
25
24
=head1 NAME
26
=head1 NAME
Lines 72-77 sub requests_count { Link Here
72
    })->count;
74
    })->count;
73
}
75
}
74
76
77
=head3 create_and_log
78
79
    $batch->create_and_log;
80
81
Log batch creation following storage
82
83
=cut
84
85
sub create_and_log {
86
    my ( $self ) = @_;
87
88
    $self->store;
89
90
    my $logger = Koha::Illrequest::Logger->new;
91
92
    $logger->log_something({
93
        modulename   => 'ILL',
94
        actionname  => 'batch_create',
95
        objectnumber => $self->id,
96
        infos        => to_json({})
97
    });
98
}
99
100
=head3 update_and_log
101
102
    $batch->update_and_log;
103
104
Log batch update following storage
105
106
=cut
107
108
sub update_and_log {
109
    my ( $self, $params ) = @_;
110
111
    my $before = {
112
        name       => $self->name,
113
        branchcode => $self->branchcode
114
    };
115
116
    $self->set( $params );
117
    my $update = $self->store;
118
119
    my $after = {
120
        name       => $self->name,
121
        branchcode => $self->branchcode
122
    };
123
124
    my $logger = Koha::Illrequest::Logger->new;
125
126
    $logger->log_something({
127
        modulename   => 'ILL',
128
        actionname  => 'batch_update',
129
        objectnumber => $self->id,
130
        infos        => to_json({
131
            before => $before,
132
            after  => $after
133
        })
134
    });
135
}
136
137
=head3 delete_and_log
138
139
    $batch->delete_and_log;
140
141
Log batch delete
142
143
=cut
144
145
sub delete_and_log {
146
    my ( $self ) = @_;
147
148
    my $logger = Koha::Illrequest::Logger->new;
149
150
    $logger->log_something({
151
        modulename   => 'ILL',
152
        actionname  => 'batch_delete',
153
        objectnumber => $self->id,
154
        infos        => to_json({})
155
    });
156
157
    $self->delete;
158
}
159
75
=head2 Internal methods
160
=head2 Internal methods
76
161
77
=head3 _type
162
=head3 _type
(-)a/Koha/REST/V1/Illbatches.pm (-5 / +3 lines)
Lines 129-135 sub add { Link Here
129
129
130
    return try {
130
    return try {
131
        my $batch = Koha::Illbatch->new( $body );
131
        my $batch = Koha::Illbatch->new( $body );
132
        $batch->store;
132
        $batch->create_and_log;
133
        $c->res->headers->location( $c->req->url->to_string . '/' . $batch->id );
133
        $c->res->headers->location( $c->req->url->to_string . '/' . $batch->id );
134
134
135
        my $ret = {
135
        my $ret = {
Lines 171-178 sub update { Link Here
171
    delete $params->{cardnumber};
171
    delete $params->{cardnumber};
172
172
173
    return try {
173
    return try {
174
        $batch->set( $params );
174
        $batch->update_and_log( $params );
175
        $batch->store();
176
175
177
        my $ret = {
176
        my $ret = {
178
            %{$batch->unblessed},
177
            %{$batch->unblessed},
Lines 208-214 sub delete { Link Here
208
    }
207
    }
209
208
210
    return try {
209
    return try {
211
        $batch->delete;
210
        $batch->delete_and_log;
212
        return $c->render( status => 204, openapi => '');
211
        return $c->render( status => 204, openapi => '');
213
    }
212
    }
214
    catch {
213
    catch {
215
- 

Return to bug 30719