From 963566759763b77996d12741327cd1ab1981c131 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Tue, 7 Apr 2009 07:37:36 +0200 Subject: [PATCH] Fixed splitting multivalue fields. Corrected handling locked fields. --- .../Kolab_Server/lib/Horde/Kolab/Server/Object.php | 41 +++++++++++++++------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php index 5c71aaaaf..6e36cf85e 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php @@ -302,7 +302,7 @@ class Horde_Kolab_Server_Object } } - if (!empty($this->attribute_map['derived']) + if (!empty($this->attribute_map['derived']) && in_array($attr, $this->attribute_map['derived'])) { return $this->derive($attr); } @@ -371,7 +371,11 @@ class Horde_Kolab_Server_Object if (empty($base)) { return; } - $fields = explode($separator, $base, $max_count); + if (!empty($max_count)) { + $fields = explode($separator, $base, $max_count); + } else { + $fields = explode($separator, $base); + } return isset($fields[$this->attributes[$attr]['order']]) ? $fields[$this->attributes[$attr]['order']] : null; } @@ -529,7 +533,7 @@ class Horde_Kolab_Server_Object $collapse = array(); foreach ($this->attribute_map['derived'] as $key) { $attribute = $this->attributes[$key]; - if (isset($attribute['base']) + if (empty($attribute['readonly']) && isset($attribute['base']) && isset($attribute['order'])) { $collapse[$attribute['base']][$attribute['order']] = $key; } @@ -541,7 +545,7 @@ class Horde_Kolab_Server_Object if (!$this->exists()) { foreach ($this->attribute_map['required'] as $key) { - if (!in_array($key, array_keys($info)) || empty($info[$key])) { + if (!in_array($key, array_keys($info)) || $info[$key] === null) { if (empty($this->attributes[$key]['default'])) { throw new Horde_Kolab_Server_Exception(sprintf(_("The value for \"%s\" is empty but required!"), $key)); @@ -553,22 +557,23 @@ class Horde_Kolab_Server_Object $submitted = $info; foreach ($submitted as $key => $value) { - if (empty($value)) { + if ($value === null) { unset($info[$key]); } } } else { - foreach ($info as $key => $value) { - if (in_array($key, $this->attribute_map['locked'])) { - throw new Horde_Kolab_Server_Exception(sprintf(_("The value for \"%s\" may not be modified on an existing object!"), - $key)); - } - } - $old_keys = array_keys($this->_cache); $submitted = $info; foreach ($submitted as $key => $value) { - if (empty($value) && !isset($this->_cache[$key])) { + /** + * Empty values are ignored in case there is also no old value + * stored or the value is locked. If there is an old value we + * must assume the value was removed. + */ + if ($value === null + && (!isset($this->_cache[$key]) + || in_array($key, $this->attribute_map['locked']))) { + unset($info[$key]); continue; } @@ -595,6 +600,16 @@ class Horde_Kolab_Server_Object } } } + + /** + * This ensures that we did not change anything that is locked after creating the element. + */ + foreach ($info as $key => $value) { + if (in_array($key, $this->attribute_map['locked'])) { + throw new Horde_Kolab_Server_Exception(sprintf(_("The value for \"%s\" may not be modified on an existing object!"), + $key)); + } + } } $result = $this->server->save($this->uid, $info, $this->exists()); -- 2.11.0