PFAHandler.php:

- initStruct(): add some comments
- add calledBy() and protected $called_by - calledBy() should be called if one 
  *Handler class calls another one (to avoid loops etc.)

AliasHandler.php:
- replace $called_by_MailboxHandler / MailboxAliasConfig() with $called_by
  (code moved to PFAHandler->calledBy())

MailboxHandler.php:
- beforestore(): update alias active status on edit
  (contains some whitespace changes - basically I removed "if ($this->new)"
  around most parts of the code)
- use calledBy() instead of MailboxAliasConfig()



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

@ -10,8 +10,6 @@ class AliasHandler extends PFAHandler {
protected $domain_field = 'domain'; protected $domain_field = 'domain';
protected $called_by_MailboxHandler = false;
/** /**
* *
* @public * @public
@ -104,13 +102,6 @@ class AliasHandler extends PFAHandler {
); );
} }
/**
* set a special flag if called by MailboxHandler
*/
public function MailboxAliasConfig() {
$this->called_by_MailboxHandler = true;
}
/** /**
* AliasHandler needs some special handling in init() and therefore overloads the function. * AliasHandler needs some special handling in init() and therefore overloads the function.
* It also calls parent::init() * It also calls parent::init()
@ -177,7 +168,7 @@ class AliasHandler extends PFAHandler {
* check number of existing aliases for this domain - is one more allowed? * check number of existing aliases for this domain - is one more allowed?
*/ */
private function create_allowed($domain) { private function create_allowed($domain) {
if ($this->called_by_MailboxHandler) return true; # always allow creating an alias for a mailbox if ($this->called_by == 'MailboxHandler') return true; # always allow creating an alias for a mailbox
$limit = get_domain_properties ($domain); $limit = get_domain_properties ($domain);

@ -189,31 +189,33 @@ class MailboxHandler extends PFAHandler {
$this->values['quota'] = $this->values['quota'] * Config::read('quota_multiplier'); # convert quota from MB to bytes $this->values['quota'] = $this->values['quota'] * Config::read('quota_multiplier'); # convert quota from MB to bytes
} }
if ($this->new) { $ah = new AliasHandler($this->new, $this->admin_username);
$ah = new AliasHandler(1, $this->admin_username);
$ah->MailboxAliasConfig(); $ah->calledBy('MailboxHandler');
if ( !$ah->init($this->id) ) { if ( !$ah->init($this->id) ) {
$this->errormsg[] = $ah->errormsg[0]; $this->errormsg[] = $ah->errormsg[0];
return false; return false;
} }
$alias_data = array( $alias_data = array();
# 'goto_mailbox' = 1; # would be technically correct, but setting 'goto' is easier
'goto' => array($this->id),
'active' => $this->values['active'],
);
if (!$ah->set($alias_data)) { if (isset($this->values['active'])) { # might not be set in edit mode
$this->errormsg[] = $ah->errormsg[0]; $alias_data['active'] = $this->values['active'];
return false; }
}
if (!$ah->store()) { if ($this->new) {
$this->errormsg[] = $ah->errormsg[0]; $alias_data['goto'] == array($this->id); # 'goto_mailbox' = 1; # would be technically correct, but setting 'goto' is easier
return false; }
}
if (!$ah->set($alias_data)) {
$this->errormsg[] = $ah->errormsg[0];
return false;
}
if (!$ah->store()) {
$this->errormsg[] = $ah->errormsg[0];
return false;
} }
return true; # still here? good! return true; # still here? good!

@ -69,6 +69,8 @@ abstract class PFAHandler {
# filled by initMsg() # filled by initMsg()
protected $msg = array(); protected $msg = array();
# called via another *Handler class? (use calledBy() to set this information)
protected $called_by = '';
/** /**
@ -125,6 +127,11 @@ abstract class PFAHandler {
* list like enum, but allow multiple selections * list like enum, but allow multiple selections
* You can use custom types, but you'll have to add handling for them in *Handler and the smarty templates * You can use custom types, but you'll have to add handling for them in *Handler and the smarty templates
* *
* All database tables should have a 'created' and a 'modified' column.
*
* Do not use one of the following field names:
* edit, delete, prefill, webroot, help
* because those are used as parameter names in the web and/or commandline interface
*/ */
abstract protected function initStruct(); abstract protected function initStruct();
@ -149,6 +156,16 @@ abstract class PFAHandler {
*/ */
abstract public function webformConfig(); abstract public function webformConfig();
/**
* if you call one *Handler class from another one, tell the "child" *Handler as early as possible (before init())
* The flag can be used to avoid logging, avoid loops etc. The exact handling is up to the implementation in *Handler
*
* @param string calling class
*/
public function calledBy($calling_class) {
$this->called_by = $calling_class;
}
/** /**
* initialize with $id and check if it is valid * initialize with $id and check if it is valid
* @param string $id * @param string $id

Loading…
Cancel
Save