blob: be1adac1a9a77352219c6988cb1ab70d6b4aca87 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 | <?php
/**
 * Migrate plugins to the new system using ElggPlugin and private settings
 */
$old_ia = elgg_set_ignore_access(true);
$site = get_config('site');
$old_plugin_order = unserialize($site->pluginorder);
$old_enabled_plugins = $site->enabled_plugins;
$db_prefix = get_config('dbprefix');
$plugin_subtype_id = get_subtype_id('object', 'plugin');
// easy one first: make sure the the site owns all plugin entities.
$q = "UPDATE {$db_prefix}entities e
	SET owner_guid = $site->guid, container_guid = $site->guid
	WHERE e.type = 'object' AND e.subtype = $plugin_subtype_id";
$r = update_data($q);
// rewrite all plugin:setting:* to ELGG_PLUGIN_USER_SETTING_PREFIX . *
$q = "UPDATE {$db_prefix}private_settings
	SET name = replace(name, 'plugin:settings:', '" . ELGG_PLUGIN_USER_SETTING_PREFIX . "')
	WHERE name LIKE 'plugin:settings:%'";
$r = update_data($q);
// grab current plugin GUIDs to add a temp priority
$q = "SELECT * FROM {$db_prefix}entities e
	JOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid
	WHERE e.type = 'object' AND e.subtype = $plugin_subtype_id";
$plugins = get_data($q);
foreach ($plugins as $plugin) {
	$priority = elgg_namespace_plugin_private_setting('internal', 'priority');
	set_private_setting($plugin->guid, $priority, 0);
}
// force regenerating plugin entities
elgg_generate_plugin_entities();
// set the priorities for all plugins
// this function rewrites it to a normal index so use the current one.
elgg_set_plugin_priorities($old_plugin_order);
// add relationships for enabled plugins
if ($old_enabled_plugins) {
	// they might only have one plugin enabled.
	if (!is_array($old_enabled_plugins)) {
		$old_enabled_plugins = array($old_enabled_plugins);
	}
	// sometimes there were problems and you'd get 1000s of enabled plugins.
	$old_enabled_plugins = array_unique($old_enabled_plugins);
	foreach ($old_enabled_plugins as $plugin_id) {
		$plugin = elgg_get_plugin_from_id($plugin_id);
		if ($plugin) {
			$plugin->activate();
		}
	}
}
// invalidate caches
elgg_invalidate_simplecache();
elgg_filepath_cache_reset();
// clean up.
remove_metadata($site->guid, 'pluginorder');
remove_metadata($site->guid, 'enabled_plugins');
elgg_set_ignore_access($old_id);
 |