use strict;
use DBI;
-my $select_query = qq/SELECT u.id, u.first_given_name, u.second_given_name, u.family_name
+my $select_query = qq/SELECT u.id, u.first_given_name, u.second_given_name, u.family_name, u.email
FROM actor.usr u
JOIN actor.card cd on (cd.usr = u.id and cd.active)
WHERE cd.barcode = ?/;
# execute SELECT query
my $sth = $dbh->prepare("$select_query");
$sth->execute($old_barcode);
-my ($user_id1, $first_name1, $middle_name1, $last_name1);
+my ($user_id1, $first_name1, $middle_name1, $last_name1, $email1);
# iterate through resultset
# print values
-my $ref = $sth->bind_columns(\($user_id1, $first_name1, $middle_name1, $last_name1));
+my $ref = $sth->bind_columns(\($user_id1, $first_name1, $middle_name1, $last_name1, $email1));
while ($sth->fetch) {
- print "The old user has ID $user_id1, barcode $old_barcode and is named $first_name1 $middle_name1 $last_name1.\n";
+ print "The old user has ID $user_id1, barcode $old_barcode and is named $first_name1 $middle_name1 $last_name1 with an email address of $email1.\n";
}
# execute SELECT query
#$sth = $dbh->prepare("$select_query2");
$sth->execute($new_barcode);
-my ($user_id2, $first_name2, $middle_name2, $last_name2);
+my ($user_id2, $first_name2, $middle_name2, $last_name2, $email2);
# iterate through resultset
# print values
-$ref = $sth->bind_columns(\($user_id2, $first_name2, $middle_name2, $last_name2));
+$ref = $sth->bind_columns(\($user_id2, $first_name2, $middle_name2, $last_name2, $email2));
while ($sth->fetch) {
- print "The new user has ID $user_id2, barcode $new_barcode and is named $first_name2 $middle_name2 $last_name2.\n";
+ print "The new user has ID $user_id2, barcode $new_barcode and is named $first_name2 $middle_name2 $last_name2 with an email address of $email2.\n";
}
print "We will be transferring all report templates and report definitions from $first_name1 $middle_name1 $last_name1 ($old_barcode) to $first_name2 $middle_name2 $last_name2 ($new_barcode). Is that correct (y/n)? ";
print "Setting new owner for $table.\n";
}
-my $update_schedule = qq/UPDATE reporter.schedule SET runner = $user_id2 WHERE runner = $user_id1 AND complete_time IS NULL/;
+print "Updating reporter.schedule with new runner and replacing email addresses.\n";
+
+my $update_schedule = qq/UPDATE reporter.schedule SET runner = ?, email = regexp_replace(email, ?, ?) WHERE runner = ? AND complete_time IS NULL/;
+$sth = $dbh->prepare("$update_schedule");
+$sth->execute($user_id2, $email1, $email2, $user_id1);
$dbh->commit;