siteconfirmreminderhandler.php 3.9 KB

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