siteemailsummaryhandler.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. *
  5. * Handler for queue items of type 'sitesum', sends email summaries
  6. * to all users on the site.
  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 Sample
  22. * @package StatusNet
  23. * @author Evan Prodromou <evan@status.net>
  24. * @copyright 2010 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. *
  33. * Handler for queue items of type 'sitesum', sends email summaries
  34. * to all users on the site.
  35. *
  36. * @category Email
  37. * @package StatusNet
  38. * @author Evan Prodromou <evan@status.net>
  39. * @copyright 2010 StatusNet, Inc.
  40. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  41. * @link http://status.net/
  42. */
  43. class SiteEmailSummaryHandler extends QueueHandler
  44. {
  45. /**
  46. * Return transport keyword which identifies items this queue handler
  47. * services; must be defined for all subclasses.
  48. *
  49. * Must be 8 characters or less to fit in the queue_item database.
  50. * ex "email", "jabber", "sms", "irc", ...
  51. *
  52. * @return string
  53. */
  54. function transport()
  55. {
  56. return 'sitesum';
  57. }
  58. /**
  59. * Handle the site
  60. *
  61. * @param mixed $object
  62. * @return boolean true on success, false on failure
  63. */
  64. function handle($object)
  65. {
  66. $qm = QueueManager::get();
  67. try {
  68. // Enqueue a summary for all users
  69. $user = new User();
  70. $user->find();
  71. while ($user->fetch()) {
  72. try {
  73. $qm->enqueue($user->id, 'usersum');
  74. } catch (Exception $e) {
  75. common_log(LOG_WARNING, $e->getMessage());
  76. continue;
  77. }
  78. }
  79. } catch (Exception $e) {
  80. common_log(LOG_WARNING, $e->getMessage());
  81. }
  82. return true;
  83. }
  84. }