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

(-)a/debian/templates/koha-conf-site.xml.in (+4 lines)
Lines 491-495 __END_SRU_PUBLICSERVER__ Link Here
491
491
492
 <mfa_range>1</mfa_range><!-- Number of 30 second iterations to allow for MFA code checking -->
492
 <mfa_range>1</mfa_range><!-- Number of 30 second iterations to allow for MFA code checking -->
493
493
494
 <auto_renew_cronjob>
495
   <parallel_loops_count>1</parallel_loops_count>
496
 </auto_renew_cronjob>
497
494
</config>
498
</config>
495
</yazgfs>
499
</yazgfs>
(-)a/etc/koha-conf.xml (+4 lines)
Lines 302-306 Link Here
302
302
303
 <mfa_range>1</mfa_range><!-- Number of 30 second iterations to allow for MFA code checking -->
303
 <mfa_range>1</mfa_range><!-- Number of 30 second iterations to allow for MFA code checking -->
304
304
305
 <auto_renew_cronjob>
306
   <parallel_loops_count>1</parallel_loops_count>
307
 </auto_renew_cronjob>
308
305
</config>
309
</config>
306
</yazgfs>
310
</yazgfs>
(-)a/misc/cronjobs/automatic_renewals.pl (-9 / +52 lines)
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
- 

Return to bug 29507