aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/metadata.php
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-08-22 16:22:19 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-08-22 16:22:19 +0000
commit613748b75a9cd1f1b1939ab05c22e63407237984 (patch)
tree6378a1ee590a0798afea7a0a2627289711a03360 /engine/lib/metadata.php
parent8a73785aee3e51c26c65053a4de7c5d7f0ebb673 (diff)
downloadelgg-613748b75a9cd1f1b1939ab05c22e63407237984.tar.gz
elgg-613748b75a9cd1f1b1939ab05c22e63407237984.tar.bz2
Merged [6600],[6601],[6605],[6606],[6607],[6608],[6611] from 1.7 branch into trunk
git-svn-id: http://code.elgg.org/elgg/trunk@6843 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/metadata.php')
-rw-r--r--engine/lib/metadata.php22
1 files changed, 11 insertions, 11 deletions
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index 6e849cdd9..3ad774ad2 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -190,12 +190,13 @@ function remove_metadata($entity_guid, $name, $value = "") {
* @param int $owner_guid GUID of entity that owns the metadata
* @param int $access_id Default is ACCESS_PRIVATE
* @param bool $allow_multiple Allow multiple values for one key. Default is FALSE
- * @return bool
+ * @return int/bool id of metadata or FALSE if failure
*/
function create_metadata($entity_guid, $name, $value, $value_type, $owner_guid, $access_id = ACCESS_PRIVATE, $allow_multiple = false) {
global $CONFIG;
$entity_guid = (int)$entity_guid;
+ // name and value are encoded in add_metastring()
//$name = sanitise_string(trim($name));
//$value = sanitise_string(trim($value));
$value_type = detect_extender_valuetype($value, sanitise_string(trim($value_type)));
@@ -203,6 +204,10 @@ function create_metadata($entity_guid, $name, $value, $value_type, $owner_guid,
$owner_guid = (int)$owner_guid;
$allow_multiple = (boolean)$allow_multiple;
+ if (!isset($value)) {
+ return FALSE;
+ }
+
if ($owner_guid==0) {
$owner_guid = get_loggedin_userid();
}
@@ -212,14 +217,14 @@ function create_metadata($entity_guid, $name, $value, $value_type, $owner_guid,
$id = false;
$existing = get_data_row("SELECT * from {$CONFIG->dbprefix}metadata WHERE entity_guid = $entity_guid and name_id=" . add_metastring($name) . " limit 1");
- if (($existing) && (!$allow_multiple) && (isset($value))) {
- $id = $existing->id;
+ if ($existing && !$allow_multiple) {
+ $id = (int)$existing->id;
$result = update_metadata($id, $name, $value, $value_type, $owner_guid, $access_id);
if (!$result) {
return false;
}
- } else if (isset($value)) {
+ } else {
// Support boolean types
if (is_bool($value)) {
if ($value) {
@@ -243,19 +248,14 @@ function create_metadata($entity_guid, $name, $value, $value_type, $owner_guid,
// If ok then add it
$id = insert_data("INSERT into {$CONFIG->dbprefix}metadata (entity_guid, name_id, value_id, value_type, owner_guid, time_created, access_id) VALUES ($entity_guid, '$name','$value','$value_type', $owner_guid, $time, $access_id)");
- if ($id!==false) {
+ if ($id !== false) {
$obj = get_metadata($id);
if (trigger_elgg_event('create', 'metadata', $obj)) {
- return true;
+ return $id;
} else {
delete_metadata($id);
}
}
-
- } else if ($existing) {
- // TODO: Check... are you sure you meant to do this Ben? :)
- $id = $existing->id;
- delete_metadata($id);
}
return $id;