summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-09-19 14:07:36 +0200
committerAleksander Machniak <alec@alec.pl>2013-09-19 14:07:36 +0200
commitf5588098f49999de2468c9dea9b0999dd19f17a5 (patch)
treeb0b7b2991b8a000017f39c7f933ff156382c356f /lib
parente467788e6ee6b0f12ccd65dd0b419ebb18d80d60 (diff)
downloadwebadmin-f5588098f49999de2468c9dea9b0999dd19f17a5.tar.gz
Change so invalid value of optional form field throws exception (error
to the user is displayed) (Bug #2045). Some CS fixes/improvements.
Diffstat (limited to 'lib')
-rw-r--r--lib/api/kolab_api_service_form_value.php40
-rw-r--r--lib/kolab_api_service.php2
2 files changed, 8 insertions, 34 deletions
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];
}
}