lib/api lib/kolab_api_service.php
Aleksander Machniak
machniak at kolabsys.com
Thu Sep 19 14:09:16 CEST 2013
lib/api/kolab_api_service_form_value.php | 40 +++++--------------------------
lib/kolab_api_service.php | 2 -
2 files changed, 8 insertions(+), 34 deletions(-)
New commits:
commit f5588098f49999de2468c9dea9b0999dd19f17a5
Author: Aleksander Machniak <alec at alec.pl>
Date: Thu Sep 19 14:07:36 2013 +0200
Change so invalid value of optional form field throws exception (error
to the user is displayed) (Bug #2045). Some CS fixes/improvements.
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 1b66760..ce72173 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -223,28 +223,14 @@ class kolab_api_service_form_value extends kolab_api_service
}
}
- if (array_key_exists($attr_name, (array) $attribs['form_fields'])) {
- if (empty($attribs['form_fields'][$attr_name]['optional'])) {
- $attribs['form_fields'][$attr_name]['optional'] = false;
- }
+ if ($attribs['form_fields'][$attr_name]['validate'] === false) {
+ $result[$attr_name] = $attr_value;
}
-
- if (array_key_exists($attr_name, (array) $attribs['form_fields'])) {
- if (empty($attribs['form_fields'][$attr_name]['validate'])) {
- $attribs['form_fields'][$attr_name]['validate'] = true;
- }
+ else if ($attribs['form_fields'][$attr_name]['optional'] && $attr_value === '') {
+ $result[$attr_name] = $attr_value;
}
-
- if ($attribs['form_fields'][$attr_name]['optional'] && !($attribs['form_fields'][$attr_name]['validate'])) {
+ else {
$result[$attr_name] = $this->{$method_name}($attr_value, $postdata);
- } else if (!($attribs['form_fields'][$attr_name]['validate'])) {
- $result[$attr_name] = $attr_value;
- } else {
- try {
- $result[$attr_name] = $this->{$method_name}($attr_value, $postdata);
- } catch (Exception $e) {
- Log::debug("Attribute $attr_name did not validate, but it is not a required attribute. Not saving. (Error was: $e)");
- }
}
}
@@ -526,7 +512,7 @@ class kolab_api_service_form_value extends kolab_api_service
$postdata['gidnumber'] = $gidnumber;
if (empty($postdata['uidnumber'])) {
$uidnumber = $this->generate_uidnumber($postdata, $attribs);
- $gidnumber = $this->_highest_of_two($uidnumber, $gidnumber);
+ $gidnumber = max($uidnumber, $gidnumber);
}
return $gidnumber;
@@ -885,7 +871,7 @@ class kolab_api_service_form_value extends kolab_api_service
$postdata['uidnumber'] = $uidnumber;
if (empty($postdata['gidnumber'])) {
$gidnumber = $this->generate_gidnumber($postdata, $attribs);
- $uidnumber = $this->_highest_of_two($uidnumber, $gidnumber);
+ $uidnumber = max($uidnumber, $gidnumber);
}
return $uidnumber;
@@ -1131,7 +1117,6 @@ class kolab_api_service_form_value extends kolab_api_service
//console("form_value.validate_associateddomain(\$value)", $value);
return $value;
-
}
private function validate_astaccountrealmedpassword($value, $postdata)
@@ -1211,17 +1196,6 @@ class kolab_api_service_form_value extends kolab_api_service
}
}
- private function _highest_of_two($one, $two)
- {
- if ($one > $two) {
- return $one;
- } elseif ($one == $two) {
- return $one;
- } else {
- return $two;
- }
- }
-
private function _list_options_members($postdata, $attribs = array())
{
// return specified records only, by exact DN attributes
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index 5ba4109..8294dcd 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -304,7 +304,7 @@ abstract class kolab_api_service
throw new Exception("Missing input value for $key", 345);
}
else {
- Log::trace("Either \$attribs['" . $key . "'] is empty or the field is optional");
+ Log::trace("Either \$attribs['" . $key . "'] is not empty or the field is optional");
$result[$key] = $attribs[$key];
}
}
More information about the commits
mailing list