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:au';
24 $longoptions = array('type=', 'email=', 'all', 'universe');
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
35 END_OF_SENDEMAILREMINDER_HELP;
37 require_once INSTALLDIR . '/scripts/commandline.inc';
39 $quiet = have_option('q', 'quiet');
42 // registration confirmation reminder
45 'className' => 'Confirm_address',
46 'utransport' => 'uregrem'
48 // invitation confirmation reminder
51 'className' => 'Invitation',
52 'utransport' => 'uinvrem'
59 if (have_option('t', 'type')) {
60 $type = trim(get_option_value('t', 'type'));
61 if (!in_array($type, array_keys($types)) && $type !== 'all') {
62 print _m("Unknown reminder type: {$type}.\n");
74 $reminders[] = $types['register'];
77 $reminders[] = $types['invite'];
84 if (have_option('u', 'universe')) {
85 $sn = new Status_network();
87 while ($sn->fetch()) {
88 $server = $sn->getServerName();
89 StatusNet::init($server);
90 // Different queue manager, maybe!
91 $qm = QueueManager::get();
92 foreach ($reminders as $reminder) {
94 $qm->enqueue($type, 'siterem');
95 if (!$quiet) { print "Sent pending {$type} reminders to all unconfirmed addresses in the known universe.\n"; }
100 $qm = QueueManager::get();
102 // enqueue reminder for specific email address or all unconfirmed addresses
103 if (have_option('e', 'email')) {
104 $address = trim(get_option_value('e', 'email'));
105 foreach ($reminders as $reminder) {
106 // real bad voodoo here
108 $confirm = new $className;
109 $confirm->address = $address;
110 $result = $confirm->find(true);
111 if (empty($result)) {
112 throw new Exception("No confirmation code found for {$address}.");
114 $qm->enqueue($confirm, $utransport);
115 if (!$quiet) { print "Sent all pending {$type} reminder to {$address}.\n"; }
117 } else if (have_option('a', 'all')) {
118 foreach ($reminders as $reminder) {
120 $qm->enqueue($type, 'siterem');
121 if (!$quiet) { print "Sent pending {$type} reminders to all unconfirmed addresses on the site.\n"; }
127 } catch (Exception $e) {
128 if (!$quiet) { print $e->getMessage() . "\n"; }
129 common_log(LOG_ERR, $e->getMessage(), __FILE__);