4 * StatusNet - a distributed open-source microblogging tool
5 * Copyright (C) 2011, StatusNet, Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
23 $shortoptions = 't:e:auo';
24 $longoptions = array('type=', 'email=', 'all', 'universe', 'onetime');
26 $helptext = <<<END_OF_SENDEMAILREMINDER_HELP
27 sendemailreminder.php [options]
28 Send an email summary of the inbox to users
30 -t --type type of reminder to send (register | invite | all)
31 -e --email email address to send reminder to
32 -a --all send reminder to all addresses
33 -u --universe send reminder to all addresses on all sites
34 -o --onetime send one-time reminder to older addresses
36 END_OF_SENDEMAILREMINDER_HELP;
38 require_once INSTALLDIR . '/scripts/commandline.inc';
40 $quiet = have_option('q', 'quiet');
43 // registration confirmation reminder
46 'className' => 'Confirm_address',
47 'utransport' => 'uregrem'
49 // invitation confirmation reminder
52 'className' => 'Invitation',
53 'utransport' => 'uinvrem'
59 $opts = array(); // special options like "onetime"
61 if (have_option('t', 'type')) {
62 $type = trim(get_option_value('t', 'type'));
63 if (!in_array($type, array_keys($types)) && $type !== 'all') {
64 print _m("Unknown reminder type: {$type}.\n");
72 if (have_option('o', 'onetime')) {
73 $opts['onetime'] = true;
74 if (!$quiet) { print "Special one-time reminder mode.\n"; }
81 $reminders[] = $types['register'];
84 $reminders[] = $types['invite'];
91 if (have_option('u', 'universe')) {
92 $sn = new Status_network();
95 while ($sn->fetch()) {
97 $server = $sn->getServerName();
98 GNUsocial::init($server);
99 // Different queue manager, maybe!
100 $qm = QueueManager::get();
101 foreach ($reminders as $reminder) {
103 $qm->enqueue(array($type, $opts), 'siterem');
104 if (!$quiet) { print "Sent pending {$type} reminders for {$server}.\n"; }
106 } catch (Exception $e) {
108 common_log(LOG_ERR, "Couldn't init {$server}.\n", __FILE__);
109 if (!$quiet) { print "Couldn't init {$server}.\n"; }
113 if (!$quiet) { print "Done! Reminders sent to all unconfirmed addresses in the known universe.\n"; }
115 } catch (Exception $e) {
116 if (!$quiet) { print $e->getMessage() . "\n"; }
117 common_log(LOG_ERR, $e->getMessage(), __FILE__);
121 $qm = QueueManager::get();
123 // enqueue reminder for specific email address or all unconfirmed addresses
124 if (have_option('e', 'email')) {
125 $address = trim(get_option_value('e', 'email'));
126 foreach ($reminders as $reminder) {
127 // real bad voodoo here
129 $confirm = new $className;
130 $confirm->address = $address;
131 $result = $confirm->find(true);
132 if (empty($result)) {
133 throw new Exception("No confirmation code found for {$address}.");
135 $qm->enqueue(array($confirm, $opts), $utransport);
136 if (!$quiet) { print "Sent all pending {$type} reminder to {$address}.\n"; }
138 } else if (have_option('a', 'all')) {
139 foreach ($reminders as $reminder) {
141 $qm->enqueue(array($type, $opts), 'siterem');
142 if (!$quiet) { print "Sent pending {$type} reminders to all unconfirmed addresses on the site.\n"; }
148 } catch (Exception $e) {
149 if (!$quiet) { print $e->getMessage() . "\n"; }
150 common_log(LOG_ERR, $e->getMessage(), __FILE__);