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

(-)a/misc/cronjobs/j2a.pl (-30 / +75 lines)
Lines 46-51 juv2adult.pl [ -b=<branchcode> -f=<categorycode> -t=<categorycode> ] Link Here
46
   --man    full documentation
46
   --man    full documentation
47
   -v       verbose mode
47
   -v       verbose mode
48
   -n       take no action, display only
48
   -n       take no action, display only
49
   -a       anonymize, delete mame, surname, title of the guarantor 
49
   -b       <branchname>	only deal with patrons from this library/branch
50
   -b       <branchname>	only deal with patrons from this library/branch
50
   -f       <categorycode>	change patron category from this category
51
   -f       <categorycode>	change patron category from this category
51
   -t       <categorycode>	change patron category to this category
52
   -t       <categorycode>	change patron category to this category
Lines 70-75 Verbose. Without this flag set, only fatal errors are reported. Link Here
70
71
71
No Action. With this flag set, script will report changes but not actually execute them on the database.
72
No Action. With this flag set, script will report changes but not actually execute them on the database.
72
73
74
=item B<-a>
75
76
Anonymize. With this flag set, script will delete contactname, contactfirstname, contacttitle in the database.
77
73
=item B<-b>
78
=item B<-b>
74
79
75
changes patrons for one specific branch. Use the value in the
80
changes patrons for one specific branch. Use the value in the
Lines 101-110 C<juv2adult.pl> -f=<categorycode> -t=<categorycode> -v -n - Processes all branch Link Here
101
# These variables are set by command line options.
106
# These variables are set by command line options.
102
# They are initially set to default values.
107
# They are initially set to default values.
103
108
104
my $help     = 0;
109
my $help      = 0;
105
my $man      = 0;
110
my $man       = 0;
106
my $verbose  = 0;
111
my $verbose   = 0;
107
my $noaction = 0;
112
my $noaction  = 0;
113
my $anonymize = 0;
108
my $mybranch;
114
my $mybranch;
109
my $fromcat;
115
my $fromcat;
110
my $tocat;
116
my $tocat;
Lines 114-119 GetOptions( Link Here
114
    'man'    => \$man,
120
    'man'    => \$man,
115
    'v'      => \$verbose,
121
    'v'      => \$verbose,
116
    'n'      => \$noaction,
122
    'n'      => \$noaction,
123
    'a'      => \$anonymize,
117
    'f=s'    => \$fromcat,
124
    'f=s'    => \$fromcat,
118
    't=s'    => \$tocat,
125
    't=s'    => \$tocat,
119
    'b=s'    => \$mybranch,
126
    'b=s'    => \$mybranch,
Lines 166-184 my $itsyourbirthday = "$year-$mon-$mday"; Link Here
166
if ( not $noaction ) {
173
if ( not $noaction ) {
167
    if ($mybranch) {    #yep, we received a specific branch to work on.
174
    if ($mybranch) {    #yep, we received a specific branch to work on.
168
        $verbose and print "Looking for patrons of $mybranch to update from $fromcat to $tocat that were born before $itsyourbirthday\n";
175
        $verbose and print "Looking for patrons of $mybranch to update from $fromcat to $tocat that were born before $itsyourbirthday\n";
169
        my $query = qq|
176
        if ($anonymize) {
170
            UPDATE borrowers
177
            my $query = qq|
171
            SET guarantorid ='0',
178
                UPDATE borrowers
172
                categorycode = ?
179
                SET guarantorid ='0',
173
            WHERE dateofbirth <= ?
180
                    contactname = NULL,
174
              AND dateofbirth != '0000-00-00'
181
                    contactfirstname = NULL, 
175
              AND branchcode = ?
182
                    contacttitle = NULL, 
176
              AND categorycode IN (
183
                    categorycode = ?
177
                SELECT categorycode
184
                WHERE dateofbirth <= ?
178
                FROM categories
185
                  AND dateofbirth != '0000-00-00'
179
                WHERE category_type = 'C'
186
                  AND branchcode = ?
180
                  AND categorycode = ?
187
                  AND categorycode IN (
181
              )|;
188
                    SELECT categorycode
189
                    FROM categories
190
                    WHERE category_type = 'C'
191
                      AND categorycode = ?
192
                  )|;
193
        }
194
        else {
195
            my $query = qq|
196
                UPDATE borrowers
197
                SET guarantorid ='0',
198
                    categorycode = ?
199
                WHERE dateofbirth <= ?
200
                  AND dateofbirth != '0000-00-00'
201
                  AND branchcode = ?
202
                  AND categorycode IN (
203
                    SELECT categorycode
204
                    FROM categories
205
                    WHERE category_type = 'C'
206
                      AND categorycode = ?
207
                  )|;
208
        }
182
        my $sth = $dbh->prepare($query);
209
        my $sth = $dbh->prepare($query);
183
        my $res = $sth->execute( $tocat, $itsyourbirthday, $mybranch, $fromcat )
210
        my $res = $sth->execute( $tocat, $itsyourbirthday, $mybranch, $fromcat )
184
          or die "can't execute";
211
          or die "can't execute";
Lines 192-209 if ( not $noaction ) { Link Here
192
    }
219
    }
193
    else {    # branch was not supplied, processing all branches
220
    else {    # branch was not supplied, processing all branches
194
        $verbose and print "Looking in all branches for patrons to update from $fromcat to $tocat that were born before $itsyourbirthday\n";
221
        $verbose and print "Looking in all branches for patrons to update from $fromcat to $tocat that were born before $itsyourbirthday\n";
195
        my $query = qq|
222
        if ($anonymize) {
196
            UPDATE borrowers
223
            my $query = qq|
197
            SET guarantorid = '0',
224
                UPDATE borrowers
198
                categorycode = ?
225
                SET guarantorid = '0',
199
            WHERE dateofbirth <= ?
226
                    contactname = NULL,
200
              AND dateofbirth!='0000-00-00'
227
                    contactfirstname = NULL, 
201
              AND categorycode IN (
228
                    contacttitle = NULL, 
202
                SELECT categorycode
229
                    categorycode = ?
203
                FROM categories
230
                WHERE dateofbirth <= ?
204
                WHERE category_type = 'C'
231
                  AND dateofbirth!='0000-00-00'
205
                  AND categorycode = ?
232
                  AND categorycode IN (
206
              )|;
233
                    SELECT categorycode
234
                    FROM categories
235
                    WHERE category_type = 'C'
236
                      AND categorycode = ?
237
                  )|;
238
        }
239
        else {
240
            my $query = qq|
241
                UPDATE borrowers
242
                SET guarantorid = '0',
243
                    categorycode = ?
244
                WHERE dateofbirth <= ?
245
                  AND dateofbirth!='0000-00-00'
246
                  AND categorycode IN (
247
                    SELECT categorycode
248
                    FROM categories
249
                    WHERE category_type = 'C'
250
                      AND categorycode = ?
251
                  )|;
252
        }
207
        my $sth = $dbh->prepare($query);
253
        my $sth = $dbh->prepare($query);
208
        my $res = $sth->execute( $tocat, $itsyourbirthday, $fromcat )
254
        my $res = $sth->execute( $tocat, $itsyourbirthday, $fromcat )
209
          or die "can't execute";
255
          or die "can't execute";
210
- 

Return to bug 23170