Upgrade.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace ColdTrick\ContentSubscriptions;
  3. class Upgrade {
  4. /**
  5. * Listen to the upgrade event, to register a script
  6. *
  7. * @param string $event name of the event
  8. * @param string $type type of the event
  9. * @param null $object supplied object
  10. *
  11. * @return void
  12. */
  13. public static function registerScript($event, $type, $object) {
  14. // Upgrade also possible hidden entities. This feature get run
  15. // by an administrator so there's no need to ignore access.
  16. $access_status = access_get_show_hidden_status();
  17. access_show_hidden_entities(true);
  18. // register an upgrade script
  19. $options = array(
  20. 'type' => 'user',
  21. 'relationship' => CONTENT_SUBSCRIPTIONS_SUBSCRIPTION,
  22. 'inverse_relationship' => true,
  23. 'count' => true
  24. );
  25. $count = elgg_get_entities_from_relationship($options);
  26. if ($count) {
  27. $path = 'admin/upgrades/content_subscriptions';
  28. $upgrade = new \ElggUpgrade();
  29. if (!$upgrade->getUpgradeFromPath($path)) {
  30. $upgrade->setPath($path);
  31. $upgrade->title = 'Content Subscription upgrade';
  32. $upgrade->description = 'The way content subscriptions are handled has changed.
  33. Run this script to make sure all content subscriptions are migrated.';
  34. $upgrade->save();
  35. }
  36. }
  37. access_show_hidden_entities($access_status);
  38. }
  39. }