/** * Called before each test method. */ public function setUp() { $this->container = new \ElggObject(); $this->container->access_id = ACCESS_PUBLIC; $this->container->save(); $this->comment = new \ElggComment(); $this->comment->description = 'comment description'; $this->comment->container_guid = $this->container->guid; $this->comment->access_id = $this->container->access_id; $this->comment->save(); }
/** * @param $guid * @param $text * @param $username * @return mixed * @throws InvalidParameterException */ function file_post_comment($guid, $text, $username) { if (!$username) { $user = elgg_get_logged_in_user_entity(); } else { $user = get_user_by_username($username); if (!$user) { throw new InvalidParameterException('registration:usernamenotvalid'); } } if ($guid) { $entity = get_entity($guid); } if ($entity) { $return['success'] = false; if (empty($text)) { $return['message'] = elgg_echo("thefilecomment:blank"); return $return; } if ($entity) { $comment = new ElggComment(); $comment->description = $text; $comment->owner_guid = $user->guid; $comment->container_guid = $entity->guid; $comment->access_id = $entity->access_id; $guid_comment = $comment->save(); if ($guid_comment) { $return['success'] = $guid_comment; elgg_create_river_item(array('view' => 'river/object/comment/create', 'action_type' => 'comment', 'subject_guid' => $user->guid, 'object_guid' => $guid_comment, 'target_guid' => $entity->guid)); } } return $return; } else { $return['success'] = false; $return['message'] = 'Require guid from post'; return $return; } }
register_error(elgg_echo('generic_comment:failure')); } } else { // Create a new comment on the target entity $entity = get_entity($entity_guid); if (!$entity) { register_error(elgg_echo("generic_comment:notfound")); forward(REFERER); } $user = elgg_get_logged_in_user_entity(); $comment = new ElggComment(); $comment->description = $comment_text; $comment->owner_guid = $user->getGUID(); $comment->container_guid = $entity->getGUID(); $comment->access_id = $entity->access_id; $guid = $comment->save(); if (!$guid) { register_error(elgg_echo("generic_comment:failure")); forward(REFERER); } // Notify if poster wasn't owner if ($entity->owner_guid != $user->guid) { $owner = $entity->getOwnerEntity(); notify_user($owner->guid, $user->guid, elgg_echo('generic_comment:email:subject', array(), $owner->language), elgg_echo('generic_comment:email:body', array($entity->title, $user->name, $comment_text, $comment->getURL(), $user->name, $user->getURL()), $owner->language), array('object' => $comment, 'action' => 'create')); } // Add to river elgg_create_river_item(array('view' => 'river/object/comment/create', 'action_type' => 'comment', 'subject_guid' => $user->guid, 'object_guid' => $guid, 'target_guid' => $entity_guid)); system_message(elgg_echo('generic_comment:posted')); } if ($is_edit_page) { forward($comment->getURL());
if (!$annotations) { // no annotations left break; } $db_prefix = elgg_get_config('dbprefix'); // Create a new object for each annotation foreach ($annotations as $annotation) { $object = new ElggComment(); $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 comments stay disabled $object->enabled = $annotation->enabled; $object->time_created = $annotation->time_created; $object->save(false); $guid = $object->getGUID(); if ($guid) { /** * Update the entry in river table for this comment * * - Update the view path * - Remove annotation id * - Save comment guid to the object_guid column */ $query = "\n\t\t\t\tUPDATE {$db_prefix}river\n\t\t\t\tSET view = 'river/object/comment/create',\n\t\t\t\t\ttype = 'object',\n\t\t\t\t\tsubtype = 'comment',\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 = 'comment'\n\t\t\t\t AND annotation_id = {$annotation->id}\n\t\t\t"; if (!update_data($query)) { register_error(elgg_echo('upgrade:comments:river_update_failed', array($annotation->id))); $error_count++; continue; }
$comment->__faker = true; if ($comment->save()) { $success++; elgg_create_river_item(array('view' => 'river/object/comment/create', 'action_type' => 'comment', 'subject_guid' => $comment->owner_guid, 'object_guid' => $comment->guid, 'target_guid' => $entity->guid)); for ($k = 0; $k < $reply_count; $k++) { $owner = $users[array_rand($users, 1)]; if ($comment->canComment($owner->guid)) { $reply = new \ElggComment(); $reply->subtype = 'comment'; $reply->owner_guid = $owner->guid; $reply->container_guid = $comment->guid; $reply->description = $faker->text(rand(25, 1000)); $reply->access_id = $entity->access_id; $reply->time_created = rand($comment->time_created, time()); $reply->__faker = true; if ($reply->save()) { $success++; elgg_create_river_item(array('view' => 'river/object/comment/create', 'action_type' => 'comment', 'subject_guid' => $reply->owner_guid, 'object_guid' => $reply->guid, 'target_guid' => $comment->guid)); } else { $error++; } } } } else { $error++; } } } if ($error) { system_message(elgg_echo('faker:gen_comments:error', array($success, $error))); } else {