123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
- define('INSTALLDIR', dirname(__DIR__, 3));
- define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
- $shortoptions = 't:e:auo';
- $longoptions = array('type=', 'email=', 'all', 'universe', 'onetime');
- $helptext = <<<END_OF_SENDEMAILREMINDER_HELP
- sendemailreminder.php [options]
- Send an email summary of the inbox to users
- -t --type type of reminder to send (register | invite | all)
- -e --email email address to send reminder to
- -a --all send reminder to all addresses
- -u --universe send reminder to all addresses on all sites
- -o --onetime send one-time reminder to older addresses
- END_OF_SENDEMAILREMINDER_HELP;
- require_once INSTALLDIR . '/scripts/commandline.inc';
- $quiet = have_option('q', 'quiet');
- $types = array(
-
- 'register' => array(
- 'type' => 'register',
- 'className' => 'Confirm_address',
- 'utransport' => 'uregrem'
- ),
-
- 'invite' => array(
- 'type' => 'invite',
- 'className' => 'Invitation',
- 'utransport' => 'uinvrem'
- )
-
- );
- $type = null;
- $opts = array();
- if (have_option('t', 'type')) {
- $type = trim(get_option_value('t', 'type'));
- if (!in_array($type, array_keys($types)) && $type !== 'all') {
- echo _m('Unknown reminder type: ' . $type . '.' . "\n");
- exit(1);
- }
- } else {
- show_help();
- exit(1);
- }
- if (have_option('o', 'onetime')) {
- $opts['onetime'] = true;
- if (!$quiet) {
- echo 'Special one-time reminder mode.' . "\n";
- }
- }
- $reminders = array();
- switch ($type) {
- case 'register':
- $reminders[] = $types['register'];
- break;
- case 'invite':
- $reminders[] = $types['invite'];
- break;
- case 'all':
- $reminders = $types;
- break;
- }
- if (have_option('u', 'universe')) {
- $sn = new Status_network();
- try {
- if ($sn->find()) {
- while ($sn->fetch()) {
- try {
- $server = $sn->getServerName();
- GNUsocial::init($server);
-
- $qm = QueueManager::get();
- foreach ($reminders as $reminder) {
- extract($reminder);
- $qm->enqueue(array($type, $opts), 'siterem');
- if (!$quiet) {
- echo 'Sent pending ' . $type . ' reminders for ' . $server . '.' . "\n";
- }
- }
- } catch (Exception $e) {
-
- common_log(LOG_ERR, "Couldn't init {$server}.\n", __FILE__);
- if (!$quiet) {
- echo "Couldn't init " . $server . ".\n";
- }
- continue;
- }
- }
- if (!$quiet) {
- echo 'Done! Reminders sent to all unconfirmed addresses in the known universe.' . "\n";
- }
- }
- } catch (Exception $e) {
- if (!$quiet) {
- echo $e->getMessage() . "\n";
- }
- common_log(LOG_ERR, $e->getMessage(), __FILE__);
- exit(1);
- }
- } else {
- $qm = QueueManager::get();
- try {
-
- if (have_option('e', 'email')) {
- $address = trim(get_option_value('e', 'email'));
- foreach ($reminders as $reminder) {
-
- extract($reminder);
- $confirm = new $className;
- $confirm->address = $address;
- $result = $confirm->find(true);
- if (empty($result)) {
- throw new Exception("No confirmation code found for {$address}.");
- }
- $qm->enqueue(array($confirm, $opts), $utransport);
- if (!$quiet) {
- echo 'Sent all pending ' . $type . ' reminder to ' . $address . '.' . "\n";
- }
- }
- } elseif (have_option('a', 'all')) {
- foreach ($reminders as $reminder) {
- extract($reminder);
- $qm->enqueue(array($type, $opts), 'siterem');
- if (!$quiet) {
- echo 'Sent pending ' . $type . ' reminders to all unconfirmed addresses on the site.' . "\n";
- }
- }
- } else {
- show_help();
- exit(1);
- }
- } catch (Exception $e) {
- if (!$quiet) {
- echo $e->getMessage() . "\n";
- }
- common_log(LOG_ERR, $e->getMessage(), __FILE__);
- exit(1);
- }
- }
|