sendemailreminder.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #!/usr/bin/env php
  2. <?php
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. /**
  18. * @package GNUsocial
  19. * @copyright 2011 StatusNet, Inc.
  20. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  21. */
  22. define('INSTALLDIR', dirname(__DIR__, 3));
  23. define('PUBLICDIR', INSTALLDIR);
  24. $shortoptions = 't:e:auo';
  25. $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
  29. -t --type type of reminder to send (register | invite | all)
  30. -e --email email address to send reminder to
  31. -a --all send reminder to all addresses
  32. -u --universe send reminder to all addresses on all sites
  33. -o --onetime send one-time reminder to older addresses
  34. END_OF_SENDEMAILREMINDER_HELP;
  35. require_once INSTALLDIR . '/scripts/commandline.inc';
  36. $quiet = have_option('q', 'quiet');
  37. $types = array(
  38. // registration confirmation reminder
  39. 'register' => array(
  40. 'type' => 'register',
  41. 'className' => 'Confirm_address',
  42. 'utransport' => 'uregrem'
  43. ),
  44. // invitation confirmation reminder
  45. 'invite' => array(
  46. 'type' => 'invite',
  47. 'className' => 'Invitation',
  48. 'utransport' => 'uinvrem'
  49. )
  50. // ... add more here
  51. );
  52. $type = null;
  53. $opts = array(); // special options like "onetime"
  54. if (have_option('t', 'type')) {
  55. $type = trim(get_option_value('t', 'type'));
  56. if (!in_array($type, array_keys($types)) && $type !== 'all') {
  57. echo _m('Unknown reminder type: ' . $type . '.' . "\n");
  58. exit(1);
  59. }
  60. } else {
  61. show_help();
  62. exit(1);
  63. }
  64. if (have_option('o', 'onetime')) {
  65. $opts['onetime'] = true;
  66. if (!$quiet) {
  67. echo 'Special one-time reminder mode.' . "\n";
  68. }
  69. }
  70. $reminders = array();
  71. switch ($type) {
  72. case 'register':
  73. $reminders[] = $types['register'];
  74. break;
  75. case 'invite':
  76. $reminders[] = $types['invite'];
  77. break;
  78. case 'all':
  79. $reminders = $types;
  80. break;
  81. }
  82. if (have_option('u', 'universe')) {
  83. $sn = new Status_network();
  84. try {
  85. if ($sn->find()) {
  86. while ($sn->fetch()) {
  87. try {
  88. $server = $sn->getServerName();
  89. GNUsocial::init($server);
  90. // Different queue manager, maybe!
  91. $qm = QueueManager::get();
  92. foreach ($reminders as $reminder) {
  93. extract($reminder);
  94. $qm->enqueue(array($type, $opts), 'siterem');
  95. if (!$quiet) {
  96. echo 'Sent pending ' . $type . ' reminders for ' . $server . '.' . "\n";
  97. }
  98. }
  99. } catch (Exception $e) {
  100. // keep going
  101. common_log(LOG_ERR, "Couldn't init {$server}.\n", __FILE__);
  102. if (!$quiet) {
  103. echo "Couldn't init " . $server . ".\n";
  104. }
  105. continue;
  106. }
  107. }
  108. if (!$quiet) {
  109. echo 'Done! Reminders sent to all unconfirmed addresses in the known universe.' . "\n";
  110. }
  111. }
  112. } catch (Exception $e) {
  113. if (!$quiet) {
  114. echo $e->getMessage() . "\n";
  115. }
  116. common_log(LOG_ERR, $e->getMessage(), __FILE__);
  117. exit(1);
  118. }
  119. } else {
  120. $qm = QueueManager::get();
  121. try {
  122. // enqueue reminder for specific email address or all unconfirmed addresses
  123. if (have_option('e', 'email')) {
  124. $address = trim(get_option_value('e', 'email'));
  125. foreach ($reminders as $reminder) {
  126. // real bad voodoo here
  127. extract($reminder);
  128. $confirm = new $className;
  129. $confirm->address = $address;
  130. $result = $confirm->find(true);
  131. if (empty($result)) {
  132. throw new Exception("No confirmation code found for {$address}.");
  133. }
  134. $qm->enqueue(array($confirm, $opts), $utransport);
  135. if (!$quiet) {
  136. echo 'Sent all pending ' . $type . ' reminder to ' . $address . '.' . "\n";
  137. }
  138. }
  139. } elseif (have_option('a', 'all')) {
  140. foreach ($reminders as $reminder) {
  141. extract($reminder);
  142. $qm->enqueue(array($type, $opts), 'siterem');
  143. if (!$quiet) {
  144. echo 'Sent pending ' . $type . ' reminders to all unconfirmed addresses on the site.' . "\n";
  145. }
  146. }
  147. } else {
  148. show_help();
  149. exit(1);
  150. }
  151. } catch (Exception $e) {
  152. if (!$quiet) {
  153. echo $e->getMessage() . "\n";
  154. }
  155. common_log(LOG_ERR, $e->getMessage(), __FILE__);
  156. exit(1);
  157. }
  158. }