PFAHandler.php:

- set(): if a field is not set and there's no _missing_$field() method
  for it, take default value from $this->struct
  (side effect: this automagically fixes CLI create domain)
- store(): add a beforestore() hook that is called at the beginning of
  store()
- add empty beforestore() (will be overwritten by MailboxHandler)
- some comment updates


git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1423 a1433add-5e2c-0410-b055-b7f2511e0802
pull/2/head
Christian Boltz 12 years ago
parent a46bcc955c
commit 28f59d8305

@ -201,11 +201,19 @@ abstract class PFAHandler {
if ($this->new) {
foreach($this->struct as $key=>$row) {
if ($row['editable'] && !isset($values[$key]) ) {
# if a field is editable and not set, call $this->_missing_$fieldname()
# (if the method exists - otherwise the field won't be set, resulting in an error later)
/**
* when creating a new item:
* if a field is editable and not set,
* - if $this->_missing_$fieldname() exists, call it
* (it can set $this->RAWvalues[$fieldname] - or do nothing if it can't set a useful value)
* - otherwise use the default value from $this->struct
* (if you don't want this, create an empty _missing_$fieldname() function)
*/
$func="_missing_".$key;
if (method_exists($this, $func) ) {
$this->{$func}($key); # function can set $this->RAWvalues[$key] (or do nothing if it can't set a useful value)
$this->{$func}($key); # call _missing_$fieldname()
} else {
$this->set_default_value($key); # take default value from $this->struct
}
}
}
@ -225,6 +233,7 @@ abstract class PFAHandler {
} else { # field is editable
if (isset($values[$key])) {
if ($row['type'] != "pass" || strlen($values[$key]) > 0 || $this->new == 1) { # skip on empty (aka unchanged) password on edit
# TODO: do not skip "password2" if "password" is filled, but "password2" is empty
$valid = true; # trust input unless validator objects
# validate based on field type ($this->_inp_$type)
@ -287,6 +296,10 @@ abstract class PFAHandler {
return false;
}
if ( !$this->beforestore() ) {
return false;
}
$db_values = $this->values;
foreach(array_keys($db_values) as $key) {
@ -320,6 +333,14 @@ abstract class PFAHandler {
return $result;
}
/**
* called by $this->store() before storing the values in the database
* @return bool - if false, store() will abort
*/
protected function beforestore() {
return true; # do nothing, successfully ;-)
}
/**
* called by $this->store() after storing $this->values in the database
* can be used to update additional tables, call scripts etc.
@ -505,7 +526,6 @@ abstract class PFAHandler {
/**
* set field to default value
* typically called from _missing_$fieldname()
* @param string $field - fieldname
*/
protected function set_default_value($field) {

Loading…
Cancel
Save