public function testElggEntityDisableAndEnable() { global $CONFIG; // add annotations and metadata to check if they're disabled. $annotation_id = create_annotation($this->entity->guid, 'test_annotation_' . rand(), 'test_value_' . rand()); $metadata_id = create_metadata($this->entity->guid, 'test_metadata_' . rand(), 'test_value_' . rand()); $this->assertTrue($this->entity->disable()); // ensure disabled by comparing directly with database $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$this->entity->guid}'"); $this->assertIdentical($entity->enabled, 'no'); $annotation = get_data_row("SELECT * FROM {$CONFIG->dbprefix}annotations WHERE id = '{$annotation_id}'"); $this->assertIdentical($annotation->enabled, 'no'); $metadata = get_data_row("SELECT * FROM {$CONFIG->dbprefix}metadata WHERE id = '{$metadata_id}'"); $this->assertIdentical($metadata->enabled, 'no'); // re-enable for deletion to work $this->assertTrue($this->entity->enable()); // check enabled // check annotations and metadata enabled. $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$this->entity->guid}'"); $this->assertIdentical($entity->enabled, 'yes'); $annotation = get_data_row("SELECT * FROM {$CONFIG->dbprefix}annotations WHERE id = '{$annotation_id}'"); $this->assertIdentical($annotation->enabled, 'yes'); $metadata = get_data_row("SELECT * FROM {$CONFIG->dbprefix}metadata WHERE id = '{$metadata_id}'"); $this->assertIdentical($metadata->enabled, 'yes'); $this->assertTrue($this->entity->delete()); $this->entity = null; }
public function testPreventRelationshipOnEntityDelete() { $this->assertTrue(add_entity_relationship($this->entity1->guid, 'test_relationship', $this->entity2->guid)); $this->assertTrue(add_entity_relationship($this->entity2->guid, 'test_relationship', $this->entity1->guid)); $guid = $this->entity1->guid; elgg_register_event_handler('delete', 'relationship', 'Elgg\\Values::getFalse'); $this->assertTrue($this->entity1->delete()); elgg_unregister_event_handler('delete', 'relationship', 'Elgg\\Values::getFalse'); // relationships should still be gone as there is no entity // despite the fact we have a handler trying to prevent it $this->assertFalse(check_entity_relationship($guid, 'test_relationship', $this->entity2->guid)); $this->assertFalse(check_entity_relationship($this->entity2->guid, 'test_relationship', $guid)); }
/** * User specific override of the entity delete method. * * @return bool */ public function delete() { // Delete owned data clear_annotations_by_owner($this->guid); clear_metadata_by_owner($this->guid); // Delete entity return parent::delete(); }
/** * User specific override of the entity delete method. * * @return bool */ public function delete() { global $USERNAME_TO_GUID_MAP_CACHE; // clear cache if (isset($USERNAME_TO_GUID_MAP_CACHE[$this->username])) { unset($USERNAME_TO_GUID_MAP_CACHE[$this->username]); } clear_user_files($this); // Delete entity return parent::delete(); }
/** * Delete the site. * * @note You cannot delete the current site. * * @return bool * @throws SecurityException */ public function delete() { global $CONFIG; if ($CONFIG->site->getGUID() == $this->guid) { throw new SecurityException('SecurityException:deletedisablecurrentsite'); } return parent::delete(); }
/** * Called after each test method. */ public function tearDown() { $this->entity->delete(); remove_subtype('object', 'elgg_annotation_test'); _elgg_services()->hooks = $this->original_hooks; }
/** * User specific override of the entity delete method. * * @return bool */ public function delete() { global $USERNAME_TO_GUID_MAP_CACHE, $CODE_TO_GUID_MAP_CACHE; // clear cache if (isset($USERNAME_TO_GUID_MAP_CACHE[$this->username])) { unset($USERNAME_TO_GUID_MAP_CACHE[$this->username]); } if (isset($CODE_TO_GUID_MAP_CACHE[$this->code])) { unset($CODE_TO_GUID_MAP_CACHE[$this->code]); } // Delete owned data clear_annotations_by_owner($this->guid); clear_metadata_by_owner($this->guid); clear_user_files($this); // Delete entity return parent::delete(); }
/** * Delete the site. * * @note You cannot delete the current site. * * @return bool * @throws SecurityException */ public function delete() { global $CONFIG; if ($CONFIG->site->getGUID() == $this->guid) { throw new \SecurityException('You cannot delete the current site'); } return parent::delete(); }