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();
 }
Beispiel #2
0
 function delete()
 {
     try {
         $this->startSession();
         $this->get_pad_client()->deletePad($this->getMetaData('pname'));
     } catch (Exception $e) {
         return false;
     }
     return parent::delete();
 }
Beispiel #3
0
/**
 * Condense annotation into object
 *
 * @param ElggObject $topic
 */
function groups_2011030101($topic)
{
    $annotation = $topic->getAnnotations('group_topic_post', 1);
    if (!$annotation) {
        // no text for this forum post so we delete (probably caused by #2624)
        return $topic->delete();
    }
    $topic->description = $annotation[0]->value;
    $topic->save();
    return $annotation[0]->delete();
}
Beispiel #4
0
 public function testElggUserLoad()
 {
     // new object
     $object = new ElggObject();
     $this->AssertEqual($object->getGUID(), 0);
     $guid = $object->save();
     $this->AssertNotEqual($guid, 0);
     // fail on wrong type
     $this->assertFalse(get_user($guid));
     // clean up
     $object->delete();
 }
Beispiel #5
0
 public function delete()
 {
     $result = false;
     $event = get_entity($this->event_guid);
     $result = remove_entity_relationship($this->event_guid, ZHAOHU_MANAGER_RELATION_ATTENDING, $this->user_guid);
     if (!$result) {
         elgg_log("ZHError ,coupon:delete, failed to remove_entity_relationship, coupon_id {$this->guid}", "ERROR");
         return false;
     }
     parent::delete();
     return true;
 }
Beispiel #6
0
 function delete($recursive = true)
 {
     if ($widgets = $this->getWidgets(false)) {
         foreach ($widgets as $col => $col_widgets) {
             if (!empty($col_widgets)) {
                 foreach ($col_widgets as $widget) {
                     $widget->delete();
                 }
             }
         }
     }
     return parent::delete($recursive);
 }
Beispiel #7
0
 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());
 }
Beispiel #8
0
/**
 * Condense first annotation into object
 *
 * @param ElggObject $topic
 */
function groups_2011030101($topic)
{
    // do not upgrade topics that have already been upgraded
    if ($topic->description) {
        return true;
    }
    $annotation = $topic->getAnnotations(array('annotation_name' => 'group_topic_post', 'limit' => 1));
    if (!$annotation) {
        // no text for this forum post so we delete (probably caused by #2624)
        return $topic->delete();
    }
    $topic->description = $annotation[0]->value;
    $topic->save();
    return $annotation[0]->delete();
}
 public function testDefaultOrderedById()
 {
     $ia = elgg_set_ignore_access(true);
     $obj = new ElggObject();
     $obj->owner_guid = elgg_get_site_entity()->guid;
     $obj->container_guid = elgg_get_site_entity()->guid;
     $obj->access_id = ACCESS_PUBLIC;
     $obj->save();
     $obj->test_md = [1, 2, 3];
     $time = time();
     $prefix = _elgg_services()->db->getTablePrefix();
     // reverse the times
     $mds = elgg_get_metadata(['metadata_owner_guids' => $obj->guid, 'metadata_names' => 'test_md', 'order_by' => 'n_table.id ASC']);
     foreach ($mds as $i => $md) {
         update_data("\n\t\t\t\tUPDATE {$prefix}metadata\n\t\t\t\tSET time_created = " . ($time - $i) . "\n\t\t\t\tWHERE id = {$md->id}\n\t\t\t");
     }
     // verify ID order
     $mds = elgg_get_metadata(['guid' => $obj->guid, 'metadata_names' => 'test_md']);
     $md_values = array_map(function (ElggMetadata $md) {
         return (int) $md->value;
     }, $mds);
     $this->assertEqual($md_values, [1, 2, 3]);
     // ignore access bypasses the MD cache, so we try it both ways
     elgg_set_ignore_access(false);
     _elgg_services()->metadataCache->clear($obj->guid);
     $md_values = $obj->test_md;
     $this->assertEqual($md_values, [1, 2, 3]);
     elgg_set_ignore_access(true);
     _elgg_services()->metadataCache->clear($obj->guid);
     $md_values = $obj->test_md;
     $this->assertEqual($md_values, [1, 2, 3]);
     $obj->delete();
     elgg_set_ignore_access($ia);
 }
Beispiel #10
0
 /**
  * Delete this file.
  *
  * @return bool
  */
 public function delete()
 {
     $fs = $this->getFilestore();
     $result = $fs->delete($this);
     if ($this->getGUID() && $result) {
         $result = parent::delete();
     }
     return $result;
 }
Beispiel #11
0
 /**
  * Also remove API user when deleting the object
  * 
  * @param boolean $recursive if the delete should be recursive
  * 
  * @return boolean
  * 
  * @see ElggEntity::delete()
  */
 function delete($recursive = true)
 {
     if ($keys = $this->getApiKeys()) {
         remove_api_user($this->site_guid, $keys["api_key"]);
     }
     return parent::delete($recursive);
 }
 /**
  * Called after each test method.
  */
 public function tearDown()
 {
     $this->obj1->delete();
     $this->obj2->delete();
     elgg_set_ignore_access($this->ignoreAccess);
 }
Beispiel #13
0
 public function testElggApiGettersEntityNoValueSubtypeSet()
 {
     global $CONFIG;
     // create an entity we can later delete.
     // order by time created and limit by 1 should == this entity.
     $subtype = 'subtype_' . rand();
     $e_subtype = new \ElggObject();
     $e_subtype->subtype = $subtype;
     $e_subtype->save();
     $e = new \ElggObject();
     $e->save();
     $options = array('type' => 'object', 'subtype' => ELGG_ENTITIES_NO_VALUE, 'limit' => 1, 'order_by' => 'guid desc');
     // grab ourself again to fill out attributes.
     $e = get_entity($e->getGUID());
     $entities = elgg_get_entities($options);
     $this->assertEqual(count($entities), 1);
     // this entity should NOT be the entity we just created
     // and should have no subtype
     foreach ($entities as $entity) {
         $this->assertEqual($entity->subtype_id, 0);
     }
     $e_subtype->delete();
     $e->delete();
     $q = "DELETE FROM {$CONFIG->dbprefix}entity_subtypes WHERE subtype = '{$subtype}'";
     delete_data($q);
 }
 */
$title = get_input('title');
$description = get_input('description');
$address = get_input('address');
$access = ACCESS_PRIVATE;
//this is private and only admins can see it
if ($title && $address) {
    $entity = new ElggObject();
    $entity->subtype = "reported_content";
    $entity->owner_guid = $_SESSION['user']->getGUID();
    $entity->title = $title;
    $entity->address = $address;
    $entity->description = $description;
    $entity->access_id = $access;
    if ($entity->save()) {
        if (!trigger_plugin_hook('reportedcontent:add', $reported->type, array('entity' => $reported), true)) {
            $entity->delete();
            register_error(elgg_echo('reportedcontent:failed'));
        } else {
            system_message(elgg_echo('reportedcontent:success'));
            $entity->state = "active";
        }
        forward($address);
    } else {
        register_error(elgg_echo('reportedcontent:failed'));
        forward($address);
    }
} else {
    register_error(elgg_echo('reportedcontent:failed'));
    forward($address);
}
Beispiel #15
0
 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'));
 }
Beispiel #16
0
 /**
  * Removes the thumbnail of the object prior to the deletion of the object
  *
  * @see ElggEntity::delete()
  */
 public function delete($recursive = true)
 {
     $this->removeThumbnail();
     return parent::delete($recursive);
 }
Beispiel #17
0
 public function testElggRiverDisableEnable()
 {
     $user = new \ElggUser();
     $user->save();
     $entity = new \ElggObject();
     $entity->save();
     $params = array('view' => 'river/relationship/friend/create', 'action_type' => 'create', 'subject_guid' => $user->guid, 'object_guid' => $entity->guid);
     $id = elgg_create_river_item($params);
     $river = elgg_get_river(array('ids' => array($id)));
     $this->assertIdentical($river[0]->enabled, 'yes');
     $user->disable();
     // should no longer be able to get the river
     $river = elgg_get_river(array('ids' => array($id)));
     $this->assertIdentical($river, array());
     // renabling the user should re-enable the river
     access_show_hidden_entities(true);
     $user->enable();
     access_show_hidden_entities(false);
     $river = elgg_get_river(array('ids' => array($id)));
     $this->assertIdentical($river[0]->enabled, 'yes');
     $user->delete();
     $entity->delete();
 }
Beispiel #18
0
 /**
  * Called after each test method.
  */
 public function tearDown()
 {
     $this->container->delete();
     $this->comment->delete();
 }
Beispiel #19
0
 public function testElggRecursiveDelete()
 {
     $types = array('\\ElggGroup', '\\ElggObject', '\\ElggUser', '\\ElggSite');
     $db_prefix = elgg_get_config('dbprefix');
     foreach ($types as $type) {
         $parent = new $type();
         $this->assertTrue($parent->save());
         $child = new \ElggObject();
         $child->container_guid = $parent->guid;
         $this->assertTrue($child->save());
         $grandchild = new \ElggObject();
         $grandchild->container_guid = $child->guid;
         $this->assertTrue($grandchild->save());
         $this->assertTrue($parent->delete(true));
         $q = "SELECT * FROM {$db_prefix}entities WHERE guid = {$parent->guid}";
         $r = get_data($q);
         $this->assertFalse($r);
         $q = "SELECT * FROM {$db_prefix}entities WHERE guid = {$child->guid}";
         $r = get_data($q);
         $this->assertFalse($r);
         $q = "SELECT * FROM {$db_prefix}entities WHERE guid = {$grandchild->guid}";
         $r = get_data($q);
         $this->assertFalse($r);
     }
     // object that owns itself
     // can't check container_guid because of infinite loops in can_edit_entity()
     $obj = new \ElggObject();
     $obj->save();
     $obj->owner_guid = $obj->guid;
     $obj->save();
     $q = "SELECT * FROM {$db_prefix}entities WHERE guid = {$obj->guid}";
     $r = get_data_row($q);
     $this->assertEqual($obj->guid, $r->owner_guid);
     $this->assertTrue($obj->delete(true));
     $q = "SELECT * FROM {$db_prefix}entities WHERE guid = {$obj->guid}";
     $r = get_data_row($q);
     $this->assertFalse($r);
 }
 /**
  * Make sure changes related to #5775 do not affect inverse relationship queries
  * @covers elgg_get_entities_from_relationship()
  */
 public function testElggApiGettersEntityRelationshipDistinctResultInverse()
 {
     $obj1 = new ElggObject();
     $obj1->save();
     $obj2 = new ElggObject();
     $obj2->save();
     $obj3 = new ElggObject();
     $obj3->save();
     add_entity_relationship($obj2->guid, 'test_5775_inverse', $obj1->guid);
     add_entity_relationship($obj3->guid, 'test_5775_inverse', $obj1->guid);
     $options = array('relationship' => 'test_5775_inverse', 'inverse_relationship' => true, 'count' => true);
     $count = elgg_get_entities_from_relationship($options);
     $this->assertIdentical($count, 2);
     unset($options['count']);
     $objects = elgg_get_entities_from_relationship($options);
     $this->assertTrue(is_array($objects));
     $this->assertIdentical(count($objects), 2);
     $obj1->delete();
     $obj2->delete();
     $obj3->delete();
 }
Beispiel #21
0
 /**
  * Delete album
  *
  * @return bool
  */
 public function delete()
 {
     $this->deleteImages();
     $this->deleteAlbumDir();
     return parent::delete();
 }
Beispiel #22
0
 public function testElggEntityRecursiveDisableAndEnable()
 {
     global $CONFIG;
     $obj1 = new \ElggObject();
     $obj1->container_guid = $this->entity->getGUID();
     $obj1->save();
     $obj2 = new \ElggObject();
     $obj2->container_guid = $this->entity->getGUID();
     $obj2->save();
     // disable $obj2 before disabling the container
     $this->assertTrue($obj2->disable());
     // disable entities container by $this->entity
     $this->assertTrue($this->entity->disable());
     $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$obj1->guid}'");
     $this->assertIdentical($entity->enabled, 'no');
     // enable entities that were disabled with the container (but not $obj2)
     $this->assertTrue($this->entity->enable());
     $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$obj1->guid}'");
     $this->assertIdentical($entity->enabled, 'yes');
     $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$obj2->guid}'");
     $this->assertIdentical($entity->enabled, 'no');
     // cleanup
     $this->assertTrue($obj2->enable());
     $this->assertTrue($obj2->delete());
     $this->assertTrue($obj1->delete());
 }
Beispiel #23
0
 /**
  * Delete this file.
  *
  * @return bool
  */
 public function delete()
 {
     $fs = $this->getFilestore();
     if ($fs->delete($this)) {
         return parent::delete();
     }
 }
Beispiel #24
0
 public function testElggBatchDeleteHandlesBrokenEntities()
 {
     $num_test_entities = 8;
     $guids = array();
     for ($i = $num_test_entities; $i > 0; $i--) {
         $entity = new \ElggObject();
         $entity->type = 'object';
         $entity->subtype = 'test_5357_subtype';
         $entity->access_id = ACCESS_PUBLIC;
         $entity->save();
         $guids[] = $entity->guid;
         _elgg_invalidate_cache_for_entity($entity->guid);
     }
     // break entities such that the first fetch has one incomplete
     // and the second and third fetches have only incompletes!
     $db_prefix = elgg_get_config('dbprefix');
     delete_data("\n\t\t\tDELETE FROM {$db_prefix}objects_entity\n\t\t\tWHERE guid IN ({$guids[1]}, {$guids[2]}, {$guids[3]}, {$guids[4]}, {$guids[5]})\n\t\t");
     $options = array('type' => 'object', 'subtype' => 'test_5357_subtype', 'order_by' => 'e.guid');
     $entities_visited = array();
     $batch = new \ElggBatch('elgg_get_entities', $options, null, 2, false);
     /* @var \ElggEntity[] $batch */
     foreach ($batch as $entity) {
         $entities_visited[] = $entity->guid;
         $entity->delete();
     }
     // The broken entities should not have been visited
     $this->assertEqual($entities_visited, array($guids[0], $guids[6], $guids[7]));
     // cleanup (including leftovers from previous tests)
     $entity_rows = elgg_get_entities(array_merge($options, array('callback' => '', 'limit' => false)));
     $guids = array();
     foreach ($entity_rows as $row) {
         $guids[] = $row->guid;
     }
     delete_data("DELETE FROM {$db_prefix}entities WHERE guid IN (" . implode(',', $guids) . ")");
     delete_data("DELETE FROM {$db_prefix}objects_entity WHERE guid IN (" . implode(',', $guids) . ")");
 }
Beispiel #25
0
 public function testElggUserLoad()
 {
     // new object
     $object = new ElggObject();
     $this->AssertEqual($object->getGUID(), 0);
     $guid = $object->save();
     $this->AssertNotEqual($guid, 0);
     // fail on wrong type
     try {
         $error = new ElggUserTest($guid);
         $this->assertTrue(FALSE);
     } catch (Exception $e) {
         $this->assertIsA($e, 'InvalidClassException');
         $message = sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $guid, 'ElggUser');
         $this->assertIdentical($e->getMessage(), $message);
     }
     // clean up
     $object->delete();
 }
Beispiel #26
0
 /**
  * Delete this file.
  *
  * @param bool $follow_symlinks If true, will also delete the target file if the current file is a symlink
  * @return bool
  */
 public function delete($follow_symlinks = true)
 {
     $result = $this->getFilestore()->delete($this, $follow_symlinks);
     if ($this->getGUID() && $result) {
         $result = parent::delete();
     }
     return $result;
 }
Beispiel #27
0
 public function test_elgg_metadata_multiple_values()
 {
     $u1 = new ElggUser();
     $u1->username = rand();
     $u1->save();
     $u2 = new ElggUser();
     $u2->username = rand();
     $u2->save();
     $obj = new ElggObject();
     $obj->owner_guid = $u1->guid;
     $obj->container_guid = $u1->guid;
     $obj->access_id = ACCESS_PUBLIC;
     $obj->save();
     $md_values = array('one', 'two', 'three');
     // need to fake different logins.
     // good times without mocking.
     $original_user = elgg_get_logged_in_user_entity();
     $_SESSION['user'] = $u1;
     elgg_set_ignore_access(false);
     // add metadata as one user
     $obj->test = $md_values;
     // check only these md exists
     $db_prefix = elgg_get_config('dbprefix');
     $q = "SELECT * FROM {$db_prefix}metadata WHERE entity_guid = {$obj->guid}";
     $data = get_data($q);
     $this->assertEqual(count($md_values), count($data));
     foreach ($data as $md_row) {
         $md = elgg_get_metadata_from_id($md_row->id);
         $this->assertTrue(in_array($md->value, $md_values));
         $this->assertEqual('test', $md->name);
     }
     // add md w/ same name as a different user
     $_SESSION['user'] = $u2;
     $md_values2 = array('four', 'five', 'six', 'seven');
     $obj->test = $md_values2;
     $q = "SELECT * FROM {$db_prefix}metadata WHERE entity_guid = {$obj->guid}";
     $data = get_data($q);
     $this->assertEqual(count($md_values2), count($data));
     foreach ($data as $md_row) {
         $md = elgg_get_metadata_from_id($md_row->id);
         $this->assertTrue(in_array($md->value, $md_values2));
         $this->assertEqual('test', $md->name);
     }
     $_SESSION['user'] = $original_user;
     $obj->delete();
     $u1->delete();
     $u2->delete();
 }
 function testElggApiGettersEntityMetadataValueInvalidMultiple()
 {
     $subtypes = $this->getRandomValidSubtypes(array('object'), 1);
     $subtype = $subtypes[0];
     $md_name = 'test_metadata_name_' . rand();
     $md_value = 'test_metadata_value_' . rand();
     $e = new \ElggObject();
     $e->subtype = $subtype;
     $e->{$md_name} = $md_value;
     $e->save();
     $md_invalid_values = array();
     $md_invalid_values[] = 'test_metadata_value_' . rand();
     $md_invalid_values[] = 'test_metadata_value_' . rand();
     $options = array('type' => 'object', 'subtype' => $subtype, 'metadata_values' => $md_invalid_values);
     $entities = elgg_get_entities_from_metadata($options);
     $this->assertIdentical(array(), $entities);
     $e->delete();
 }
 function test_can_write_to_container()
 {
     $user = new \ElggUser();
     $user->username = '******' . rand();
     $user->name = 'test_user_name_' . rand();
     $user->email = '*****@*****.**';
     $user->container_guid = 0;
     $user->owner_guid = 0;
     $user->save();
     $object = new \ElggObject();
     $object->save();
     $group = new \ElggGroup();
     $group->save();
     // disable access overrides because we're admin.
     $ia = elgg_set_ignore_access(false);
     $this->assertFalse(can_write_to_container($user->guid, $object->guid));
     global $elgg_test_user;
     $elgg_test_user = $user;
     // register hook to allow access
     function can_write_to_container_test_hook($hook, $type, $value, $params)
     {
         global $elgg_test_user;
         if ($params['user']->getGUID() == $elgg_test_user->getGUID()) {
             return true;
         }
     }
     elgg_register_plugin_hook_handler('container_permissions_check', 'all', 'can_write_to_container_test_hook');
     $this->assertTrue(can_write_to_container($user->guid, $object->guid));
     elgg_unregister_plugin_hook_handler('container_permissions_check', 'all', 'can_write_to_container_test_hook');
     $this->assertFalse(can_write_to_container($user->guid, $group->guid));
     $group->join($user);
     $this->assertTrue(can_write_to_container($user->guid, $group->guid));
     elgg_set_ignore_access($ia);
     $user->delete();
     $object->delete();
     $group->delete();
 }
Beispiel #30
0
 /**
  * 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);
 }