events.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * All event handler callback functions are bundled in this file
  4. */
  5. /**
  6. * Make sure we can autosubscribe the user to further updates
  7. *
  8. * @param string $event "create"
  9. * @param string $type "object"
  10. * @param ElggObject $object the created annotation
  11. *
  12. * @return void
  13. */
  14. function content_subscriptions_create_object_handler($event, $type, ElggObject $object) {
  15. if (!empty($object) && (elgg_instanceof($object, "object", "discussion_reply") || elgg_instanceof($object, "object", "comment"))) {
  16. $owner = $object->getOwnerEntity();
  17. $entity = $object->getContainerEntity();
  18. // add auto subscription for this user
  19. content_subscriptions_autosubscribe($entity->getGUID(), $owner->getGUID());
  20. }
  21. }
  22. /**
  23. * Listen to the upgrade event
  24. *
  25. * @param string $event name of the event
  26. * @param string $type type of the event
  27. * @param null $object supplied object
  28. *
  29. * @return void
  30. */
  31. function content_subscriptions_upgrade_system_handler($event, $type, $object) {
  32. // Upgrade also possible hidden entities. This feature get run
  33. // by an administrator so there's no need to ignore access.
  34. $access_status = access_get_show_hidden_status();
  35. access_show_hidden_entities(true);
  36. // register an upgrade script
  37. $options = array(
  38. "type" => "user",
  39. "relationship" => CONTENT_SUBSCRIPTIONS_SUBSCRIPTION,
  40. "inverse_relationship" => true,
  41. "count" => true
  42. );
  43. $count = elgg_get_entities_from_relationship($options);
  44. if ($count) {
  45. $path = "admin/upgrades/content_subscriptions";
  46. $upgrade = new ElggUpgrade();
  47. if (!$upgrade->getUpgradeFromPath($path)) {
  48. $upgrade->setPath($path);
  49. $upgrade->title = "Content Subscription upgrade";
  50. $upgrade->description = "The way content subscriptions are handled has changed. Run this script to make sure all content subscriptions are migrated.";
  51. $upgrade->save();
  52. }
  53. }
  54. access_show_hidden_entities($access_status);
  55. }