4 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
6 $shortoptions = 'e::ay';
7 $longoptions = array('email=', 'all', 'yes');
9 $self = basename($_SERVER['PHP_SELF']);
11 $helptext = <<<END_OF_HELP
13 resends confirmation email either for a specific email (if found) or for
14 all lingering confirmations.
16 NOTE: You probably want to do something like this to your database first so
17 only relatively fresh accounts get resent this:
19 DELETE FROM confirm_address WHERE modified < DATE_SUB(NOW(), INTERVAL 1 month);
23 -e --email e-mail address to send for
24 -a --all send for all emails in confirm_address table
25 -y --yes skip interactive verification
29 require_once INSTALLDIR.'/scripts/commandline.inc';
34 if (have_option('e', 'email')) {
35 $email = get_option_value('e', 'email');
37 $ca = Confirm_address::getByAddress($email, 'email');
38 } catch (NoResultException $e) {
39 print sprintf("Can't find %s address %s in %s table.\n", $e->obj->address_type, $e->obj->address, $e->obj->tableName());
42 } elseif (have_option('a', 'all')) {
44 $ca = new Confirm_address();
45 $ca->address_type = 'email';
47 print "confirm_address table contains no lingering email addresses\n";
51 print "You must provide an email (or --all).\n";
55 if (!have_option('y', 'yes')) {
56 print "About to resend confirm_address email to {$ca->N} recipients. Are you sure? [y/N] ";
57 $response = fgets(STDIN);
58 if (strtolower(trim($response)) != 'y') {
64 function mailConfirmAddress(Confirm_address $ca)
67 $user = User::getByID($ca->user_id);
68 $profile = $user->getProfile();
69 if ($profile->isSilenced()) {
73 if ($user->email === $ca->address) {
74 throw new AlreadyFulfilledException('User already has identical confirmed email address.');
76 } catch (AlreadyFulfilledException $e) {
77 print "\n User already had verified email: "._ve($ca->address);
79 } catch (Exception $e) {
80 print "\n Failed to get user with ID "._ve($user_id).', deleting confirm_address entry: '._ve($e->getMessage());
84 mail_confirm_address($user, $ca->code, $user->getNickname(), $ca->address);
87 require_once(INSTALLDIR . '/lib/mail.php');
90 mailConfirmAddress($ca);
92 while ($ca->fetch()) {
93 mailConfirmAddress($ca);