|
Lines 22-27
use warnings;
Link Here
|
| 22 |
|
22 |
|
| 23 |
use Koha::Script; |
23 |
use Koha::Script; |
| 24 |
use C4::Context; |
24 |
use C4::Context; |
|
|
25 |
use C4::Log qw(cronlogaction); |
| 25 |
use C4::Members::Messaging; |
26 |
use C4::Members::Messaging; |
| 26 |
use Getopt::Long qw( GetOptions ); |
27 |
use Getopt::Long qw( GetOptions ); |
| 27 |
use Pod::Usage qw( pod2usage ); |
28 |
use Pod::Usage qw( pod2usage ); |
|
Lines 32-40
sub usage {
Link Here
|
| 32 |
} |
33 |
} |
| 33 |
|
34 |
|
| 34 |
sub force_borrower_messaging_defaults { |
35 |
sub force_borrower_messaging_defaults { |
| 35 |
my ( $doit, $since, $not_expired, $no_overwrite, $category, $branchcode, $message_name ) = @_; |
36 |
my ( $doit, $since, $not_expired, $no_overwrite, $category, $branchcode, $message_name, $verbose ) = @_; |
| 36 |
|
37 |
|
| 37 |
print "Since: $since\n" if $since; |
38 |
print "Since: $since\n" if $since; |
|
|
39 |
my $update_statement = $doit ? "Updating" : "Would have updated"; |
| 38 |
|
40 |
|
| 39 |
my $dbh = C4::Context->dbh; |
41 |
my $dbh = C4::Context->dbh; |
| 40 |
$dbh->{AutoCommit} = 0; |
42 |
$dbh->{AutoCommit} = 0; |
|
Lines 58-64
WHERE 1|;
Link Here
|
| 58 |
$sth->execute( $since || (), $category || (), $branchcode || () ); |
60 |
$sth->execute( $since || (), $category || (), $branchcode || () ); |
| 59 |
my $cnt = 0; |
61 |
my $cnt = 0; |
| 60 |
while ( my ( $borrowernumber, $categorycode ) = $sth->fetchrow ) { |
62 |
while ( my ( $borrowernumber, $categorycode ) = $sth->fetchrow ) { |
| 61 |
print "$borrowernumber: $categorycode\n"; |
63 |
print "$update_statement borrowernumber: $borrowernumber : category ($categorycode)\n" if $verbose; |
| 62 |
next unless $doit; |
64 |
next unless $doit; |
| 63 |
my $options = { |
65 |
my $options = { |
| 64 |
borrowernumber => $borrowernumber, |
66 |
borrowernumber => $borrowernumber, |
|
Lines 72-78
WHERE 1|;
Link Here
|
| 72 |
print "Total borrowers updated: $cnt\n" if $doit; |
74 |
print "Total borrowers updated: $cnt\n" if $doit; |
| 73 |
} |
75 |
} |
| 74 |
|
76 |
|
| 75 |
my ( $doit, $since, $help, $not_expired, $no_overwrite, $category, $branchcode, $message_name ); |
77 |
my ( $doit, $since, $help, $not_expired, $no_overwrite, $category, $branchcode, $message_name, $verbose ); |
| 76 |
my $result = GetOptions( |
78 |
my $result = GetOptions( |
| 77 |
'doit' => \$doit, |
79 |
'doit' => \$doit, |
| 78 |
'since:s' => \$since, |
80 |
'since:s' => \$since, |
|
Lines 82-92
my $result = GetOptions(
Link Here
|
| 82 |
'library:s' => \$branchcode, |
84 |
'library:s' => \$branchcode, |
| 83 |
'message-name:s' => \$message_name, |
85 |
'message-name:s' => \$message_name, |
| 84 |
'help|h' => \$help, |
86 |
'help|h' => \$help, |
|
|
87 |
'verbose|v+' => \$verbose, |
| 85 |
); |
88 |
); |
| 86 |
|
89 |
|
|
|
90 |
my $command_line_options = join( " ", @ARGV ); |
| 91 |
|
| 92 |
if ($doit) { |
| 93 |
cronlogaction( { action => 'Run', info => $command_line_options } ); |
| 94 |
} else { |
| 95 |
print "Running in dry-run mode, provide --doit to apply the changes\n"; |
| 96 |
} |
| 97 |
|
| 87 |
usage() if $help; |
98 |
usage() if $help; |
| 88 |
|
99 |
|
| 89 |
force_borrower_messaging_defaults( $doit, $since, $not_expired, $no_overwrite, $category, $branchcode, $message_name ); |
100 |
force_borrower_messaging_defaults( |
|
|
101 |
$doit, $since, $not_expired, $no_overwrite, $category, $branchcode, $message_name, |
| 102 |
$verbose |
| 103 |
); |
| 90 |
|
104 |
|
| 91 |
=head1 NAME |
105 |
=head1 NAME |
| 92 |
|
106 |
|
|
Lines 120-125
use the options -not-expired or -no-overwrite to update a subset).
Link Here
|
| 120 |
|
134 |
|
| 121 |
Prints this help |
135 |
Prints this help |
| 122 |
|
136 |
|
|
|
137 |
=item B<--verbose> |
| 138 |
|
| 139 |
Report on borrowers that will be updated |
| 140 |
|
| 123 |
=item B<--doit> |
141 |
=item B<--doit> |
| 124 |
|
142 |
|
| 125 |
Actually update the borrowers. |
143 |
Actually update the borrowers. |
| 126 |
- |
|
|