]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
fixes saving of empty values on profile metadata #4858
authorJeroen Dalsem <jdalsem@coldtrick.com>
Thu, 13 Sep 2012 09:13:08 +0000 (11:13 +0200)
committerJeroen Dalsem <jdalsem@coldtrick.com>
Thu, 13 Sep 2012 09:13:08 +0000 (11:13 +0200)
actions/profile/edit.php

index 8ca60f246356564d727c47adb2ee8eea213c44c6..0456c60bc5fa1ba74dbb40a917492836e1b211c0 100644 (file)
@@ -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);
                }
        }