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

(-)a/misc/cronjobs/update_patrons_category.pl (-44 / +13 lines)
Lines 56-64 Options: Link Here
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 --field 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
   -dn --notfield name=value  where <name> is a column in the borrowers table, patrons will be updated if the field is not equal to given <value>
59
   --where <conditions> where clause to add to the query
60
   -dl --likefield name=value  where <name> is a column in the borrowers table, patrons will be updated if the field is like the given <value>
61
   -dnl --notlikefield name=value  where <name> is a column in the borrowers table, patrons will be updated if the field is not like the given <value>
62
   -v -verbose              verbose mode
60
   -v -verbose              verbose mode
63
   -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
64
   -b --branch <branchname> only deal with patrons from this library/branch
62
   -b --branch <branchname> only deal with patrons from this library/branch
Lines 131-163 e.g. Link Here
131
--field dateexpiry=2016-01-01
129
--field dateexpiry=2016-01-01
132
will update all patrons who expired on that date, useful for schools etc.
130
will update all patrons who expired on that date, useful for schools etc.
133
131
134
=item B<--notfield column=value | -dn column=value>
132
=item B<--where $conditions>
135
133
136
Use this flag to specify a column in the borrowers table and update only patrons whose value in that column does not equal the value supplied (repeatable)
134
Use this option to specify a condition built with columns from the borrowers table
137
A value of null will check for a field that is not set.
138
135
139
e.g.
136
e.g.
140
--notfield email=NULL
137
--where 'email IS NULL'
141
will update all patrons with no value for email
138
will update all patrons with no value for email
142
139
143
=item B<--likefield column=value | -dl column=value>
140
--where 'categorycode LIKE "%CHILD"'
144
145
Use this flag to specify a column in the borrowers table and update only patrons whose value in that column is like the value supplied (repeatable)
146
use '%' as a wildcard.
147
A value of null will check for a field that is not set.
148
149
e.g.
150
--likefield categorycode=%CHILD
151
will update all patrons with a category ending in CHILD.
141
will update all patrons with a category ending in CHILD.
152
142
153
=item B<--notlikefield column=value | -dnl column=value>
143
--where 'categorycode LIKE RESIDENT%'
154
155
Use this flag to specify a column in the borrowers table and update only patrons whose value in that column is not like the value supplied (repeatable)
156
use '%' as a wildcard.
157
A value of null will check for a field that is not set.
158
159
e.g.
160
--notlikefield categorycode=RESIDENT%
161
will update all patrons whose category does not begin with RESIDENT.
144
will update all patrons whose category does not begin with RESIDENT.
162
145
163
=back
146
=back
Lines 196-204 my $reg_bef; Link Here
196
my $reg_aft;
179
my $reg_aft;
197
my $branch_lim;
180
my $branch_lim;
198
my %fields;
181
my %fields;
199
my %not_fields;
182
my @where;
200
my %like_fields;
201
my %not_like_fields;
202
183
203
GetOptions(
184
GetOptions(
204
    'help|?'          => \$help,
185
    'help|?'          => \$help,
Lines 215-223 GetOptions( Link Here
215
    'ra|regafter=s'   => \$reg_aft,
196
    'ra|regafter=s'   => \$reg_aft,
216
    'b|branch=s'      => \$branch_lim,
197
    'b|branch=s'      => \$branch_lim,
217
    'd|field=s'       => \%fields,
198
    'd|field=s'       => \%fields,
218
    'dn|notfield=s'   => \%not_fields,
199
    'where=s'         => \@where,
219
    'dl|likefield=s'       => \%like_fields,
220
    'dnl|notlikefield=s'   => \%not_like_fields
221
);
200
);
222
201
223
pod2usage(1) if $help;
202
pod2usage(1) if $help;
Lines 278-297 while ( my ( $key, $value ) = each %fields ) { Link Here
278
    $value = undef if lc($value) eq 'null';
257
    $value = undef if lc($value) eq 'null';
279
    $params{ "me." . $key } = $value;
258
    $params{ "me." . $key } = $value;
280
}
259
}
281
while ( my ( $key, $value ) = each %not_fields ) {
260
282
    $verbose and print "    Borrower column $key is not $value\n";
261
my $where_literal = join ' AND ', @where;
283
    $value = undef if lc($value) eq 'null';
262
my $target_patrons = Koha::Patrons->search( \%params )
284
    $params{ "me." . $key } = { '!=' => $value };
263
  ->search( \$where_literal )
285
}
264
  ->search_patrons_to_update_category(
286
while ( my ( $key, $value ) = each %like_fields ) {
287
    $verbose and print "    Borrower column $key is like $value\n";
288
    $params{ "me." . $key } = { 'LIKE' => $value };
289
}
290
while ( my ( $key, $value ) = each %not_like_fields ) {
291
    $verbose and print "    Borrower column $key is not like $value\n";
292
    $params{ "me." . $key } = { 'NOT LIKE' => $value };
293
}
294
my $target_patrons = Koha::Patrons->search(\%params)->search_patrons_to_update_category(
295
    {
265
    {
296
        from          => $fromcat,
266
        from          => $fromcat,
297
        search_params => \%params,
267
        search_params => \%params,
298
- 

Return to bug 25624