From 721896a6b5a9933ea81fb8b7be921e1915d176e5 Mon Sep 17 00:00:00 2001 From: Christophe Croullebois Date: Thu, 20 Jun 2019 15:30:21 +0200 Subject: [PATCH 1/1] [PATCH] Bug 23170: add anonymize option to j2a.pl --- misc/cronjobs/j2a.pl | 104 +++++++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 29 deletions(-) diff --git a/misc/cronjobs/j2a.pl b/misc/cronjobs/j2a.pl index cdbb8f81ed..182fc404c0 100755 --- a/misc/cronjobs/j2a.pl +++ b/misc/cronjobs/j2a.pl @@ -46,6 +46,7 @@ juv2adult.pl [ -b= -f= -t= ] --man full documentation -v verbose mode -n take no action, display only + -a anonymize, delete mame, surname, title of the guarantor -b only deal with patrons from this library/branch -f change patron category from this category -t change patron category to this category @@ -70,6 +71,10 @@ Verbose. Without this flag set, only fatal errors are reported. No Action. With this flag set, script will report changes but not actually execute them on the database. +=item B<-a> + +Anonymize. With this flag set, script will delete contactname, contactfirstname, contacttitle in the database. + =item B<-b> changes patrons for one specific branch. Use the value in the @@ -101,10 +106,11 @@ C -f= -t= -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 $noaction = 0; +my $help = 0; +my $man = 0; +my $verbose = 0; +my $noaction = 0; +my $anonymize = 0; my $mybranch; my $fromcat; my $tocat; @@ -114,6 +120,7 @@ GetOptions( 'man' => \$man, 'v' => \$verbose, 'n' => \$noaction, + 'a' => \$anonymize, 'f=s' => \$fromcat, 't=s' => \$tocat, 'b=s' => \$mybranch, @@ -166,19 +173,39 @@ 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 = ? - )|; + if ($anonymize) { + my $query = qq| + UPDATE borrowers + SET guarantorid ='0', + contactname = NULL, + contactfirstname = NULL, + contacttitle = NULL, + categorycode = ? + WHERE dateofbirth <= ? + AND dateofbirth != '0000-00-00' + AND branchcode = ? + AND categorycode IN ( + SELECT categorycode + FROM categories + WHERE category_type = 'C' + AND categorycode = ? + )|; + } + else { + 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"; @@ -192,18 +219,37 @@ if ( not $noaction ) { } 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 = ? - )|; + if ($anonymize) { + my $query = qq| + UPDATE borrowers + SET guarantorid = '0', + contactname = NULL, + contactfirstname = NULL, + contacttitle = NULL, + categorycode = ? + WHERE dateofbirth <= ? + AND dateofbirth!='0000-00-00' + AND categorycode IN ( + SELECT categorycode + FROM categories + WHERE category_type = 'C' + AND categorycode = ? + )|; + } + else { + 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"; -- 2.17.1