Lines 75-81
chosen 'Digests only' on the advance messages.
Link Here
|
75 |
=cut |
75 |
=cut |
76 |
|
76 |
|
77 |
use Modern::Perl; |
77 |
use Modern::Perl; |
78 |
use Pod::Usage qw( pod2usage ); |
78 |
use Parallel::ForkManager; |
|
|
79 |
use Pod::Usage qw( pod2usage ); |
79 |
use Getopt::Long qw( GetOptions ); |
80 |
use Getopt::Long qw( GetOptions ); |
80 |
|
81 |
|
81 |
use Koha::Script -cron; |
82 |
use Koha::Script -cron; |
Lines 135-141
$verbose = 1 unless $verbose or $confirm;
Link Here
|
135 |
print "Test run only\n" unless $confirm; |
136 |
print "Test run only\n" unless $confirm; |
136 |
|
137 |
|
137 |
print "getting auto renewals\n" if $verbose; |
138 |
print "getting auto renewals\n" if $verbose; |
138 |
my $auto_renews = Koha::Checkouts->search( |
139 |
my @auto_renews = Koha::Checkouts->search( |
139 |
{ |
140 |
{ |
140 |
auto_renew => 1, |
141 |
auto_renew => 1, |
141 |
'patron.autorenew_checkouts' => 1, |
142 |
'patron.autorenew_checkouts' => 1, |
Lines 143-155
my $auto_renews = Koha::Checkouts->search(
Link Here
|
143 |
{ |
144 |
{ |
144 |
join => ['patron','item'] |
145 |
join => ['patron','item'] |
145 |
} |
146 |
} |
146 |
); |
147 |
)->as_list; |
147 |
print "found " . $auto_renews->count . " auto renewals\n" if $verbose; |
148 |
print "found " . scalar @auto_renews . " auto renewals\n" if $verbose; |
|
|
149 |
|
150 |
my $cron_options = C4::Context->config('auto_renew_cronjob'); |
151 |
my $loops = $cron_options ? $cron_options->{parallel_loops_count} // 1 : 1; |
152 |
|
153 |
# Split the list of issues into chunks to run in parallel |
154 |
my @chunks; |
155 |
if ( $loops > 1 ) { |
156 |
my $i = 0; |
157 |
my $borrowernumber = 0; |
158 |
while (@auto_renews) { |
159 |
my $auto_renew = pop(@auto_renews); |
160 |
if ( $borrowernumber != $auto_renew->borrowernumber ) { |
161 |
$i++ if $borrowernumber; |
162 |
$borrowernumber = $auto_renew->borrowernumber; |
163 |
} |
164 |
$i = 0 if $i >= $loops; |
165 |
push( @{ $chunks[$i] }, $auto_renew ); |
166 |
} |
167 |
my $pm = Parallel::ForkManager->new($loops); |
168 |
DATA_LOOP: |
169 |
foreach my $chunk (@chunks) { |
170 |
my $pid = $pm->start and next DATA_LOOP; |
171 |
_ProcessRenewals($chunk); |
172 |
$pm->finish; |
173 |
} |
174 |
$pm->wait_all_children; |
175 |
} |
176 |
else { |
177 |
_ProcessRenewals( \@auto_renews ); |
178 |
} |
179 |
|
180 |
cronlogaction({ action => 'End', info => "COMPLETED" }); |
181 |
|
182 |
|
183 |
=head1 METHODS |
184 |
|
185 |
=head2 _ProcessRenewals |
186 |
|
187 |
Internal method to process the queue in chunks |
188 |
|
189 |
=cut |
190 |
|
191 |
sub _ProcessRenewals { |
192 |
my $auto_renew_issues = shift; |
148 |
|
193 |
|
149 |
my $renew_digest = {}; |
194 |
my $renew_digest = {}; |
150 |
my %report; |
195 |
my %report; |
151 |
my @item_renewal_ids; |
196 |
my @item_renewal_ids; |
152 |
while ( my $auto_renew = $auto_renews->next ) { |
197 |
|
|
|
198 |
foreach my $auto_renew (@$auto_renew_issues) { |
153 |
print "examining item '" . $auto_renew->itemnumber . "' to auto renew\n" if $verbose; |
199 |
print "examining item '" . $auto_renew->itemnumber . "' to auto renew\n" if $verbose; |
154 |
|
200 |
|
155 |
my ( $borrower_preferences, $wants_messages, $wants_digest ) = ( undef, 0, 0 ); |
201 |
my ( $borrower_preferences, $wants_messages, $wants_digest ) = ( undef, 0, 0 ); |
Lines 295-303
if ( $send_notices && $confirm ) {
Link Here
|
295 |
} |
341 |
} |
296 |
} |
342 |
} |
297 |
|
343 |
|
298 |
cronlogaction({ action => 'End', info => "COMPLETED" }); |
344 |
} |
299 |
|
|
|
300 |
=head1 METHODS |
301 |
|
345 |
|
302 |
=head2 send_digests |
346 |
=head2 send_digests |
303 |
|
347 |
|
304 |
- |
|
|