Beispiel #1
0
/**
 * Condense first annotation into object
 *
 * @param ElggObject $topic
 */
function threads_groupforumtopic_2012100501($topic)
{
    require_once elgg_get_plugins_path() . 'upgrade-tools/lib/upgrade_tools.php';
    $first_post = current($topic->getEntitiesFromRelationship('group_discussion_top_level_post', false, 1));
    global $MIGRATED;
    $MIGRATED += 1;
    if ($topic->migrated == 1) {
        return true;
    }
    if ($MIGRATED % 100 == 0) {
        error_log("topic {$topic->guid} {$first_post->guid}");
    }
    if ($first_post) {
        $annotations = $first_post->getAnnotations('group_topic_post');
        $description = "";
        foreach ($annotations as $annotation) {
            if ($annotation->value) {
                $description = $annotation->value;
            }
        }
        $topic->description = $description;
        $topic->migrated = 1;
        $topic->save();
        // delete the first post, we dont need it any more
        $first_post->delete();
        // update river
        $options = array('object_guid' => $topic->guid);
        $items = elgg_get_river($options);
        foreach ($items as $item) {
            if ($item->action_type == 'create') {
                upgrade_update_river($item->id, 'river/object/groupforumtopic/create', $topic->guid, 0);
            }
        }
    }
    return true;
}