Bugzilla – Attachment 109116 Details for
Bug 25624
Update patrons category script should allow finding null and not null and wildcards
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25624: Add 'operator' option to allow for different comparisons
Bug-25624-Add-operator-option-to-allow-for-differe.patch (text/plain), 4.96 KB, created by
Nick Clemens (kidclamp)
on 2020-08-25 15:45:53 UTC
(
hide
)
Description:
Bug 25624: Add 'operator' option to allow for different comparisons
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2020-08-25 15:45:53 UTC
Size:
4.96 KB
patch
obsolete
>From 28d403a1f6bd70762261a34ee0750d0ffeabc407 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Tue, 25 Aug 2020 15:38:26 +0000 >Subject: [PATCH] Bug 25624: Add 'operator' option to allow for different > comparisons > >This patch adds the option to specify the operators fper field specified in the script > >We also add support for testing 'null' fields > >To test: >1 - Run the script with no parameters and verify the help explains the parameters >2 - Add a patron in category PT (or your choice) with email 'a@b.com' >3 - Add a patron in category PT (or as above) with email 'c@d.com' >4 - Try running with options > perl misc/cronjobs/update_patrons_category.pl -f PT -t s --field email=a@b.com (first patron returned) > perl misc/cronjobs/update_patrons_category.pl -f PT -t s --field email=a@b.com -o email=e (first patron returned) > perl misc/cronjobs/update_patrons_category.pl -f PT -t s --field email=a@b.com -o email=gt (both patrons returned) > perl misc/cronjobs/update_patrons_category.pl -f PT -t s --field email=a@b.com -o email=gte (second patron returned) > perl misc/cronjobs/update_patrons_category.pl -f PT -t s --field email=a@b% -o email=l (first patron returned) > perl misc/cronjobs/update_patrons_category.pl -f PT -t s --field email=a@b% -o email=nl (second patron returned) > perl misc/cronjobs/update_patrons_category.pl -f PT -t s --field email=null -o email=e (neither patron returned) > perl misc/cronjobs/update_patrons_category.pl -f PT -t s --field email=null -o email=ne (both patrons returned) >5 - Test other combination >6 - Test with --confirm and ensure updates suceed as before patches > >https://bugs.koha-community.org/show_bug.cgi?id=25264 >--- > misc/cronjobs/update_patrons_category.pl | 44 +++++++++++++++++++++++++++++--- > 1 file changed, 40 insertions(+), 4 deletions(-) > >diff --git a/misc/cronjobs/update_patrons_category.pl b/misc/cronjobs/update_patrons_category.pl >index 207f9b6cd9..380b6625f8 100755 >--- a/misc/cronjobs/update_patrons_category.pl >+++ b/misc/cronjobs/update_patrons_category.pl >@@ -55,7 +55,8 @@ Options: > -fu=X --fineunder=X update if fines under X amount > -rb=date --regbefore update if registration date is before given date > -ra=date --regafter update if registration date is after a given date >- -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> >+ -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> >+ -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) > -v -verbose verbose mode > -c --confirm commit changes to db, no action will be taken unless this switch is included > -b --branch <branchname> only deal with patrons from this library/branch >@@ -127,6 +128,26 @@ e.g. > --field dateexpiry=2016-01-01 > will update all patrons who expired on that date, useful for schools etc. > >+=item B<--operator column=value | -o column=value> >+ >+Use this flag to specify a column in the borrowers table from a --field param and a comparison operator using options: >+ >+lt for < or 'less than' >+lte for <= or 'less than or equal' >+e for = or 'equal' >+gte for >= ir 'greater than or equal' >+gt for > or 'greater than' >+ne for != or 'not equal' >+l for LIKE, use % for wildcard >+nl for NOT LIKE, use % for wildcard >+ >+e.g. >+--field email=null --operator email=ne >+will update all patrons who do not have a null email >+ >+Note: 'null' will be treated as a string for any operator other then e or ne >+i.e. --field email=null --operator email=l will search patrons with email like the word 'null' >+ > =back > > =head1 DESCRIPTION >@@ -163,6 +184,7 @@ my $reg_bef; > my $reg_aft; > my $branch_lim; > my %fields; >+my %operators = (); > > GetOptions( > 'help|?' => \$help, >@@ -178,7 +200,8 @@ GetOptions( > 'rb|regbefore=s' => \$reg_bef, > 'ra|regafter=s' => \$reg_aft, > 'b|branch=s' => \$branch_lim, >- 'd|field=s' => \%fields >+ 'd|field=s' => \%fields, >+ 'o|operator=s' => \%operators > ); > > pod2usage(1) if $help; >@@ -234,9 +257,22 @@ if ($verbose) { > } > } > >+my %operator_values = ( >+ lt => '<', >+ lte => '<=', >+ e => '=', >+ gte => '>=', >+ gt => '>', >+ ne => '!=', >+ l => 'LIKE', >+ nl => 'NOT LIKE' >+); >+ > while ( my ( $key, $value ) = each %fields ) { >- $verbose and print " Borrower column $key is equal to $value\n"; >- $params{ "me." . $key } = $value; >+ my $operator = $operator_values{ $operators{$key} } // '='; >+ $verbose and print " Borrower column $key is $operator to $value\n"; >+ $value = undef if lc($value) eq 'null' && ($operator eq '=' || $operator eq '!='); >+ $params{ "me." . $key } = { $operator => $value }; > } > my $target_patrons = Koha::Patrons->search(\%params)->search_patrons_to_update_category( > { >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 25624
:
105439
|
105605
|
106965
|
107291
|
107292
|
109116
|
109370
|
109421
|
109427
|
109440
|
110747