From e1eedeae6a43a5f040402a4ba2c09146877a2672 Mon Sep 17 00:00:00 2001 From: Jeroen Dalsem Date: Thu, 13 Sep 2012 11:13:08 +0200 Subject: fixes saving of empty values on profile metadata #4858 --- actions/profile/edit.php | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/actions/profile/edit.php b/actions/profile/edit.php index 8ca60f246..0456c60bc 100644 --- a/actions/profile/edit.php +++ b/actions/profile/edit.php @@ -51,7 +51,7 @@ foreach ($profile_fields as $shortname => $valuetype) { if ($valuetype == 'tags') { $value = string_to_tag_array($value); } - + $input[$shortname] = $value; } @@ -74,21 +74,26 @@ if (sizeof($input) > 0) { 'metadata_name' => $shortname ); elgg_delete_metadata($options); - if (isset($accesslevel[$shortname])) { - $access_id = (int) $accesslevel[$shortname]; - } else { - // this should never be executed since the access level should always be set - $access_id = ACCESS_DEFAULT; - } - if (is_array($value)) { - $i = 0; - foreach ($value as $interval) { - $i++; - $multiple = ($i > 1) ? TRUE : FALSE; - create_metadata($owner->guid, $shortname, $interval, 'text', $owner->guid, $access_id, $multiple); + + if(!is_null($value) && ($value !== '')){ + // only create metadata for non empty values (0 is allowed) to prevent metadata records with empty string values #4858 + + if (isset($accesslevel[$shortname])) { + $access_id = (int) $accesslevel[$shortname]; + } else { + // this should never be executed since the access level should always be set + $access_id = ACCESS_DEFAULT; + } + if (is_array($value)) { + $i = 0; + foreach ($value as $interval) { + $i++; + $multiple = ($i > 1) ? TRUE : FALSE; + create_metadata($owner->guid, $shortname, $interval, 'text', $owner->guid, $access_id, $multiple); + } + } else { + create_metadata($owner->getGUID(), $shortname, $value, 'text', $owner->getGUID(), $access_id); } - } else { - create_metadata($owner->getGUID(), $shortname, $value, 'text', $owner->getGUID(), $access_id); } } -- cgit v1.2.3 From 2a01ffb27c6509f4b9e32675cf4386d3aae1c713 Mon Sep 17 00:00:00 2001 From: Jeroen Dalsem Date: Thu, 13 Sep 2012 11:16:23 +0200 Subject: fixes not showing and deleting all metadata values for array type metadata fields #4858 --- actions/profile/edit.php | 3 ++- views/default/forms/profile/edit.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/actions/profile/edit.php b/actions/profile/edit.php index 0456c60bc..b6d73ff2d 100644 --- a/actions/profile/edit.php +++ b/actions/profile/edit.php @@ -71,7 +71,8 @@ if (sizeof($input) > 0) { foreach ($input as $shortname => $value) { $options = array( 'guid' => $owner->guid, - 'metadata_name' => $shortname + 'metadata_name' => $shortname, + 'limit' => false ); elgg_delete_metadata($options); diff --git a/views/default/forms/profile/edit.php b/views/default/forms/profile/edit.php index 222935344..9538b779e 100644 --- a/views/default/forms/profile/edit.php +++ b/views/default/forms/profile/edit.php @@ -18,7 +18,8 @@ if (is_array($profile_fields) && count($profile_fields) > 0) { foreach ($profile_fields as $shortname => $valtype) { $metadata = elgg_get_metadata(array( 'guid' => $vars['entity']->guid, - 'metadata_name' => $shortname + 'metadata_name' => $shortname, + 'limit' => false )); if ($metadata) { if (is_array($metadata)) { -- cgit v1.2.3