aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/lib/metadata.php15
-rw-r--r--engine/tests/objects/entities.php23
2 files changed, 34 insertions, 4 deletions
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index ffa7b74e0..8b6fe364f 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -60,12 +60,19 @@ function remove_metadata($entity_guid, $name, $value = "") {
$entity_guid = (int) $entity_guid;
$name = sanitise_string($name);
$value = sanitise_string($value);
+
+ $name = get_metastring_id($name);
+ if ($name === FALSE) {
+ // name doesn't exist
+ return FALSE;
+ }
- $query = "SELECT * from {$CONFIG->dbprefix}metadata"
- . " WHERE entity_guid = $entity_guid and name_id=" . add_metastring($name);
-
+ $query = "SELECT * from {$CONFIG->dbprefix}metadata WHERE entity_guid = '$entity_guid' and name_id = '$name'";
if ($value != "") {
- $query .= " and value_id=" . add_metastring($value);
+ $value = get_metastring_id($value);
+ if ($value !== FALSE) {
+ $query .= " AND value_id = '$value'";
+ }
}
if ($existing = get_data($query)) {
diff --git a/engine/tests/objects/entities.php b/engine/tests/objects/entities.php
index 018f7aa02..1f1f6d2b4 100644
--- a/engine/tests/objects/entities.php
+++ b/engine/tests/objects/entities.php
@@ -205,6 +205,29 @@ class ElggCoreEntityTest extends ElggCoreUnitTest {
$this->assertTrue($this->entity->enable());
$this->assertTrue($this->entity->delete());
}
+
+ public function testElggEntityMetadata() {
+ // let's delte a non-existent metadata
+ $this->assertFalse($this->entity->clearMetaData('important'));
+
+ // let's add the meatadata
+ $this->assertTrue($this->entity->important = 'indeed!');
+ $this->assertTrue($this->entity->less_important = 'true, too!');
+ $this->save_entity();
+
+ // test deleting incorrectly: Ticket #2273
+ $this->assertFalse($this->entity->clearMetaData('impotent'));
+ $this->assertEqual($this->entity->important, 'indeed!');
+
+ // get rid of one metadata
+ $this->assertEqual($this->entity->important, 'indeed!');
+ $this->assertTrue($this->entity->clearMetaData('important'));
+ $this->assertEqual($this->entity->important, '');
+
+ // get rid of all metadata
+ $this->assertTrue($this->entity->clearMetaData());
+ $this->assertEqual($this->entity->less_important, '');
+ }
public function testElggEntityExportables() {
$exportables = array(