aboutsummaryrefslogtreecommitdiff
path: root/actions/widgets/upgrade.php
blob: 0a5cf8d48b8fe603ea232e18d21872936dbc592c (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
<?php
/**
 * Upgrade default widgets for Elgg 1.8
 *
 * Pre-1.8, default widgets were stored as metadata on a defaultwidgets object.
 * Now they are stored as widget objects owned by the site.
 * 
 * @package Elgg.Core
 * @subpackage Widgets.Management
 */

$object = elgg_get_entities(array(
	'type' => 'object',
	'subtype' => 'moddefaultwidgets',
	'limit' => 1,
));

if (!$object) {
	forward(REFERER);
}

$object = $object[0];

$site = elgg_get_site_entity();

$ia = elgg_set_ignore_access(true);
foreach (array('profile', 'dashboard') as $context) {
	if (isset($object->$context)) {
		elgg_push_context($context);
		elgg_push_context('default_widgets');
		elgg_push_context('widgets');

		// deserialize the widget information
		list($left, $middle, $right) = split('%%', $object->$context);
		$left_widgets = split('::', $left);
		$middle_widgets = split('::', $middle);
		$right_widgets = split('::', $right);

		// 1st column is right column in default theme
		$widgets = array(
			1 => array_reverse($right_widgets),
			2 => array_reverse($middle_widgets),
			3 => array_reverse($left_widgets),
		);

		foreach ($widgets as $column => $column_widgets) {
			foreach ($column_widgets as $handler) {
				$guid = elgg_create_widget($site->getGUID(), $handler, $context);
				if ($guid) {
					$widget = get_entity($guid);
					$widget->move($column, 0);
				}
			}
		}

		elgg_pop_context();
		elgg_pop_context();
		elgg_pop_context();
	}
}
elgg_set_ignore_access($ia);

$object->delete();
system_message(elgg_echo('upgrade:core'));
forward(REFERER);