Bugzilla – Attachment 47687 Details for
Bug 15742
Unnecessary loop in j2a cronjob
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15742 [QA Followup] - Tidy script
Bug-15742-QA-Followup---Tidy-script.patch (text/plain), 11.98 KB, created by
Kyle M Hall (khall)
on 2016-02-05 11:43:45 UTC
(
hide
)
Description:
Bug 15742 [QA Followup] - Tidy script
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2016-02-05 11:43:45 UTC
Size:
11.98 KB
patch
obsolete
>From f1da69bd8ad841bc07b0df7bbfb26bee6d3a96b4 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Thu, 4 Feb 2016 21:24:53 +0000 >Subject: [PATCH] Bug 15742 [QA Followup] - Tidy script > >Script does not appear to have any other modifying patches at this >time based on bz splitter. This is a perfect time to clean up this >script! > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > misc/cronjobs/j2a.pl | 275 +++++++++++++++++++++++++++++---------------------- > 1 file changed, 159 insertions(+), 116 deletions(-) > >diff --git a/misc/cronjobs/j2a.pl b/misc/cronjobs/j2a.pl >index 744a65f..ba90ad0 100755 >--- a/misc/cronjobs/j2a.pl >+++ b/misc/cronjobs/j2a.pl >@@ -17,8 +17,7 @@ > # You should have received a copy of the GNU General Public License > # along with Koha; if not, see <http://www.gnu.org/licenses>. > >-use strict; >-use warnings; >+use Modern::Perl; > > BEGIN { > # find Koha's Perl modules >@@ -27,7 +26,6 @@ BEGIN { > eval { require "$FindBin::Bin/../kohalib.pl" }; > } > >- > use C4::Context; > use C4::Members; > use Getopt::Long; >@@ -43,13 +41,14 @@ juv2adult.pl - convert juvenile/child patrons from juvenile patron category and > juv2adult.pl [ -b=<branchcode> -f=<categorycode> -t=<categorycode> ] > > Options: >- --help brief help message >- --man full documentation >- -v verbose mode >- -n take no action, display only >- -b <branchname> only deal with patrons from this library/branch >- -f <categorycode> change patron category from this category >- -t <categorycode> change patron category to this category >+ --help brief help message >+ --man full documentation >+ -v verbose mode >+ -n take no action, display only >+ -b <branchname> only deal with patrons from this library/branch >+ -f <categorycode> change patron category from this category >+ -t <categorycode> change patron category to this category >+ > =head1 OPTIONS > > =over 8 >@@ -101,136 +100,180 @@ C<juv2adult.pl> -f=<categorycode> -t=<categorycode> -v -n - Processes all branch > # These variables are set by command line options. > # They are initially set to default values. > >- >-my $help = 0; >-my $man = 0; >-my $verbose = 0; >+my $help = 0; >+my $man = 0; >+my $verbose = 0; > my $noaction = 0; > my $mybranch; > my $fromcat; > my $tocat; > > GetOptions( >- 'help|?' => \$help, >- 'man' => \$man, >- 'v' => \$verbose, >- 'n' => \$noaction, >- 'f=s' => \$fromcat, >- 't=s' => \$tocat, >- 'b=s' => \$mybranch, >+ 'help|?' => \$help, >+ 'man' => \$man, >+ 'v' => \$verbose, >+ 'n' => \$noaction, >+ 'f=s' => \$fromcat, >+ 't=s' => \$tocat, >+ 'b=s' => \$mybranch, > ) or pod2usage(2); > pod2usage(1) if $help; > pod2usage( -verbose => 2 ) if $man; > >-if(not $fromcat && $tocat) { #make sure we've specified the info we need. >- print "please specify -help for usage tips.\n"; >- exit; >+if ( not $fromcat && $tocat ) { #make sure we've specified the info we need. >+ print "please specify -help for usage tips.\n"; >+ exit; > } > > cronlogaction(); > >-my $dbh=C4::Context->dbh; >+my $dbh = C4::Context->dbh; >+ > #get today's date, format it and subtract upperagelimit >-my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); >-$year +=1900; >-$mon +=1; if ($mon < 10) {$mon = "0".$mon;} >-if ($mday < 10) {$mday = "0".$mday;} >+my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = >+ localtime(time); >+$year += 1900; >+$mon += 1; >+if ( $mon < 10 ) { $mon = "0" . $mon; } >+if ( $mday < 10 ) { $mday = "0" . $mday; } >+ > # get the upperagelimit from the category to be transitioned from >-my $query=qq|SELECT upperagelimit from categories where categorycode =?|; >-my $sth=$dbh->prepare( $query ); >-$sth->execute( $fromcat ) >- or die "Couldn't execute statement: " . $sth->errstr; >+my $query = qq|SELECT upperagelimit from categories where categorycode =?|; >+my $sth = $dbh->prepare($query); >+$sth->execute($fromcat) >+ or die "Couldn't execute statement: " . $sth->errstr; > my $agelimit = $sth->fetchrow_array(); > if ( not $agelimit ) { >- >- die "No patron category $fromcat. Please try again. \n"; >+ die "No patron category $fromcat. Please try again. \n"; > } >-$query=qq|SELECT categorycode from categories where categorycode=?|; >-$sth=$dbh->prepare( $query ); >-$sth->execute( $tocat ) >- or die "Couldn't execute statement: " . $sth->errstr; >+ >+$query = qq|SELECT categorycode from categories where categorycode=?|; >+$sth = $dbh->prepare($query); >+$sth->execute($tocat) >+ or die "Couldn't execute statement: " . $sth->errstr; > my $tocatage = $sth->fetchrow_array(); >-if ( not $tocatage ){ >- die "No patron category $tocat. Please try again. \n"; >+if ( not $tocatage ) { >+ die "No patron category $tocat. Please try again. \n"; > } >-$sth->finish( ); >-$year -=$agelimit; >+ >+$year -= $agelimit; > > $verbose and print "The age limit for category $fromcat is $agelimit\n"; > > my $itsyourbirthday = "$year-$mon-$mday"; > >- >-if ( not $noaction) { >- if ( $mybranch ) { #yep, we received a specific branch to work on. >- $verbose and print "Looking for patrons of $mybranch to update from $fromcat to $tocat that were born before $itsyourbirthday\n"; >- my $query=qq|UPDATE borrowers >- SET guarantorid ='0', >- categorycode =? >- WHERE dateofbirth<=? >- AND dateofbirth!='0000-00-00' >- AND branchcode=? >- AND categorycode IN (select categorycode from categories where category_type='C' and categorycode=?)|; >- my $sth=$dbh->prepare($query); >- my $res = $sth->execute( $tocat, $itsyourbirthday, $mybranch, $fromcat ) or die "can't execute"; >- if ($res eq '0E0') { print "No patrons updated\n"; >- } else { print "Updated $res patrons\n"; } >- } else { # branch was not supplied, processing all branches >- $verbose and print "Looking in all branches for patrons to update from $fromcat to $tocat that were born before $itsyourbirthday\n"; >- my $query=qq|UPDATE borrowers >- SET guarantorid ='0', >- categorycode =? >- WHERE dateofbirth<=? >- AND dateofbirth!='0000-00-00' >- AND categorycode IN (select categorycode from categories where category_type='C' and categorycode=?)|; >- my $sth=$dbh->prepare($query); >- my $res = $sth->execute( $tocat, $itsyourbirthday, $fromcat ) or die "can't execute"; >- if ($res eq '0E0') { print "No patrons updated\n"; >- } else { print "Updated $res patrons\n"; } >- } >-} else { >- my $birthday; >- if ( $mybranch ) { >- $verbose and print "Displaying patrons that would be updated from $fromcat to $tocat from $mybranch\n"; >- my $query=qq|SELECT firstname, >- surname, >- cardnumber, >- dateofbirth >- FROM borrowers >- WHERE dateofbirth<=? >- AND dateofbirth!='0000-00-00' >- AND branchcode=? >- AND categorycode IN (select categorycode from categories where category_type='C' and categorycode=?)|; >- my $sth=$dbh->prepare( $query ); >- $sth->execute( $itsyourbirthday, $mybranch, $fromcat ) >- or die "Couldn't execute statement: " . $sth->errstr; >- while ( my @res = $sth->fetchrow_array()) { >- my $firstname = $res[0]; >- my $surname = $res[1]; >- my $barcode = $res[2]; >- $birthday = $res[3]; >- print "$firstname $surname $barcode $birthday\n"; >- } >- } else { >- $verbose and print "Displaying patrons that would be updated from $fromcat to $tocat.\n"; >- my $query=qq|SELECT firstname, >- surname, >- cardnumber, >- dateofbirth >- FROM borrowers >- WHERE dateofbirth<=? >- AND dateofbirth!='0000-00-00' >- AND categorycode IN (select categorycode from categories where category_type='C' and categorycode=?)|; >- my $sth=$dbh->prepare( $query ); >- $sth->execute( $itsyourbirthday, $fromcat ) >- or die "Couldn't execute statement: " . $sth->errstr; >- while ( my @res = $sth->fetchrow_array()) { >- my $firstname = $res[0]; >- my $surname = $res[1]; >- my $barcode = $res[2]; >- $birthday = $res[3]; >- print "$firstname $surname $barcode $birthday\n"; >- } >- } >- $sth->finish( ); >+if ( not $noaction ) { >+ if ($mybranch) { #yep, we received a specific branch to work on. >+ $verbose and print "Looking for patrons of $mybranch to update from $fromcat to $tocat that were born before $itsyourbirthday\n"; >+ my $query = qq| >+ UPDATE borrowers >+ SET guarantorid ='0', >+ categorycode = ? >+ WHERE dateofbirth <= ? >+ AND dateofbirth != '0000-00-00' >+ AND branchcode = ? >+ AND categorycode IN ( >+ SELECT categorycode >+ FROM categories >+ WHERE category_type = 'C' >+ AND categorycode = ? >+ )|; >+ my $sth = $dbh->prepare($query); >+ my $res = $sth->execute( $tocat, $itsyourbirthday, $mybranch, $fromcat ) >+ or die "can't execute"; >+ >+ if ( $res eq '0E0' ) { >+ print "No patrons updated\n"; >+ } >+ else { >+ print "Updated $res patrons\n"; >+ } >+ } >+ else { # branch was not supplied, processing all branches >+ $verbose and print "Looking in all branches for patrons to update from $fromcat to $tocat that were born before $itsyourbirthday\n"; >+ my $query = qq| >+ UPDATE borrowers >+ SET guarantorid = '0', >+ categorycode = ? >+ WHERE dateofbirth <= ? >+ AND dateofbirth!='0000-00-00' >+ AND categorycode IN ( >+ SELECT categorycode >+ FROM categories >+ WHERE category_type = 'C' >+ AND categorycode = ? >+ )|; >+ my $sth = $dbh->prepare($query); >+ my $res = $sth->execute( $tocat, $itsyourbirthday, $fromcat ) >+ or die "can't execute"; >+ >+ if ( $res eq '0E0' ) { >+ print "No patrons updated\n"; >+ } >+ else { >+ print "Updated $res patrons\n"; >+ } >+ } >+} >+else { >+ my $birthday; >+ if ($mybranch) { >+ $verbose and print "Displaying patrons that would be updated from $fromcat to $tocat from $mybranch\n"; >+ my $query = qq| >+ SELECT firstname, >+ surname, >+ cardnumber, >+ dateofbirth >+ FROM borrowers >+ WHERE dateofbirth <= ? >+ AND dateofbirth != '0000-00-00' >+ AND branchcode = ? >+ AND categorycode IN ( >+ SELECT categorycode >+ FROM categories >+ WHERE category_type = 'C' >+ AND categorycode = ? >+ ) >+ |; >+ my $sth = $dbh->prepare($query); >+ $sth->execute( $itsyourbirthday, $mybranch, $fromcat ) >+ or die "Couldn't execute statement: " . $sth->errstr; >+ >+ while ( my @res = $sth->fetchrow_array() ) { >+ my $firstname = $res[0]; >+ my $surname = $res[1]; >+ my $barcode = $res[2]; >+ $birthday = $res[3]; >+ print "$firstname $surname $barcode $birthday\n"; >+ } >+ } >+ else { >+ $verbose and print "Displaying patrons that would be updated from $fromcat to $tocat.\n"; >+ my $query = qq| >+ SELECT firstname, >+ surname, >+ cardnumber, >+ dateofbirth >+ FROM borrowers >+ WHERE dateofbirth <= ? >+ AND dateofbirth != '0000-00-00' >+ AND categorycode IN ( >+ SELECT categorycode >+ FROM categories >+ WHERE category_type = 'C' >+ AND categorycode = ? >+ ) >+ |; >+ my $sth = $dbh->prepare($query); >+ $sth->execute( $itsyourbirthday, $fromcat ) >+ or die "Couldn't execute statement: " . $sth->errstr; >+ >+ while ( my @res = $sth->fetchrow_array() ) { >+ my $firstname = $res[0]; >+ my $surname = $res[1]; >+ my $barcode = $res[2]; >+ $birthday = $res[3]; >+ print "$firstname $surname $barcode $birthday\n"; >+ } >+ } > } >-- >2.1.4
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 15742
:
47642
|
47658
|
47686
| 47687