2011010101.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Migrate plugins to the new system using \ElggPlugin and private settings
  4. */
  5. $old_ia = elgg_set_ignore_access(true);
  6. $site = get_config('site');
  7. $old_plugin_order = unserialize($site->pluginorder);
  8. $old_enabled_plugins = $site->enabled_plugins;
  9. $db_prefix = get_config('dbprefix');
  10. $plugin_subtype_id = get_subtype_id('object', 'plugin');
  11. // easy one first: make sure the the site owns all plugin entities.
  12. $q = "UPDATE {$db_prefix}entities e
  13. SET owner_guid = $site->guid, container_guid = $site->guid
  14. WHERE e.type = 'object' AND e.subtype = $plugin_subtype_id";
  15. $r = update_data($q);
  16. // rewrite all plugin:setting:* to ELGG_PLUGIN_USER_SETTING_PREFIX . *
  17. $q = "UPDATE {$db_prefix}private_settings
  18. SET name = replace(name, 'plugin:settings:', '" . ELGG_PLUGIN_USER_SETTING_PREFIX . "')
  19. WHERE name LIKE 'plugin:settings:%'";
  20. $r = update_data($q);
  21. // grab current plugin GUIDs to add a temp priority
  22. $q = "SELECT * FROM {$db_prefix}entities e
  23. JOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid
  24. WHERE e.type = 'object' AND e.subtype = $plugin_subtype_id";
  25. $plugins = get_data($q);
  26. foreach ($plugins as $plugin) {
  27. $priority = _elgg_namespace_plugin_private_setting('internal', 'priority');
  28. set_private_setting($plugin->guid, $priority, 0);
  29. }
  30. // force regenerating plugin entities
  31. _elgg_generate_plugin_entities();
  32. // set the priorities for all plugins
  33. // this function rewrites it to a normal index so use the current one.
  34. _elgg_set_plugin_priorities($old_plugin_order);
  35. // add relationships for enabled plugins
  36. if ($old_enabled_plugins) {
  37. // they might only have one plugin enabled.
  38. if (!is_array($old_enabled_plugins)) {
  39. $old_enabled_plugins = array($old_enabled_plugins);
  40. }
  41. // sometimes there were problems and you'd get 1000s of enabled plugins.
  42. $old_enabled_plugins = array_unique($old_enabled_plugins);
  43. foreach ($old_enabled_plugins as $plugin_id) {
  44. $plugin = elgg_get_plugin_from_id($plugin_id);
  45. if ($plugin) {
  46. $plugin->activate();
  47. }
  48. }
  49. }
  50. // invalidate caches
  51. elgg_invalidate_simplecache();
  52. elgg_reset_system_cache();
  53. // clean up.
  54. remove_metadata($site->guid, 'pluginorder');
  55. remove_metadata($site->guid, 'enabled_plugins');
  56. elgg_set_ignore_access($old_id);
  57. /**
  58. * @hack
  59. *
  60. * We stop the upgrade at this point because plugins weren't given the chance to
  61. * load due to the new plugin code introduced with Elgg 1.8. Instead, we manually
  62. * set the version and start the upgrade process again.
  63. *
  64. * The variables from upgrade_code() are available because this script was included
  65. */
  66. if ($upgrade_version > $version) {
  67. datalist_set('version', $upgrade_version);
  68. }
  69. // add ourselves to the processed_upgrades.
  70. $processed_upgrades[] = '2011010101.php';
  71. $processed_upgrades = array_unique($processed_upgrades);
  72. elgg_set_processed_upgrades($processed_upgrades);
  73. _elgg_upgrade_unlock();
  74. forward('upgrade.php');