aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/entities.php5
-rw-r--r--engine/lib/export.php4
-rw-r--r--engine/lib/input.php5
-rw-r--r--engine/lib/metadata.php22
-rw-r--r--engine/tests/objects/metadata.php1
5 files changed, 19 insertions, 18 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 0f718d162..c34aea550 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -334,7 +334,8 @@ abstract class ElggEntity implements
} else {
unset($this->temp_metadata[$name]);
if ((int) $this->guid > 0) {
- return create_metadata($this->getGUID(), $name, $value, $value_type, $this->getOwner(), $this->getAccessID(), $multiple);
+ $result = create_metadata($this->getGUID(), $name, $value, $value_type, $this->getOwner(), $this->getAccessID(), $multiple);
+ return (bool)$result;
} else {
if (($multiple) && (isset($this->temp_metadata[$name]))) {
if (!is_array($this->temp_metadata[$name])) {
@@ -2511,7 +2512,7 @@ function disable_entity($guid, $reason = "", $recursive = true) {
if (trigger_elgg_event('disable',$entity->type,$entity)) {
if ($entity->canEdit()) {
if ($reason) {
- create_metadata($guid, 'disable_reason', $reason,'', 0, ACCESS_PUBLIC);
+ create_metadata($guid, 'disable_reason', $reason, '', 0, ACCESS_PUBLIC);
}
if ($recursive) {
diff --git a/engine/lib/export.php b/engine/lib/export.php
index c541b583b..1b09016b0 100644
--- a/engine/lib/export.php
+++ b/engine/lib/export.php
@@ -135,12 +135,14 @@ function get_entity_from_uuid($uuid) {
*
* @param int $guid
* @param string $uuid
+ * @return bool
*/
function add_uuid_to_guid($guid, $uuid) {
$guid = (int)$guid;
$uuid = sanitise_string($uuid);
- return create_metadata($guid, "import_uuid", $uuid);
+ $result = create_metadata($guid, "import_uuid", $uuid);
+ return (bool)$result;
}
diff --git a/engine/lib/input.php b/engine/lib/input.php
index 2ddc0e643..7e650c8de 100644
--- a/engine/lib/input.php
+++ b/engine/lib/input.php
@@ -65,10 +65,7 @@ function set_input($variable, $value) {
}
if (is_array($value)) {
- foreach ($value as $key => $val) {
- $value[$key] = trim($val);
- }
-
+ array_walk_recursive($value, create_function('&$v, $k', '$v = trim($v);'));
$CONFIG->input[trim($variable)] = $value;
} else {
$CONFIG->input[trim($variable)] = trim($value);
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;
diff --git a/engine/tests/objects/metadata.php b/engine/tests/objects/metadata.php
index bc6523279..3595331e4 100644
--- a/engine/tests/objects/metadata.php
+++ b/engine/tests/objects/metadata.php
@@ -59,6 +59,7 @@ class ElggCoreMetadataTest extends ElggCoreUnitTest {
$this->create_metastring('metaUnitTest');
$this->create_metastring('tested');
+ // create_metadata returns id of metadata on success
$this->assertTrue(create_metadata($this->object->guid, 'metaUnitTest', 'tested'));
// check value with improper case