model/DomainHandler.php:

- split __construct to
  - __construct($new=0) - init $struct etc.   and
  - init($username) - validate $username
  This allows reading of $struct before doing any check on the username,
  and will also avoid problems when I implement a function to list all
  domains
- init(): use direct return values instead of $this->return

scripts/shells/domain.php, create-domain.php
- update to use new DomainHandler->init()


git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1219 a1433add-5e2c-0410-b055-b7f2511e0802
pull/2/head
Christian Boltz 13 years ago
parent 5c5c79e8a9
commit f8fb724dcf

@ -58,8 +58,8 @@ foreach($form_fields as $key => $field) {
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$handler = new DomainHandler($values['domain'], 1);
if (!$handler->result()) {
$handler = new DomainHandler(1);
if (!$handler->init($values['domain'])) {
$error = 1;
$pAdminCreate_domain_domain_text_error = join("<br />", $handler->errormsg);
}

@ -16,35 +16,44 @@ class DomainHandler extends PFAHandler {
public $errormsg = array();
# error messages used in __construct() and view()
# error messages used in init() and view()
protected $error_already_exists = 'pAdminCreate_domain_domain_text_error';
protected $error_does_not_exist = 'domain_does_not_exist';
/**
* @param string $username
* Constructor: fill $struct etc.
* @param string $new
*/
public function __construct($username, $new = 0) {
$this->username = strtolower($username); # TODO: find a better place for strtolower() to avoid a special constructor in DomainHandler (or agree that $username should be lowercase in all *Handler classes ;-)
public function __construct($new = 0) {
if ($new) $this->new = 1;
$this->initStruct();
}
/**
* initialize with $username and check if it is valid
* @param string $username
*/
public function init($username) {
$this->username = strtolower($username);
$exists = $this->view(false);
$this->return = false; # be pessimistic by default
if ($new) {
if ($this->new) {
if ($exists) {
$this->errormsg[] = Lang::read($this->error_already_exists);
return false;
} elseif (!$this->validate_id() ) {
# errormsg filled by validate_id()
return false;
} else {
$this->return = true;
return true;
}
} else { # edit mode
if (!$exists) {
$this->errormsg[] = Lang::read($this->error_does_not_exist);
return false;
} else {
$this->return = true;
return true;
}
}
}

@ -110,7 +110,7 @@ class AddTask extends Shell {
$question = "Domain Quota (in MB):";
$d = $this->in($question);
$handler = new DomainHandler($domain);
$handler = new DomainHandler();
$transports = $handler->getTransports();
$qt[] = 'Choose transport option';
foreach ($transports AS $key => $val) {
@ -141,8 +141,8 @@ class AddTask extends Shell {
function __handle($domain, $desc, $a, $m, $t, $q, $d, $default, $backup) {
$handler = new DomainHandler($domain, 1);
if (!$handler->result()) {
$handler = new DomainHandler(1);
if (!$handler->init($domain)) {
$this->error("Error:",join("\n", $handler->errormsg));
return;
}
@ -269,8 +269,8 @@ class DeleteTask extends Shell {
* @access private
*/
function __handle($address) {
$handler = new DomainHandler($address);
if (!$handler->result()) {
$handler = new DomainHandler();
if (!$handler->init($address)) {
$this->error("Error:",join("\n", $handler->errormsg));
return;
}
@ -345,8 +345,8 @@ class ViewTask extends Shell {
function __handle($domain) {
$handler = new DomainHandler($domain);
if (!$handler->result()) {
$handler = new DomainHandler();
if (!$handler->init($domain)) {
$this->error("Error:",join("\n", $handler->errormsg));
return;
}

Loading…
Cancel
Save