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

(-)a/Koha/Patrons.pm (-12 / +5 lines)
Lines 402-422 sub search_patrons_to_update_category { Link Here
402
    my $cat_from = Koha::Patron::Categories->find($params->{from});
402
    my $cat_from = Koha::Patron::Categories->find($params->{from});
403
    $search_params->{categorycode}=$params->{from};
403
    $search_params->{categorycode}=$params->{from};
404
    if ($params->{too_young} || $params->{too_old}){
404
    if ($params->{too_young} || $params->{too_old}){
405
        my $dtf = Koha::Database->new->schema->storage->datetime_parser;
405
        if( $cat_from->dateofbirthrequired && $params->{too_young} ) {
406
        if( $cat_from->dateofbirthrequired && $params->{too_young} ) {
406
            my $date_after = output_pref({
407
            my $date_after = dt_from_string()->subtract( years => $cat_from->dateofbirthrequired);
407
                dt         => dt_from_string()->subtract( years => $cat_from->dateofbirthrequired),
408
            $search_params->{dateofbirth}{'>'} = $dtf->format_datetime( $date_after );
408
                dateonly   => 1,
409
                dateformat => 'sql'
410
            });
411
            $search_params->{dateofbirth}{'>'} = $date_after;
412
        }
409
        }
413
        if( $cat_from->upperagelimit && $params->{too_old} ) {
410
        if( $cat_from->upperagelimit && $params->{too_old} ) {
414
            my $date_before = output_pref({
411
            my $date_before = dt_from_string()->subtract( years => $cat_from->upperagelimit);
415
                dt         => dt_from_string()->subtract( years => $cat_from->upperagelimit),
412
            $search_params->{dateofbirth}{'<'} = $dtf->format_datetime( $date_before );
416
                dateonly   => 1,
417
                dateformat => 'sql'
418
            });
419
            $search_params->{dateofbirth}{'<'} = $date_before;
420
        }
413
        }
421
    }
414
    }
422
    if ($params->{fine_min} || $params->{fine_max}) {
415
    if ($params->{fine_min} || $params->{fine_max}) {
(-)a/misc/cronjobs/update_patrons_category.pl (-20 / +13 lines)
Lines 107-113 Update patron only if they are below the minimum age range specified for the 'fr Link Here
107
107
108
Supply a number and only account with fines over this number will be updated.
108
Supply a number and only account with fines over this number will be updated.
109
109
110
=item B<==fineunder=X | -fu=X>
110
=item B<--fineunder=X | -fu=X>
111
111
112
Supply a number and only account with fines under this number will be updated.
112
Supply a number and only account with fines under this number will be updated.
113
113
Lines 179-202 GetOptions( Link Here
179
    'ra|regafter=s'   => \$reg_aft,
179
    'ra|regafter=s'   => \$reg_aft,
180
    'b|branch=s'      => \$branch_lim,
180
    'b|branch=s'      => \$branch_lim,
181
    'd|field=s'       => \%fields
181
    'd|field=s'       => \%fields
182
) or pod2usage(2);
182
);
183
183
pod2usage(1) if $help;
184
pod2usage(1) if $help;
184
pod2usage( -verbose => 2 ) if $man;
185
185
186
warn "v $verbose c $doit f $fromcat t $tocat";
186
pod2usage( -verbose => 2 ) if $man;
187
exit;
188
187
189
if ( not $fromcat && $tocat ) {    #make sure we've specified the info we need.
188
if ( not $fromcat && $tocat ) {    #make sure we've specified the info we need.
190
    print
189
    print "Must supply category from and to (-f & -t) please specify -help for usage tips.\n";
191
"Must supply category from and to (-f & -t) please specify -help for usage tips.\n";
190
    pod2usage(1);
192
    exit;
191
    exit;
193
}
192
}
194
193
195
( $verbose && !$doit ) and print "No actions will be taken (test mode)\n";
194
( $verbose && !$doit ) and print "No actions will be taken (test mode)\n";
196
195
197
$verbose
196
$verbose and print "Will update patrons from $fromcat to $tocat with conditions below (if any)\n";
198
  and print
199
"Will update patrons from $fromcat to $tocat with conditions below (if any)\n";
200
197
201
my %params;
198
my %params;
202
199
Lines 206-220 if ( $reg_bef || $reg_aft ) { Link Here
206
    if ( defined $reg_bef ) {
203
    if ( defined $reg_bef ) {
207
        eval { $date_bef = dt_from_string( $reg_bef, 'iso' ); };
204
        eval { $date_bef = dt_from_string( $reg_bef, 'iso' ); };
208
    }
205
    }
209
    die
206
    die "$reg_bef is not a valid date before, aborting! Use a date in format YYYY-MM-DD.$@"
210
"$reg_bef is not a valid date before, aborting! Use a date in format YYYY-MM-DD.$@"
207
        if $@;
211
      if $@;
212
    if ( defined $reg_aft ) {
208
    if ( defined $reg_aft ) {
213
        eval { $date_aft = dt_from_string( $reg_aft, 'iso' ); };
209
        eval { $date_aft = dt_from_string( $reg_aft, 'iso' ); };
214
    }
210
    }
215
    die
211
    die "$reg_bef is not a valid date after, aborting! Use a date in format YYYY-MM-DD.$@"
216
"$reg_bef is not a valid date after, aborting! Use a date in format YYYY-MM-DD.$@"
212
        if $@;
217
      if $@;
218
    $params{dateenrolled}{'<='} = $reg_bef if defined $date_bef;
213
    $params{dateenrolled}{'<='} = $reg_bef if defined $date_bef;
219
    $params{dateenrolled}{'>='} = $reg_aft if defined $date_aft;
214
    $params{dateenrolled}{'>='} = $reg_aft if defined $date_aft;
220
}
215
}
Lines 243-250 while ( my ( $key, $value ) = each %fields ) { Link Here
243
    $verbose and print "    Borrower column $key is equal to $value\n";
238
    $verbose and print "    Borrower column $key is equal to $value\n";
244
    $params{ "me." . $key } = $value;
239
    $params{ "me." . $key } = $value;
245
}
240
}
246
241
my $target_patrons = Koha::Patrons->search(\%params)->search_patrons_to_update_category(
247
my $target_patrons = Koha::Patrons->search({ search_params => \%params })->search_patrons_to_update(
248
    {
242
    {
249
        from          => $fromcat,
243
        from          => $fromcat,
250
        search_params => \%params,
244
        search_params => \%params,
Lines 270-276 if ($verbose) { Link Here
270
    $target_patrons->reset;
264
    $target_patrons->reset;
271
}
265
}
272
if ($doit) {
266
if ($doit) {
273
    $actually_updated = $target_patrons->update_category( { to => $tocat } );
267
    $actually_updated = $target_patrons->update_category_to( { category => $tocat } );
274
}
268
}
275
269
276
$verbose and print "$patrons_found found, $actually_updated updated\n";
270
$verbose and print "$patrons_found found, $actually_updated updated\n";
277
- 

Return to bug 17168