SF.net SVN: postfixadmin:[1535] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2013-10-13 16:11:19
|
Revision: 1535 http://sourceforge.net/p/postfixadmin/code/1535 Author: christian_boltz Date: 2013-10-13 16:11:15 +0000 (Sun, 13 Oct 2013) Log Message: ----------- model/PFAHandler.php: - getList: change return value to be always true (even if the database result is an empty array), and die() if the database result is not an array. This avoids some if blocks in various files to implement a fallback to array() on empty results. functions.inc.php: - list_admins(): simplify after the *Handler->getList() change - get_domain_properties(): change a forgotten $handler->return to $handler->result() (follow-up for r1534) list-domain, list-virtual.php: - simplify after the *Handler->getList() change Revision Links: -------------- http://sourceforge.net/p/postfixadmin/code/1534 Modified Paths: -------------- trunk/functions.inc.php trunk/list-domain.php trunk/list-virtual.php trunk/model/PFAHandler.php Modified: trunk/functions.inc.php =================================================================== --- trunk/functions.inc.php 2013-10-13 15:26:37 UTC (rev 1534) +++ trunk/functions.inc.php 2013-10-13 16:11:15 UTC (rev 1535) @@ -410,7 +410,7 @@ die("Error: " . join("\n", $handler->errormsg)); } - $result = $handler->return; + $result = $handler->result(); return $result; } @@ -631,14 +631,8 @@ function list_admins () { $handler = new AdminHandler(); - if ($handler->getList('1=1')) { - $list = $handler->result(); - } else { - $list = array(); - # TODO: check if there was an error or simply no admins (which shouldn't happen because nobody could login then...) - } - - return $list; + $handler->getList(''); + return $handler->result(); } Modified: trunk/list-domain.php =================================================================== --- trunk/list-domain.php 2013-10-13 15:26:37 UTC (rev 1534) +++ trunk/list-domain.php 2013-10-13 16:11:15 UTC (rev 1535) @@ -37,14 +37,9 @@ } $handler = new DomainHandler(0, $admin_username); -if ($handler->getList('1=1')) { - $domain_properties = $handler->result(); -} else { - $domain_properties = array(); - # TODO: check if there was an error or simply no domains -} +$handler->getList(''); +$domain_properties = $handler->result(); - $smarty->assign ('domain_properties', $domain_properties); $smarty->assign ('select_options', select_options($list_admins, array ($fUsername)), false); if ($is_superadmin) { Modified: trunk/list-virtual.php =================================================================== --- trunk/list-virtual.php 2013-10-13 15:26:37 UTC (rev 1534) +++ trunk/list-virtual.php 2013-10-13 16:11:15 UTC (rev 1535) @@ -103,21 +103,16 @@ } $handler = new AliasdomainHandler(0, $admin_username); - if ($handler->getList($list_param)) { - $tAliasDomains = $handler->result(); - } else { - $tAliasDomains = array(); - # TODO: check if there was an error or simply no alias domains - } + $handler->getList($list_param); + $tAliasDomains = $handler->result(); $can_create_alias_domain = 1; foreach ($tAliasDomains as $row) { if ($row['alias_domain'] == $fDomain) $can_create_alias_domain = 0; # domain is already an alias domain } # set $can_create_alias_domain = 0 if all domains (of this admin) are already used as alias domains - if ($handler->getList("1=1")) { - if ( count($handler->result()) + 1 >= count($list_domains) ) $can_create_alias_domain = 0; # all domains (of this admin) are already alias domains - } + $handler->getList(""); + if ( count($handler->result()) + 1 >= count($list_domains) ) $can_create_alias_domain = 0; # all domains (of this admin) are already alias domains } # @@ -150,12 +145,8 @@ */ $handler = new AliasHandler(0, $admin_username); -if ($handler->getList($list_param, $page_size, $fDisplay)) { - $tAlias = $handler->result(); -} else { - $tAlias= array(); - # TODO: check if there was an error or simply no aliases -} +$handler->getList($list_param, $page_size, $fDisplay); +$tAlias = $handler->result(); Modified: trunk/model/PFAHandler.php =================================================================== --- trunk/model/PFAHandler.php 2013-10-13 15:26:37 UTC (rev 1534) +++ trunk/model/PFAHandler.php 2013-10-13 16:11:15 UTC (rev 1535) @@ -513,19 +513,20 @@ * @param array or string $condition - see read_from_db for details * @param integer limit - maximum number of rows to return * @param integer offset - number of first row to return - * @return bool - true if at least one item was found + * @return bool - always true, no need to check ;-) (if $result is not an array, getList die()s) * The data is stored in $this->result (as array of rows, each row is an associative array of column => value) */ public function getList($condition, $limit=-1, $offset=-1) { $result = $this->read_from_db($condition, $limit, $offset); - if (count($result) >= 1) { - $this->result = $result; - return true; + + if (!is_array($result)) { + error_log('getList: read_from_db didn\'t return an array. table: ' . $this->db_table . ' - condition: $condition - limit: $limit - offset: $offset'); + error_log('getList: This is most probably caused by read_from_db_postprocess()'); + die('Unexpected error while reading from database! (Please check the error log for details, and open a bugreport)'); } -# $this->errormsg[] = Lang::read($this->msg['error_does_not_exist']); -# $this->errormsg[] = $result['error']; - return false; + $this->result = $result; + return true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |