use Koha::Patrons;
use Koha::Patron::Categories;
use Koha::DateUtils;
-use Data::Dumper;
+use Koha::Script -cron;
=head1 NAME
Prints the manual page and exits.
-=item B<--verbosse | -v>
+=item B<--verbose | -v>
Verbose. Without this flag set, only fatal errors are reported.
Supply a number and only account with fines over this number will be updated.
-=item B<==fineunder=X | -fu=X>
+=item B<--fineunder=X | -fu=X>
Supply a number and only account with fines under this number will be updated.
'ra|regafter=s' => \$reg_aft,
'b|branch=s' => \$branch_lim,
'd|field=s' => \%fields
-) or pod2usage(2);
+);
+
pod2usage(1) if $help;
-pod2usage( -verbose => 2 ) if $man;
-warn "v $verbose c $doit f $fromcat t $tocat";
-exit;
+pod2usage( -verbose => 2 ) if $man;
if ( not $fromcat && $tocat ) { #make sure we've specified the info we need.
- print
-"Must supply category from and to (-f & -t) please specify -help for usage tips.\n";
+ print "Must supply category from and to (-f & -t) please specify -help for usage tips.\n";
+ pod2usage(1);
exit;
}
( $verbose && !$doit ) and print "No actions will be taken (test mode)\n";
-$verbose
- and print
-"Will update patrons from $fromcat to $tocat with conditions below (if any)\n";
+$verbose and print "Will update patrons from $fromcat to $tocat with conditions below (if any)\n";
my %params;
if ( defined $reg_bef ) {
eval { $date_bef = dt_from_string( $reg_bef, 'iso' ); };
}
- die
-"$reg_bef is not a valid date before, aborting! Use a date in format YYYY-MM-DD.$@"
- if $@;
+ die "$reg_bef is not a valid date before, aborting! Use a date in format YYYY-MM-DD.$@"
+ if $@;
if ( defined $reg_aft ) {
eval { $date_aft = dt_from_string( $reg_aft, 'iso' ); };
}
- die
-"$reg_bef is not a valid date after, aborting! Use a date in format YYYY-MM-DD.$@"
- if $@;
+ die "$reg_bef is not a valid date after, aborting! Use a date in format YYYY-MM-DD.$@"
+ if $@;
$params{dateenrolled}{'<='} = $reg_bef if defined $date_bef;
$params{dateenrolled}{'>='} = $reg_aft if defined $date_aft;
}
$verbose and print " Borrower column $key is equal to $value\n";
$params{ "me." . $key } = $value;
}
-
-my $target_patrons = Koha::Patrons->search({ search_params => \%params })->search_patrons_to_update(
+my $target_patrons = Koha::Patrons->search(\%params)->search_patrons_to_update_category(
{
from => $fromcat,
search_params => \%params,
fine_max => $fine_max,
}
);
+
my $patrons_found = $target_patrons->count;
my $actually_updated = 0;
my $testdisplay = $doit ? "" : "WOULD HAVE ";
if ($verbose) {
while ( my $target_patron = $target_patrons->next() ) {
- my $target = Koha::Patrons->find( $target_patron->borrowernumber );
+ $target_patron->discard_changes();
$verbose
and print $testdisplay
. "Updated "
- . $target->firstname . " "
- . $target->surname
+ . $target_patron->firstname() . " "
+ . $target_patron->surname()
. " from $fromcat to $tocat\n";
}
$target_patrons->reset;
}
if ($doit) {
- $actually_updated = $target_patrons->update_category( { to => $tocat } );
+ $actually_updated = $target_patrons->update_category_to( { category => $tocat } );
}
$verbose and print "$patrons_found found, $actually_updated updated\n";