pluginqueuehandler.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. defined('GNUSOCIAL') || die();
  17. /**
  18. * Queue handler for letting plugins handle stuff.
  19. *
  20. * The module queue handler accepts notices over the "plugin" queue
  21. * and simply passes them through the "HandleQueuedNotice" event.
  22. *
  23. * This gives plugins a chance to do background processing without
  24. * actually registering their own queue and ensuring that things
  25. * are queued into it.
  26. *
  27. * Fancier plugins may wish to instead hook the 'GetQueueHandlerClass'
  28. * event with their own class, in which case they must ensure that
  29. * their notices get enqueued when they need them.
  30. */
  31. class PluginQueueHandler extends QueueHandler
  32. {
  33. function transport()
  34. {
  35. return 'plugin';
  36. }
  37. function handle($notice): bool
  38. {
  39. if (!($notice instanceof Notice)) {
  40. common_log(LOG_ERR, "Got a bogus notice, not broadcasting");
  41. return true;
  42. }
  43. try {
  44. Event::handle('HandleQueuedNotice', array(&$notice));
  45. } catch (NoProfileException $unp) {
  46. // We can't do anything about this, so just skip
  47. return true;
  48. }
  49. return true;
  50. }
  51. }