aboutsummaryrefslogtreecommitdiff
path: root/engine
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
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')
-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