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