// no annotations left break; } $db_prefix = elgg_get_config('dbprefix'); $container_guids = array(); // Create a new object for each annotation foreach ($annotations as $annotation) { $object = new ElggDiscussionReply(); $object->owner_guid = $annotation->owner_guid; $object->container_guid = $annotation->entity_guid; $object->description = $annotation->value; $object->access_id = $annotation->access_id; // make sure disabled replies stay disabled $object->enabled = $annotation->enabled; $object->time_created = $annotation->time_created; $object->save(false); $container_guids[] = $object->container_guid; $guid = $object->getGUID(); if ($guid) { /** * Update the entry in river table for this reply * * - Update the view path * - Remove annotation id * - Save reply guid to the object_guid column */ $query = "\n\t\t\t\tUPDATE {$db_prefix}river\n\t\t\t\tSET view = 'river/object/discussion_reply/create',\n\t\t\t\t\ttype = 'object',\n\t\t\t\t\tsubtype = 'discussion_reply',\n\t\t\t\t\taction_type = 'reply',\n\t\t\t\t\tannotation_id = 0,\n\t\t\t\t\tobject_guid = {$guid},\n\t\t\t\t\ttarget_guid = {$object->container_guid}\n\t\t\t\tWHERE action_type = 'reply'\n\t\t\t\t AND annotation_id = {$annotation->id}\n\t\t\t"; if (!update_data($query)) { register_error(elgg_echo('upgrade:river_update_failed', array($annotation->id))); $error_count++; }
forward(REFERER); } $reply->description = $text; if ($reply->save()) { system_message(elgg_echo('discussion:reply:edited')); } else { register_error(elgg_echo('discussion:reply:error')); } } else { // add the reply to the forum topic $reply = new ElggDiscussionReply(); $reply->description = $text; $reply->access_id = $topic->access_id; $reply->container_guid = $topic->getGUID(); $reply->owner_guid = $user->getGUID(); $reply_guid = $reply->save(); if ($reply_guid == false) { register_error(elgg_echo('discussion:post:failure')); forward(REFERER); } elgg_create_river_item(array('view' => 'river/object/discussion_reply/create', 'action_type' => 'reply', 'subject_guid' => $user->guid, 'object_guid' => $reply->guid, 'target_guid' => $topic->guid)); system_message(elgg_echo('discussion:post:success')); } // return to activity page if posted from there if (!empty($_SERVER['HTTP_REFERER'])) { // don't redirect to URLs from client without verifying within site $site_url = preg_quote(elgg_get_site_url(), '~'); if (preg_match("~^{$site_url}activity(/|\\z)~", $_SERVER['HTTP_REFERER'], $m)) { forward("{$m[0]}#elgg-object-{$reply->guid}"); } }
$reply->container_guid = $topic->getGUID(); $reply->access_id = $topic->access_id; $reply->description = $answer->description; if ($reply->save()) { questions_backdate_entity($reply->getGUID(), $answer->time_created); } // copy all comments on the answer to topic replies $comment_options['container_guid'] = $answer->getGUID(); $comments = new ElggBatch('elgg_get_entities', $comment_options); foreach ($comments as $comment) { $reply = new ElggDiscussionReply(); $reply->owner_guid = $comment->getOwnerGUID(); $reply->container_guid = $topic->getGUID(); $reply->access_id = $topic->access_id; $reply->description = $comment->description; if ($reply->save()) { questions_backdate_entity($reply->getGUID(), $comment->time_created); } $comment->delete(); } $answer->delete(); } // last changes to the topic // backdate the discussion $topic->time_created = $entity->time_created; // set correct owner of the topic $topic->owner_guid = $entity->getOwnerGUID(); $topic->save(); // cleaup the old question $entity->delete(); // restore access
$success++; if ($discussion->status == 'published') { elgg_create_river_item(array('view' => 'river/object/discussion/create', 'action_type' => 'create', 'subject_guid' => $owner->guid, 'object_guid' => $discussion->guid)); } if ($container instanceof ElggGroup) { $members = $container->getMembers(['limit' => 10]); } else { if ($container instanceof ElggUser) { $members = $container->getFriends(['limit' => 10]); } } for ($k = 0; $k < $count; $k++) { $replier = $members[array_rand($members, 1)]; $reply = new ElggDiscussionReply(); $reply->description = $faker->text(); $reply->owner_guid = $replier->guid; $reply->container_guid = $discussion->guid; $reply->save(); elgg_create_river_item(array('view' => 'river/object/discussion_reply/create', 'action_type' => 'reply', 'subject_guid' => $replier->guid, 'object_guid' => $reply->guid, 'target_guid' => $discussion->guid)); } } else { $error++; } } } if ($error) { system_message(elgg_echo('faker:gen_discussions:error', array($success, $error))); } else { system_message(elgg_echo('faker:gen_discussions:success', array($success))); } forward(REFERER);