Lines 55-61
Options:
Link Here
|
55 |
-fu=X --fineunder=X update if fines under X amount |
55 |
-fu=X --fineunder=X update if fines under X amount |
56 |
-rb=date --regbefore update if registration date is before given date |
56 |
-rb=date --regbefore update if registration date is before given date |
57 |
-ra=date --regafter update if registration date is after a given date |
57 |
-ra=date --regafter update if registration date is after a given date |
58 |
-d --dbfield name=value where <name> is a column in the borrowers table, patrons will be updated if the field is equal to given <value> |
58 |
-d --field name=value where <name> is a column in the borrowers table, patrons will be updated if the field is equal to given <value> |
|
|
59 |
-o --operator name=value where <name> is a column in the borrowers table specified in a --dbfield param and <value> is the operator to use from (l,le,e,ge,e) |
59 |
-v -verbose verbose mode |
60 |
-v -verbose verbose mode |
60 |
-c --confirm commit changes to db, no action will be taken unless this switch is included |
61 |
-c --confirm commit changes to db, no action will be taken unless this switch is included |
61 |
-b --branch <branchname> only deal with patrons from this library/branch |
62 |
-b --branch <branchname> only deal with patrons from this library/branch |
Lines 127-132
e.g.
Link Here
|
127 |
--field dateexpiry=2016-01-01 |
128 |
--field dateexpiry=2016-01-01 |
128 |
will update all patrons who expired on that date, useful for schools etc. |
129 |
will update all patrons who expired on that date, useful for schools etc. |
129 |
|
130 |
|
|
|
131 |
=item B<--operator column=value | -o column=value> |
132 |
|
133 |
Use this flag to specify a column in the borrowers table from a --field param and a comparison operator using options: |
134 |
|
135 |
lt for < or 'less than' |
136 |
lte for <= or 'less than or equal' |
137 |
e for = or 'equal' |
138 |
gte for >= ir 'greater than or equal' |
139 |
gt for > or 'greater than' |
140 |
ne for != or 'not equal' |
141 |
l for LIKE, use % for wildcard |
142 |
nl for NOT LIKE, use % for wildcard |
143 |
|
144 |
e.g. |
145 |
--field email=null --operator email=ne |
146 |
will update all patrons who do not have a null email |
147 |
|
148 |
Note: 'null' will be treated as a string for any operator other then e or ne |
149 |
i.e. --field email=null --operator email=l will search patrons with email like the word 'null' |
150 |
|
130 |
=back |
151 |
=back |
131 |
|
152 |
|
132 |
=head1 DESCRIPTION |
153 |
=head1 DESCRIPTION |
Lines 163-168
my $reg_bef;
Link Here
|
163 |
my $reg_aft; |
184 |
my $reg_aft; |
164 |
my $branch_lim; |
185 |
my $branch_lim; |
165 |
my %fields; |
186 |
my %fields; |
|
|
187 |
my %operators = (); |
166 |
|
188 |
|
167 |
GetOptions( |
189 |
GetOptions( |
168 |
'help|?' => \$help, |
190 |
'help|?' => \$help, |
Lines 178-184
GetOptions(
Link Here
|
178 |
'rb|regbefore=s' => \$reg_bef, |
200 |
'rb|regbefore=s' => \$reg_bef, |
179 |
'ra|regafter=s' => \$reg_aft, |
201 |
'ra|regafter=s' => \$reg_aft, |
180 |
'b|branch=s' => \$branch_lim, |
202 |
'b|branch=s' => \$branch_lim, |
181 |
'd|field=s' => \%fields |
203 |
'd|field=s' => \%fields, |
|
|
204 |
'o|operator=s' => \%operators |
182 |
); |
205 |
); |
183 |
|
206 |
|
184 |
pod2usage(1) if $help; |
207 |
pod2usage(1) if $help; |
Lines 234-242
if ($verbose) {
Link Here
|
234 |
} |
257 |
} |
235 |
} |
258 |
} |
236 |
|
259 |
|
|
|
260 |
my %operator_values = ( |
261 |
lt => '<', |
262 |
lte => '<=', |
263 |
e => '=', |
264 |
gte => '>=', |
265 |
gt => '>', |
266 |
ne => '!=', |
267 |
l => 'LIKE', |
268 |
nl => 'NOT LIKE' |
269 |
); |
270 |
|
237 |
while ( my ( $key, $value ) = each %fields ) { |
271 |
while ( my ( $key, $value ) = each %fields ) { |
238 |
$verbose and print " Borrower column $key is equal to $value\n"; |
272 |
my $operator = $operator_values{ $operators{$key} } // '='; |
239 |
$params{ "me." . $key } = $value; |
273 |
$verbose and print " Borrower column $key is $operator to $value\n"; |
|
|
274 |
$value = undef if lc($value) eq 'null' && ($operator eq '=' || $operator eq '!='); |
275 |
$params{ "me." . $key } = { $operator => $value }; |
240 |
} |
276 |
} |
241 |
my $target_patrons = Koha::Patrons->search(\%params)->search_patrons_to_update_category( |
277 |
my $target_patrons = Koha::Patrons->search(\%params)->search_patrons_to_update_category( |
242 |
{ |
278 |
{ |
243 |
- |
|
|