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
76
77
78
79
|
<?php
/**
* Move text of first annotation to group forum topic object and delete annotation
*
* First determine if the upgrade is needed and then if needed, batch the update
*/
$tasks = elgg_get_entities(array(
'type' => 'object',
'subtype' => 'tasks',
'limit' => 1,
));
// if not topics, no upgrade required
if (empty($tasks)) {
return;
}
function tasks_2012100501($task) {
require_once(elgg_get_plugins_path() . 'upgrade-tools/lib/upgrade_tools.php');
if ($task->long_description) {
$task->description = $task->long_description;
$task->deleteMetadata('long_description');
$task->save();
}
if ($task->parent_guid) {
$task->list_guid = $task->parent_guid;
$task->deleteMetadata('parent_guid');
}
else {
$task->list_guid = 0;
}
/* Active was set as default, so it is not indicative of which tasks are
really active */
$task->deleteMetadata('active');
if ($task->done) {
$task->status = 'done';
$task->deleteMetadata('done');
} else {
$task->status = 'new';
}
// reset priority since old system was a mess
$task->priority = 2;
upgrade_change_subtype($task, 'task');
// update river
$options = array('object_guid' => $task->guid);
$items = elgg_get_river($options);
foreach($items as $item) {
if ($item->action_type == 'create') {
upgrade_update_river($item->id, 'river/object/task/create', $task->guid, 0);
}
elseif(in_array($item->action_type, array('done', 'undone', 'subscribe', 'unsubscribe'))) {
elgg_delete_river(array('id' => $item->id));
}
}
return true;
}
/*
* Run upgrade. First topics, then replies.
*/
$previous_access = elgg_set_ignore_access(true);
$options = array(
'type' => 'object',
'subtype' => 'tasks',
'limit' => 0,
);
$batch = new ElggBatch('elgg_get_entities', $options, "tasks_2012100501", 100, false);
elgg_set_ignore_access($previous_access);
if ($batch->callbackResult) {
error_log("Elgg Tasks upgrade (2012100501) succeeded");
} else {
error_log("Elgg Tasks upgrade (2012100501) failed");
}
|