SF.net SVN: postfixadmin:[1219] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2011-10-18 22:11:29
|
Revision: 1219 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=1219&view=rev Author: christian_boltz Date: 2011-10-18 22:11:22 +0000 (Tue, 18 Oct 2011) Log Message: ----------- 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() Modified Paths: -------------- trunk/create-domain.php trunk/model/DomainHandler.php trunk/scripts/shells/domain.php Modified: trunk/create-domain.php =================================================================== --- trunk/create-domain.php 2011-10-18 21:15:11 UTC (rev 1218) +++ trunk/create-domain.php 2011-10-18 22:11:22 UTC (rev 1219) @@ -58,8 +58,8 @@ 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); } Modified: trunk/model/DomainHandler.php =================================================================== --- trunk/model/DomainHandler.php 2011-10-18 21:15:11 UTC (rev 1218) +++ trunk/model/DomainHandler.php 2011-10-18 22:11:22 UTC (rev 1219) @@ -16,35 +16,44 @@ 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; } } } Modified: trunk/scripts/shells/domain.php =================================================================== --- trunk/scripts/shells/domain.php 2011-10-18 21:15:11 UTC (rev 1218) +++ trunk/scripts/shells/domain.php 2011-10-18 22:11:22 UTC (rev 1219) @@ -110,7 +110,7 @@ $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 @@ 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 @@ * @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 @@ 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; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |