aboutsummaryrefslogtreecommitdiff
path: root/mod/groups/upgrades/2011030101.php
blob: 666ae3736c30fc160d07c3754d70f08b81b39f89 (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
<?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
 */

$topics = elgg_get_entities(array(
	'type' => 'object',
	'subtype' => 'groupforumtopic',
	'limit' => 5,
));

// if not topics, no upgrade required
if (!$topics) {
	return;
}

// if all five of the topics have empty descriptions, we need to upgrade
foreach ($topics as $topic) {
	if ($topic->description) {
		return;
	}
}


/**
 * Condense annotation into object
 *
 * @param ElggObject $topic
 */
function groups_2011030101($topic) {

	$annotation = $topic->getAnnotations('group_topic_post', 1);
	if (!$annotation) {
		// no text for this forum post so we delete (probably caused by #2624)
		return $topic->delete();
	}

	$topic->description = $annotation[0]->value;
	$topic->save();

	return $annotation[0]->delete();
}

$options = array(
	'type' => 'object',
	'subtype' => 'groupforumtopic',
	'limit' => 0,
);
$batch = new ElggBatch('elgg_get_entities', $options, 'groups_2011030101', 100);

if ($batch->callbackResult) {
	error_log("Elgg Groups upgrade (2011030101) succeeded");
} else {
	error_log("Elgg Groups upgrade (2011030101) failed");
}