sendemailreminder.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * StatusNet - a distributed open-source microblogging tool
  5. * Copyright (C) 2011, StatusNet, Inc.
  6. *
  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.
  11. *
  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.
  16. *
  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/>.
  19. */
  20. define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
  21. $shortoptions = 't:e:auo';
  22. $longoptions = array('type=', 'email=', 'all', 'universe', 'onetime');
  23. $helptext = <<<END_OF_SENDEMAILREMINDER_HELP
  24. sendemailreminder.php [options]
  25. Send an email summary of the inbox to users
  26. -t --type type of reminder to send (register | invite | all)
  27. -e --email email address to send reminder to
  28. -a --all send reminder to all addresses
  29. -u --universe send reminder to all addresses on all sites
  30. -o --onetime send one-time reminder to older addresses
  31. END_OF_SENDEMAILREMINDER_HELP;
  32. require_once INSTALLDIR . '/scripts/commandline.inc';
  33. $quiet = have_option('q', 'quiet');
  34. $types = array(
  35. // registration confirmation reminder
  36. 'register' => array(
  37. 'type' => 'register',
  38. 'className' => 'Confirm_address',
  39. 'utransport' => 'uregrem'
  40. ),
  41. // invitation confirmation reminder
  42. 'invite' => array(
  43. 'type' => 'invite',
  44. 'className' => 'Invitation',
  45. 'utransport' => 'uinvrem'
  46. )
  47. // ... add more here
  48. );
  49. $type = null;
  50. $opts = array(); // special options like "onetime"
  51. if (have_option('t', 'type')) {
  52. $type = trim(get_option_value('t', 'type'));
  53. if (!in_array($type, array_keys($types)) && $type !== 'all') {
  54. print _m("Unknown reminder type: {$type}.\n");
  55. exit(1);
  56. }
  57. } else {
  58. show_help();
  59. exit(1);
  60. }
  61. if (have_option('o', 'onetime')) {
  62. $opts['onetime'] = true;
  63. if (!$quiet) { print "Special one-time reminder mode.\n"; }
  64. }
  65. $reminders = array();
  66. switch($type) {
  67. case 'register':
  68. $reminders[] = $types['register'];
  69. break;
  70. case 'invite':
  71. $reminders[] = $types['invite'];
  72. break;
  73. case 'all':
  74. $reminders = $types;
  75. break;
  76. }
  77. if (have_option('u', 'universe')) {
  78. $sn = new Status_network();
  79. try {
  80. if ($sn->find()) {
  81. while ($sn->fetch()) {
  82. try {
  83. $server = $sn->getServerName();
  84. StatusNet::init($server);
  85. // Different queue manager, maybe!
  86. $qm = QueueManager::get();
  87. foreach ($reminders as $reminder) {
  88. extract($reminder);
  89. $qm->enqueue(array($type, $opts), 'siterem');
  90. if (!$quiet) { print "Sent pending {$type} reminders for {$server}.\n"; }
  91. }
  92. } catch (Exception $e) {
  93. // keep going
  94. common_log(LOG_ERR, "Couldn't init {$server}.\n", __FILE__);
  95. if (!$quiet) { print "Couldn't init {$server}.\n"; }
  96. continue;
  97. }
  98. }
  99. if (!$quiet) { print "Done! Reminders sent to all unconfirmed addresses in the known universe.\n"; }
  100. }
  101. } catch (Exception $e) {
  102. if (!$quiet) { print $e->getMessage() . "\n"; }
  103. common_log(LOG_ERR, $e->getMessage(), __FILE__);
  104. exit(1);
  105. }
  106. } else {
  107. $qm = QueueManager::get();
  108. try {
  109. // enqueue reminder for specific email address or all unconfirmed addresses
  110. if (have_option('e', 'email')) {
  111. $address = trim(get_option_value('e', 'email'));
  112. foreach ($reminders as $reminder) {
  113. // real bad voodoo here
  114. extract($reminder);
  115. $confirm = new $className;
  116. $confirm->address = $address;
  117. $result = $confirm->find(true);
  118. if (empty($result)) {
  119. throw new Exception("No confirmation code found for {$address}.");
  120. }
  121. $qm->enqueue(array($confirm, $opts), $utransport);
  122. if (!$quiet) { print "Sent all pending {$type} reminder to {$address}.\n"; }
  123. }
  124. } else if (have_option('a', 'all')) {
  125. foreach ($reminders as $reminder) {
  126. extract($reminder);
  127. $qm->enqueue(array($type, $opts), 'siterem');
  128. if (!$quiet) { print "Sent pending {$type} reminders to all unconfirmed addresses on the site.\n"; }
  129. }
  130. } else {
  131. show_help();
  132. exit(1);
  133. }
  134. } catch (Exception $e) {
  135. if (!$quiet) { print $e->getMessage() . "\n"; }
  136. common_log(LOG_ERR, $e->getMessage(), __FILE__);
  137. exit(1);
  138. }
  139. }