4 define('INSTALLDIR', dirname(__DIR__));
5 define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
7 $shortoptions = 'e::ay';
8 $longoptions = array('email=', 'all', 'yes');
10 $self = basename($_SERVER['PHP_SELF']);
12 $helptext = <<<END_OF_HELP
14 resends confirmation email either for a specific email (if found) or for
15 all lingering confirmations.
17 NOTE: You probably want to do something like this to your database first so
18 only relatively fresh accounts get resent this:
20 DELETE FROM confirm_address WHERE modified < DATE_SUB(NOW(), INTERVAL 1 month);
24 -e --email e-mail address to send for
25 -a --all send for all emails in confirm_address table
26 -y --yes skip interactive verification
30 require_once INSTALLDIR.'/scripts/commandline.inc';
35 if (have_option('e', 'email')) {
36 $email = get_option_value('e', 'email');
38 $ca = Confirm_address::getByAddress($email, 'email');
39 } catch (NoResultException $e) {
40 print sprintf("Can't find %s address %s in %s table.\n", $e->obj->address_type, $e->obj->address, $e->obj->tableName());
43 } elseif (have_option('a', 'all')) {
45 $ca = new Confirm_address();
46 $ca->address_type = 'email';
48 print "confirm_address table contains no lingering email addresses\n";
52 print "You must provide an email (or --all).\n";
56 if (!have_option('y', 'yes')) {
57 print "About to resend confirm_address email to {$ca->N} recipients. Are you sure? [y/N] ";
58 $response = fgets(STDIN);
59 if (strtolower(trim($response)) != 'y') {
65 function mailConfirmAddress(Confirm_address $ca)
68 $user = User::getByID($ca->user_id);
69 $profile = $user->getProfile();
70 if ($profile->isSilenced()) {
74 if ($user->email === $ca->address) {
75 throw new AlreadyFulfilledException('User already has identical confirmed email address.');
77 } catch (AlreadyFulfilledException $e) {
78 print "\n User already had verified email: "._ve($ca->address);
80 } catch (Exception $e) {
81 print "\n Failed to get user with ID "._ve($user_id).', deleting confirm_address entry: '._ve($e->getMessage());
85 mail_confirm_address($user, $ca->code, $user->getNickname(), $ca->address);
88 require_once(INSTALLDIR . '/lib/mail.php');
91 mailConfirmAddress($ca);
93 while ($ca->fetch()) {
94 mailConfirmAddress($ca);