public function testCanGetEntitiesByAnnotationCreationTime() { $prefix = elgg_get_config('dbprefix'); $users = elgg_get_entities(array('type' => 'user', 'limit' => 1)); // create some test annotations $subtypes = $this->getRandomValidSubtypes(array('object'), 1); $subtype = $subtypes[0]; $annotation_name = 'test_annotation_name_' . rand(); // our targets $valid1 = new \ElggObject(); $valid1->subtype = $subtype; $valid1->save(); $id1 = $valid1->annotate($annotation_name, 1, ACCESS_PUBLIC, $users[0]->guid); // this one earlier $yesterday = time() - 86400; update_data("\n\t\t\tUPDATE {$prefix}annotations\n\t\t\tSET time_created = {$yesterday}\n\t\t\tWHERE id = {$id1}\n\t\t"); $valid2 = new \ElggObject(); $valid2->subtype = $subtype; $valid2->save(); $valid2->annotate($annotation_name, 1, ACCESS_PUBLIC, $users[0]->guid); $options = array('annotation_owner_guid' => $users[0]->guid, 'annotation_created_time_lower' => time() - 3600, 'annotation_name' => $annotation_name); $entities = elgg_get_entities_from_annotations($options); $this->assertEqual(1, count($entities)); $this->assertEqual($valid2->guid, $entities[0]->guid); $options = array('annotation_owner_guid' => $users[0]->guid, 'annotation_created_time_upper' => time() - 3600, 'annotation_name' => $annotation_name); $entities = elgg_get_entities_from_annotations($options); $this->assertEqual(1, count($entities)); $this->assertEqual($valid1->guid, $entities[0]->guid); $valid1->delete(); $valid2->delete(); }
function hypefaker_add_page($owner, $container, $parent = null) { $locale = elgg_get_plugin_setting('locale', 'hypeFaker', 'en_US'); $faker = Factory::create($locale); $access_array = get_write_access_array($owner->guid); $access_id = array_rand($access_array, 1); $write_access_array = get_write_access_array($owner->guid); unset($write_access_array[ACCESS_PUBLIC]); $write_access_id = array_rand($write_access_array, 1); $page = new ElggObject(); $page->subtype = $parent ? 'page' : 'page_top'; $page->owner_guid = $owner->guid; $page->container_guid = $container->guid; $page->title = $faker->sentence(6); $page->description = $faker->text(500); $page->tags = $faker->words(5); $page->access_id = $access_id; $page->write_access_id = $write_access_id; $page->__faker = true; if ($parent) { $page->parent_guid = $parent->guid; } if ($page->save()) { $page->annotate('page', $page->description, $page->access_id, $page->owner_guid); elgg_create_river_item(array('view' => 'river/object/page/create', 'action_type' => 'create', 'subject_guid' => $page->owner_guid, 'object_guid' => $page->getGUID())); // add some revisions $users = elgg_get_entities_from_metadata(array('types' => 'user', 'limit' => rand(1, 10), 'order_by' => 'RAND()', 'metadata_names' => '__faker')); foreach ($users as $user) { if ($page->canAnnotate($user->guid, 'page')) { $last_revision = $faker->text(500); $page->annotate('page', $last_annotation, $page->access_id, $user->guid); } } if (!empty($last_revision)) { $page->description = $last_revision; $page->save(); } return $page; } return false; }
public function testElggDeleteAnnotations() { $e = new ElggObject(); $e->save(); for ($i = 0; $i < 30; $i++) { $e->annotate('test_annotation', rand(0, 10000)); } $options = array('guid' => $e->getGUID(), 'limit' => 0); $annotations = elgg_get_annotations($options); $this->assertIdentical(30, count($annotations)); $this->assertTrue(elgg_delete_annotations($options)); $annotations = elgg_get_annotations($options); $this->assertTrue(empty($annotations)); $this->assertTrue($e->delete()); }
public function testElggEntityGetAndSetAnnotations() { $this->assertIdentical($this->entity->getAnnotations(array('annotation_name' => 'non_existent')), array()); // save entity and check for annotation $this->entity->annotate('non_existent', 'foo'); $annotations = $this->entity->getAnnotations(array('annotation_name' => 'non_existent')); $this->assertIsA($annotations[0], '\\ElggAnnotation'); $this->assertIdentical($annotations[0]->name, 'non_existent'); $this->assertEqual($this->entity->countAnnotations('non_existent'), 1); // @todo belongs in Annotations API test class $this->assertIdentical($annotations, elgg_get_annotations(array('guid' => $this->entity->getGUID()))); $this->assertIdentical($annotations, elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'object'))); $this->assertIdentical(false, elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'object', 'subtype' => 'fail'))); // clear annotation $this->assertTrue($this->entity->deleteAnnotations()); $this->assertEqual($this->entity->countAnnotations('non_existent'), 0); // @todo belongs in Annotations API test class $this->assertIdentical(array(), elgg_get_annotations(array('guid' => $this->entity->getGUID()))); $this->assertIdentical(array(), elgg_get_annotations(array('guid' => $this->entity->getGUID(), 'type' => 'object'))); }
if ($page_guid == $tree_page->guid) { $previous_parent = $page->parent_guid; $children = elgg_get_entities_from_metadata(array('metadata_name' => 'parent_guid', 'metadata_value' => $page->getGUID())); if ($children) { foreach ($children as $child) { $child->parent_guid = $previous_parent; } } } } $page->parent_guid = $parent_guid; } if ($page->save()) { //check in the page becaused the user just saved it if ($page->deleteMetadata("checkedOut")) { system_message(elgg_echo('pages:checked_in')); } else { system_message('Page could not be checked in. It is still locked for editing'); } elgg_clear_sticky_form('page'); // Now save description as an annotation $page->annotate('page', $page->description, $page->access_id); system_message(elgg_echo('pages:saved')); if ($new_page) { add_to_river('river/object/page/create', 'create', elgg_get_logged_in_user_guid(), $page->guid); } forward($page->getURL()); } else { register_error(elgg_echo('pages:error:notsaved')); forward(REFERER); }
$grouptopic->container_guid = $group_guid; // For now, set its access to public (we'll add an access dropdown shortly) $grouptopic->access_id = $access; // Set its title and description appropriately $grouptopic->title = $title; // Before we can set metadata, we need to save the topic if (!$grouptopic->save()) { register_error(elgg_echo("grouptopic:error")); forward("pg/groups/forum/{$group_guid}/"); } // Now let's add tags. We can pass an array directly to the object property! Easy. if (is_array($tagarray)) { $grouptopic->tags = $tagarray; } // add metadata $grouptopic->status = $status; // the current status i.e sticky, closed, resolved, open // now add the topic message as an annotation $grouptopic->annotate('group_topic_post', $message, $access, $user); // add to river add_to_river('river/forum/topic/create', 'create', $_SESSION['user']->guid, $grouptopic->guid); // Success message system_message(elgg_echo("grouptopic:created")); // Forward to the group forum page global $CONFIG; $url = $CONFIG->wwwroot . "pg/groups/forum/{$group_guid}/"; forward($url); } ?>
$error = elgg_echo('blog:error:cannot_save' . "{$name}={$value}"); break; } } } // only try to save base entity if no errors if (!$error) { if ($blog->save()) { // remove sticky form entries elgg_clear_sticky_form(); // remove autosave draft if exists $blog->clearAnnotations('blog_auto_save'); // if this was an edit, create a revision if (!$new_post && $revision_value) { // create a revision annotation $blog->annotate('blog_revision', $revision_value); } system_message(elgg_echo('blog:message:saved')); forward($success_forward_url); } else { register_error(elgg_echo('blog:error:cannot_save')); forward($error_forward_url); } } else { register_error($error); forward($error_forward_url); } // forward with success or failure if ($error) { register_error($error); forward($error_forward_url);
function pleio_api_save_wiki($content = "", $title = "", $wiki_id = null, $parent_id = null, $group_id = 0, $access_id = 0, $write_access_id = 0) { $wiki_id = $wiki_id ? $wiki_id : null; $user = elgg_get_logged_in_user_entity(); $user_id = $user !== false ? $user->guid : 0; if (!$content && !$wiki_id || !$user_id) { return new ErrorResult(elgg_echo("pages:error:no_save")); } $parent = false; $swordfish_group = $group_id ? pleio_api_swordfish_group($group_id) : false; if ($swordfish_group) { $group = get_entity($group_id); $url = pleio_api_swordfish_baseurl($group->site_guid) . "post-page"; $swordfish_name = pleio_api_swordfish_username($user->username); $params = array("title" => $title, "content" => $content); if (!$wiki_id) { $params["commentAllowed"] = 1; } if ($wiki_id) { $params["wikiId"] = $wiki_id; } elseif ($parent_id) { $params["parentId"] = $parent_id; } elseif ($group_id) { $params["groupId"] = $swordfish_group; } else { return new ErrorResult("Selecteer minimaal een groep of bovenliggende wiki"); } if ($access_id != ACCESS_PRIVATE) { $params["visibility"] = "internally_published"; } else { $params["visibility"] = "private"; } $result = pleio_api_call_swordfish_api($swordfish_name, $url, "POST", $params); if ($result->ok) { if (strpos($result->headers["CONTENT-TYPE"], "json")) { $response = json_decode($result->response); return new SaveSuccessResult(elgg_echo("pages:saved"), $response->id); } else { return new ErrorResult($result->headers["BOBO-EXCEPTION-VALUE"]); } } else { return new ErrorResult($result->headers["BOBO-EXCEPTION-VALUE"]); } } else { if ($wiki_id) { $wiki = get_entity($wiki_id); } else { $wiki = new ElggObject(); $wiki->owner_guid = $user_id; $wiki->subtype = "page_top"; $wiki->parent_guid = 0; } if ($group_id) { $wiki->container_guid = $group_id; } if ($access_id !== "") { $wiki->access_id = $access_id; } if ($write_access_id !== "") { $wiki->write_access_id = $write_access_id; } if (isset($parent_id)) { $parent = get_entity($parent_id); if ($parent) { $wiki->subtype = "page"; $wiki->parent_guid = $parent_id; $wiki->access_id = $parent->access_id; $wiki->container_guid = $parent->container_guid; $wiki->site_guid = $parent->site_guid; } } if ($title) { $wiki->title = $title; } if ($content) { $wiki->description = $content; } if (!$wiki->save()) { return new ErrorResult(elgg_echo("pages:error:no_save")); } $wiki->annotate('page', $wiki->description, $wiki->access_id); if (!$wiki_id) { add_to_river('river/object/page/create', 'create', $user_id, $wiki->guid); } return new SaveSuccessResult(elgg_echo("pages:saved"), $wiki->guid); } }
public function testElggAnnotationExists() { $e = new ElggObject(); $e->save(); $guid = $e->getGUID(); $this->assertFalse(elgg_annotation_exists($guid, 'test_annotation')); $e->annotate('test_annotation', rand(0, 10000)); $this->assertTrue(elgg_annotation_exists($guid, 'test_annotation')); // this metastring should always exist but an annotation of this name should not $this->assertFalse(elgg_annotation_exists($guid, 'email')); $options = array('guid' => $guid, 'limit' => 0); $this->assertTrue(elgg_disable_annotations($options)); $this->assertTrue(elgg_annotation_exists($guid, 'test_annotation')); $this->assertTrue($e->delete()); $this->assertFalse(elgg_annotation_exists($guid, 'test_annotation')); }
/** * Make sure entity is loaded from cache during save operations * See #10612 */ public function testNewObjectLoadedFromCacheDuringSaveOperations() { $object = new \ElggObject(); $object->subtype = 'elgg_entity_test_subtype'; // Add temporary metadata, annotation and private settings // to extend the scope of tests and catch issues with save operations $object->test_metadata = 'bar'; $object->annotate('test_annotation', 'baz'); $object->setPrivateSetting('test_setting', 'foo'); $metadata_called = false; $metadata_event_handler = function ($event, $type, $metadata) use(&$metadata_called) { /* @var $metadata \ElggMetadata */ $entity = get_entity($metadata->entity_guid); $this->assertEqual($metadata->entity_guid, $entity->guid); $metadata_called = true; }; $annotation_called = false; $annotation_event_handler = function ($event, $type, $annotation) use(&$annotation_called) { /* @var $metadata \ElggAnnotation */ $entity = get_entity($annotation->entity_guid); $this->assertEqual($annotation->entity_guid, $entity->guid); $annotation_called = true; }; elgg_register_event_handler('create', 'metadata', $metadata_event_handler); elgg_register_event_handler('create', 'annotation', $annotation_event_handler); $object->save(); elgg_unregister_event_handler('create', 'metadata', $metadata_event_handler); elgg_unregister_event_handler('create', 'annotation', $annotation_event_handler); $object->delete(); $this->assertTrue($metadata_called); $this->assertTrue($annotation_called); }
if (!$blog->save()) { $error = elgg_echo('blog:error:cannot_save'); } } // creat draft annotation if (!$error) { // annotations don't have a "time_updated" so // we have to delete everything or the times are wrong. // don't save if nothing changed if ($auto_save_annotations = $blog->getAnnotations('blog_auto_save', 1)) { $auto_save = $auto_save_annotations[0]; } else { $auto_save == FALSE; } if (!$auto_save) { $annotation_id = $blog->annotate('blog_auto_save', $description); } elseif ($auto_save instanceof ElggAnnotation && $auto_save->value != $description) { $blog->clearAnnotations('blog_auto_save'); $annotation_id = $blog->annotate('blog_auto_save', $description); } elseif ($auto_save instanceof ElggAnnotation && $auto_save->value == $description) { // this isn't an error because we have an up to date annotation. $annotation_id = $auto_save->id; } if (!$annotation_id) { $error = elgg_echo('blog:error:cannot_auto_save'); } } } else { $error = elgg_echo('blog:error:missing:description'); } if ($error) {
} else { if (strtotime($expiration_date) < time()) { $page->unpublished = true; } } } // save the page if ($page->save()) { //check in the page becaused the user just saved it if ($page->deleteMetadata("checkedOut")) { system_message(elgg_echo('pages:checked_in')); } else { system_message('Page could not be checked in. It is still locked for editing'); } elgg_clear_sticky_form("page"); // Now save description as an annotation $page->annotate("page", $page->description, $page->access_id); system_message(elgg_echo("pages:saved")); if ($new_page && !$page->unpublished) { add_to_river("river/object/page/create", "create", $user->getGUID(), $page->getGUID()); } elseif ($page->getOwnerGUID() != $user->getGUID()) { // not the owner edited the page, notify the owner $subject = elgg_echo("pages_tools:notify:edit:subject", array($page->title)); $msg = elgg_echo("pages_tools:notify:edit:message", array($page->title, $user->name, $page->getURL())); notify_user($page->getOwnerGUID(), $user->getGUID(), $subject, $msg); } forward($page->getURL()); } else { register_error(elgg_echo("pages:error:no_save")); forward(REFERER); }
if (sizeof($input) > 0) { foreach ($input as $name => $value) { $task->{$name} = $value; } } $list_guid = $input['list_guid']; if ($list_guid) { $task->list_guid = $list_guid; } else { $task->list_guid = 0; } $task->container_guid = $container_guid; if ($task->save()) { elgg_clear_sticky_form('task'); // Now save description as an annotation $task->annotate('task', $task->description, $task->access_id); system_message(elgg_echo('tasks:saved')); if ($new_task) { add_to_river('river/object/task/create', 'create', elgg_get_logged_in_user_guid(), $task->guid); } if ($new_task && $referer_guid && ($referer_entity = get_entity($referer_guid))) { $link = elgg_view('output/url', array('href' => $task->getURL(), 'text' => $task->title)); $annotation = create_annotation($referer_entity->guid, 'generic_comment', elgg_echo('tasks:this:referer:comment', array($link)), "", elgg_get_logged_in_user_guid(), $referer_entity->access_id); } $task_json = array(); foreach ($task->getExportableValues() as $v) { $task_json[$v] = $task->{$v}; } $task_json['list_guid'] = $task->list_guid; echo json_encode($task_json); forward($task->getURL());
/** * Add a personal watch for a user * * @param ElggObject $watch The watch entity * @param int $user_guid Should be the group owner * */ function mediawiki_set_personal_watch($watch, $user_guid) { $watch->annotate('personal', 'yes', ACCESS_PUBLIC, $user_guid); }