siteconfirmreminderhandler.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. *
  5. * Handler for reminder queue items which send reminder emails to all users
  6. * we would like to complete a given process (e.g.: registration).
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * @category Email
  22. * @package StatusNet
  23. * @author Zach Copley <zach@status.net>
  24. * @copyright 2011 StatusNet, Inc.
  25. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  26. * @link http://status.net/
  27. */
  28. if (!defined('STATUSNET')) {
  29. exit(1);
  30. }
  31. /**
  32. * Handler for reminder queue items which send reminder emails to all users
  33. * we would like to complete a given process (e.g.: registration)
  34. *
  35. * @category Email
  36. * @package StatusNet
  37. * @author Zach Copley <zach@status.net>
  38. * @copyright 2011 StatusNet, Inc.
  39. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  40. * @link http://status.net/
  41. */
  42. class SiteConfirmReminderHandler extends QueueHandler
  43. {
  44. /**
  45. * Return transport keyword which identifies items this queue handler
  46. * services; must be defined for all subclasses.
  47. *
  48. * Must be 8 characters or less to fit in the queue_item database.
  49. * ex "email", "jabber", "sms", "irc", ...
  50. *
  51. * @return string
  52. */
  53. function transport()
  54. {
  55. return 'siterem';
  56. }
  57. /**
  58. * Handle the site
  59. *
  60. * @param array $remitem type of reminder to send and any special options
  61. * @return boolean true on success, false on failure
  62. */
  63. function handle($remitem)
  64. {
  65. list($type, $opts) = $remitem;
  66. $qm = QueueManager::get();
  67. try {
  68. switch($type) {
  69. case UserConfirmRegReminderHandler::REGISTER_REMINDER:
  70. $confirm = new Confirm_address();
  71. $confirm->address_type = $type;
  72. $confirm->find();
  73. while ($confirm->fetch()) {
  74. try {
  75. $qm->enqueue(array($confirm, $opts), 'uregrem');
  76. } catch (Exception $e) {
  77. common_log(LOG_WARNING, $e->getMessage());
  78. continue;
  79. }
  80. }
  81. break;
  82. case UserInviteReminderHandler::INVITE_REMINDER:
  83. $invitation = new Invitation();
  84. // Only send one reminder (the latest one), regardless of how many invitations a user has
  85. $sql = 'SELECT * FROM (SELECT * FROM invitation WHERE registered_user_id IS NULL ORDER BY created DESC) invitees GROUP BY invitees.address';
  86. $invitation->query($sql);
  87. while ($invitation->fetch()) {
  88. try {
  89. $qm->enqueue(array($invitation, $opts), 'uinvrem');
  90. } catch (Exception $e) {
  91. common_log(LOG_WARNING, $e->getMessage());
  92. continue;
  93. }
  94. }
  95. break;
  96. default:
  97. // WTF?
  98. common_log(
  99. LOG_ERR,
  100. "Received unknown confirmation address type",
  101. __FILE__
  102. );
  103. }
  104. } catch (Exception $e) {
  105. common_log(LOG_ERR, $e->getMessage());
  106. return false;
  107. }
  108. return true;
  109. }
  110. }