aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/classes/ElggEntity.php119
-rw-r--r--engine/lib/entities.php32
-rw-r--r--engine/tests/objects/entities.php25
3 files changed, 146 insertions, 30 deletions
diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php
index 4e1bc586c..37422d702 100644
--- a/engine/classes/ElggEntity.php
+++ b/engine/classes/ElggEntity.php
@@ -271,7 +271,7 @@ abstract class ElggEntity extends ElggData implements
if (array_key_exists($name, $this->attributes)) {
$this->attributes[$name] = "";
} else {
- $this->clearMetaData($name);
+ $this->deleteMetadata($name);
}
}
@@ -341,20 +341,78 @@ abstract class ElggEntity extends ElggData implements
}
/**
+ * Deletes all metadata on this object. If you pass a name, only
+ * metadata matching that name will be deleted.
+ *
+ * @warning Calling this with no or empty arguments will clear all metadata on the entity.
+ *
+ * @param string $name The metadata name to remove.
+ * @return bool
+ * @since 1.8
+ */
+ public function deleteMetadata($name = null) {
+ $options = array(
+ 'guid' => $this->guid,
+ 'limit' => 0
+ );
+ if ($name) {
+ $options['metadata_name'] = $name;
+ }
+
+ return elgg_delete_metadata($options);
+ }
+
+ /**
* Remove metadata
*
* @warning Calling this with no or empty arguments will clear all metadata on the entity.
*
* @param string $name The name of the metadata to clear
- *
* @return mixed bool
+ * @deprecated 1.8 Use deleteMetadata()
*/
public function clearMetaData($name = '') {
- if (empty($name)) {
- return clear_metadata($this->getGUID());
- } else {
- return remove_metadata($this->getGUID(), $name);
+ return $this->deleteMetadata($name);
+ }
+
+ /**
+ * Disables metadata for this entity, optionally based on name.
+ *
+ * @param string $name An options name of metadata to disable.
+ * @return bool
+ * @since 1.8
+ */
+ public function disableMetadata($name = '') {
+ $options = array(
+ 'guid' => $this->guid,
+ 'limit' => 0
+ );
+ if ($name) {
+ $options['metadata_name'] = $name;
+ }
+
+ return elgg_disable_metadata($options);
+ }
+
+ /**
+ * Enables metadata for this entity, optionally based on name.
+ *
+ * @warning Before calling this, you must use {@link access_show_hidden_entities()}
+ *
+ * @param string $name An options name of metadata to enable.
+ * @return bool
+ * @since 1.8
+ */
+ public function enableMetadata($name = '') {
+ $options = array(
+ 'guid' => $this->guid,
+ 'limit' => 0
+ );
+ if ($name) {
+ $options['metadata_name'] = $name;
}
+
+ return elgg_enable_metadata($options);
}
/**
@@ -376,7 +434,6 @@ abstract class ElggEntity extends ElggData implements
}
}
-
/**
* Set a piece of volatile (non-persisted) data on this entity
*
@@ -393,7 +450,6 @@ abstract class ElggEntity extends ElggData implements
$this->volatile[$name] = $value;
}
-
/**
* Remove all relationships to and from this entity.
*
@@ -489,10 +545,51 @@ abstract class ElggEntity extends ElggData implements
}
/**
+ * Disables annotations for this entity, optionally based on name.
+ *
+ * @param string $name An options name of annotations to disable.
+ * @return bool
+ * @since 1.8
+ */
+ public function disableAnnotations($name = '') {
+ $options = array(
+ 'guid' => $this->guid,
+ 'limit' => 0
+ );
+ if ($name) {
+ $options['annotations_name'] = $name;
+ }
+
+ return elgg_disable_annotations($options);
+ }
+
+ /**
+ * Enables annotations for this entity, optionally based on name.
+ *
+ * @warning Before calling this, you must use {@link access_show_hidden_entities()}
+ *
+ * @param string $name An options name of annotations to enable.
+ * @return bool
+ * @since 1.8
+ */
+ public function enableAnnotations($name = '') {
+ $options = array(
+ 'guid' => $this->guid,
+ 'limit' => 0
+ );
+ if ($name) {
+ $options['annotations_name'] = $name;
+ }
+
+ return elgg_enable_annotations($options);
+ }
+
+ /**
* Helper function to return annotation calculation results
*
* @param string $name The annotation name.
* @param string $calculation A valid MySQL function to run its values through
+ * @return mixed
*/
private function getAnnotationCalculation($name, $calculation) {
$options = array(
@@ -726,9 +823,9 @@ abstract class ElggEntity extends ElggData implements
/**
* Can a user write to this entity
*
- * @param int $user_guid The user.
- * @param string $type The type of entity we're looking to write
- * @param string $subtype The subtype of the entity we're looking to write
+ * @param int $user_guid The user.
+ * @param string $type The type of entity we're looking to write
+ * @param string $subtype The subtype of the entity we're looking to write
*
* @return bool
*/
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 4f58e96a8..af0092ca1 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -1153,8 +1153,8 @@ $time_created_lower = NULL, $time_updated_upper = NULL, $time_updated_lower = NU
* pagination => BOOL Display pagination links
* gallery => BOOL display in gallery view
*
- * @param mixed $getter The entity getter function to use to fetch the entities
- * @param mixed $viewer The function to use to view the entity list.
+ * @param mixed $getter The entity getter function to use to fetch the entities
+ * @param mixed $viewer The function to use to view the entity list.
*
* @return string
* @since 1.7
@@ -1345,20 +1345,14 @@ function disable_entity($guid, $reason = "", $recursive = true) {
}
}
- // disable annotations
- // Now delete the entity itself
-// $entity->clearMetadata();
-// $entity->clearAnnotations();
-// $entity->clearRelationships();
-//
-// $res = delete_data("DELETE from {$CONFIG->dbprefix}entities where guid={$guid}");
-// if ($res) {
-// $sub_table = "";
-// }
-
$__RECURSIVE_DELETE_TOKEN = null;
}
+ $entity->disableMetadata();
+ $entity->disableAnnotations();
+ // relationships can't be disabled. hope they join to the entities table.
+ //$entity->disableRelationships();
+
$res = update_data("UPDATE {$CONFIG->dbprefix}entities
set enabled='no'
where guid={$guid}");
@@ -1398,7 +1392,10 @@ function enable_entity($guid) {
$result = update_data("UPDATE {$CONFIG->dbprefix}entities
set enabled='yes'
where guid={$guid}");
- $entity->clearMetaData('disable_reason');
+
+ $entity->deleteMetadata('disable_reason');
+ $entity->enableMetadata();
+ $entity->enableAnnotations();
return $result;
}
@@ -1830,9 +1827,9 @@ function get_entity_url($entity_guid) {
/**
* Sets the URL handler for a particular entity type and subtype
*
- * @param string $function_name The function to register
* @param string $entity_type The entity type
* @param string $entity_subtype The entity subtype
+ * @param string $function_name The function to register
*
* @return true|false Depending on success
* @see get_entity_url()
@@ -1840,7 +1837,6 @@ function get_entity_url($entity_guid) {
* @since 1.8.0
*/
function elgg_register_entity_url_handler($entity_type, $entity_subtype, $function_name) {
-
global $CONFIG;
if (!is_callable($function_name)) {
@@ -1876,7 +1872,7 @@ function elgg_register_entity_url_handler($entity_type, $entity_subtype, $functi
* @link http://docs.elgg.org/Search
* @link http://docs.elgg.org/Tutorials/Search
*/
-function register_entity_type($type, $subtype=null) {
+function register_entity_type($type, $subtype = null) {
global $CONFIG;
$type = strtolower($type);
@@ -1977,7 +1973,7 @@ function get_registered_entity_types($type = null) {
*
* @return true|false Depending on whether or not the type has been registered
*/
-function is_registered_entity_type($type, $subtype=null) {
+function is_registered_entity_type($type, $subtype = null) {
global $CONFIG;
if (!isset($CONFIG->registered_entities)) {
diff --git a/engine/tests/objects/entities.php b/engine/tests/objects/entities.php
index 67dd02596..824b47a8a 100644
--- a/engine/tests/objects/entities.php
+++ b/engine/tests/objects/entities.php
@@ -186,19 +186,42 @@ class ElggCoreEntityTest extends ElggCoreUnitTest {
// ensure enabled
$this->assertTrue($this->entity->isEnabled());
- // false on disable
+ // false on disable because it's not saved yet.
$this->assertFalse($this->entity->disable());
// save and disable
$this->save_entity();
+
+ // 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());
}