pluginqueuehandler.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. public $widgetOpts;
  34. public $scoped;
  35. function transport()
  36. {
  37. return 'plugin';
  38. }
  39. function handle($notice): bool
  40. {
  41. if (!($notice instanceof Notice)) {
  42. common_log(LOG_ERR, "Got a bogus notice, not broadcasting");
  43. return true;
  44. }
  45. try {
  46. Event::handle('HandleQueuedNotice', array(&$notice));
  47. } catch (NoProfileException $unp) {
  48. // We can't do anything about this, so just skip
  49. return true;
  50. }
  51. return true;
  52. }
  53. }