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