aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-06 13:15:58 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-06 13:15:58 +0000
commitffcb48e2841918ab8e3619e44bf6d68367da2e8a (patch)
tree2285dc50ce169a9371d5775eb17181f0d38d1a36 /engine
parentc508adaa1531e1d99b7708605f2fa158ea39b2bc (diff)
downloadelgg-ffcb48e2841918ab8e3619e44bf6d68367da2e8a.tar.gz
elgg-ffcb48e2841918ab8e3619e44bf6d68367da2e8a.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* Metadata creates and updates git-svn-id: https://code.elgg.org/elgg/trunk@96 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/metadata.php23
1 files changed, 12 insertions, 11 deletions
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index 3a326ac56..19c2e2298 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -144,25 +144,26 @@
$name = sanitise_string(trim($name));
$value = sanitise_string(trim($value));
$value_type = detect_metadata_valuetype(sanitise_string(trim($value_type)));
+ $time = time();
$owner_id = (int)$owner_id;
if ($owner_id==0) $owner_id = $_SESSION['id'];
$access_id = (int)$access_id;
+
+ $id = false;
- $id = insert_data("INSERT into {$CONFIG->dbprefix}metadata (object_id, object_type, name, value, value_type, owner_id, created, access_id) VALUES ($object_id,'$object_type','$name','$value','$value_type', $owner_id, $access_id)");
-
- if (!$id)
+ $existing = get_data_row("SELECT * from {$CONFIG->dbprefix}metadata WHERE object_id = $object_id and object_type='$object_type' and name='$name' limit 1");
+ if ($existing)
{
- $existing = get_data_row("SELECT * from {$CONFIG->dbprefix}metadata WHERE object_id = $object_id and object_type='$object_type' and name='$name' limit 1");
- if ($existing)
- {
- $id = $existing->id;
- $result = update_metadata($id,$name, $value, $value_type, $owner_id, $access_id);
-
- if (!$result) return false;
- }
+ $id = $existing->id;
+ $result = update_metadata($id,$name, $value, $value_type, $owner_id, $access_id);
+ if (!$result) return false;
+ }
+ else
+ {
+ $id = insert_data("INSERT into {$CONFIG->dbprefix}metadata (object_id, object_type, name, value, value_type, owner_id, created, access_id) VALUES ($object_id,'$object_type','$name','$value','$value_type', $owner_id, $time, $access_id)");
}
return $id;