Skip to content

Instantly share code, notes, and snippets.

@cash
Created March 3, 2011 00:32
Show Gist options
  • Save cash/852092 to your computer and use it in GitHub Desktop.
Save cash/852092 to your computer and use it in GitHub Desktop.
Elgg pre-1.8 svn upgrade for group replies
<?php
/**
* Moves comments to topic posts (replies). Only needed for those running
* an Elgg install based on svn before the 1.8 release. 1.8 release uses
* the same storage of forum topic replies as 1.7.
*
* To run, hit http://example.org/mod/groups/upgrade.php in your browser.
* Obviously, you must copy this script to that location. If you change the
* location, you'll need to update the require statement on start.php.
*/
require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
$site = elgg_get_site_entity();
$id = $site->annotate('group_topic_post', 'test', ACCESS_PUBLIC);
if (!$id) {
echo 'failed to create a test annotation';
exit;
}
if (!elgg_delete_annotation_by_id($id)) {
echo 'ugh, failed to remove the test annotation';
exit;
}
$group_topic_post_id = get_metastring_id('group_topic_post');
if (!$group_topic_post_id) {
echo 'huh, could not figure out the metastring id of group_topic_post';
exit;
}
$generic_comment_id = get_metastring_id('generic_comment');
if (!$generic_comment_id) {
echo 'huh, could not figure out the metastring id of generic_comment';
exit;
}
$groupforumtopic_id = get_subtype_id('object', 'groupforumtopic');
if (!$groupforumtopic_id) {
echo 'No forum posts so you should be set';
exit;
}
$db_prefix = elgg_get_config('dbprefix');
$sql = "UPDATE {$db_prefix}annotations AS a
JOIN {$db_prefix}entities AS e ON a.entity_guid = e.guid
SET a.name_id = $group_topic_post_id
WHERE a.name_id = $generic_comment_id AND e.subtype = $groupforumtopic_id";
if (!update_data($sql)) {
echo 'Oh, no, we failed running updating the annotations';
}
$sql = "UPDATE {$db_prefix}river SET view = 'river/annotation/group_topic_post/reply',
action_type = 'reply'
WHERE subtype = 'groupforumtopic' AND action_type = 'comment'";
if (update_data($sql)) {
echo 'Success!';
} else {
echo 'Oh, no, we failed updating the river';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment