]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - scripts/resend_confirm_address.php
Merge branch 'genericons-fix' into 'nightly'
[quix0rs-gnu-social.git] / scripts / resend_confirm_address.php
1 #!/usr/bin/env php
2 <?php
3
4 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
5
6 $shortoptions = 'e::ay';
7 $longoptions = array('email=', 'all', 'yes');
8
9 $self = basename($_SERVER['PHP_SELF']);
10
11 $helptext = <<<END_OF_HELP
12 {$self} [options]
13 resends confirmation email either for a specific email (if found) or for
14 all lingering confirmations.
15
16 NOTE: You probably want to do something like this to your database first so
17 only relatively fresh accounts get resent this:
18
19     DELETE FROM confirm_address WHERE modified < DATE_SUB(NOW(), INTERVAL 1 month);
20
21 Options:
22
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
26
27 END_OF_HELP;
28
29 require_once INSTALLDIR.'/scripts/commandline.inc';
30
31 $all = false;
32 $ca = null;
33
34 if (have_option('e', 'email')) {
35     $email = get_option_value('e', 'email');
36     $ca = Confirm_address::getAddress($email, 'email');
37     if (!$ca instanceof Confirm_address) {
38         print "Can't find email $email in confirm_address table.\n";
39         exit(1);
40     }
41 } elseif (have_option('a', 'all')) {
42     $all = true;
43     $ca = new Confirm_address();
44     $ca->address_type = 'email';
45     if (!$ca->find()) {
46         print "confirm_address table contains no lingering email addresses\n";
47         exit(0);
48     }
49 } else {
50     print "You must provide an email (or --all).\n";
51     exit(1);
52 }
53
54 if (!have_option('y', 'yes')) {
55     print "About to resend confirm_address email to {$ca->N} recipients. Are you sure? [y/N] ";
56     $response = fgets(STDIN);
57     if (strtolower(trim($response)) != 'y') {
58         print "Aborting.\n";
59         exit(0);
60     }
61 }
62
63 function mailConfirmAddress(Confirm_address $ca)
64 {
65     try {
66         $user = User::getByID($ca->user_id);
67         $profile = $user->getProfile();
68         if ($profile->isSilenced()) {
69             $ca->delete();
70             return;
71         }
72         if ($user->email === $ca->address) {
73             throw new AlreadyFulfilledException('User already has identical confirmed email address.');
74         }
75     } catch (AlreadyFulfilledException $e) {
76         print "\n User already had verified email: "._ve($ca->address);
77         $ca->delete();
78     } catch (Exception $e) {
79         print "\n Failed to get user with ID "._ve($user_id).', deleting confirm_address entry: '._ve($e->getMessage());
80         $ca->delete();
81         return;
82     }
83     mail_confirm_address($user, $ca->code, $user->getNickname(), $ca->address);
84 }
85
86 require_once(INSTALLDIR . '/lib/mail.php');
87
88 if (!$all) {
89     mailConfirmAddress($ca);
90 } else {
91     while ($ca->fetch()) {
92         mailConfirmAddress($ca);
93     }
94 }
95
96 print "\nDONE.\n";