aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/metadata.php17
1 files changed, 12 insertions, 5 deletions
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index 1a8c58a2e..52c01c5e8 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -150,18 +150,25 @@
}
/**
- * Removes metadata on an entity with a particular name
+ * Removes metadata on an entity with a particular name, optionally with a given value.
*
* @param int $entity_guid The entity GUID
- * @param string $name The name of the entity
+ * @param string $name The name of the metadata
+ * @param string $value The optional value of the item (useful for removing a single item in a multiple set)
* @return true|false Depending on success
*/
- function remove_metadata($entity_guid, $name) {
+ function remove_metadata($entity_guid, $name, $value = "") {
global $CONFIG;
$entity_guid = (int) $entity_guid;
- $name = sanitise_string(trim($name));
- if ($existing = get_data("SELECT * from {$CONFIG->dbprefix}metadata WHERE entity_guid = $entity_guid and name_id=" . add_metastring($name))) {
+ $name = sanitise_string($name);
+ $value = sanitise_string($value);
+
+ $query = "SELECT * from {$CONFIG->dbprefix}metadata WHERE entity_guid = $entity_guid and name_id=" . add_metastring($name);
+ if ($value!="")
+ $query .= " and value_id=" . add_metastring($value);
+
+ if ($existing = get_data($query)) {
foreach($existing as $ex)
delete_metadata($ex->id);
return true;