SF.net SVN: postfixadmin:[1879] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2016-11-01 17:43:35
|
Revision: 1879 http://sourceforge.net/p/postfixadmin/code/1879 Author: christian_boltz Date: 2016-11-01 17:43:32 +0000 (Tue, 01 Nov 2016) Log Message: ----------- beautify alias list search parameters AliasHandler: - initStruct(): handle __mailbox_username as separate field (needed to make it searchable) - split off a condition_ignore_mailboxes() function (used in getList() and getPagebrowser()) to add '__mailbox_username IS NULL' to the search condition array. Also, make sure $condition can be an array (preferred) or a string with a raw query list-virtual.php: - hand over a search array instead of a raw query Modified Paths: -------------- trunk/list-virtual.php trunk/model/AliasHandler.php Modified: trunk/list-virtual.php =================================================================== --- trunk/list-virtual.php 2016-11-01 15:45:45 UTC (rev 1878) +++ trunk/list-virtual.php 2016-11-01 17:43:32 UTC (rev 1879) @@ -136,10 +136,9 @@ $table_mailbox = table_by_key('mailbox'); if (count($search) == 0 || !isset($search['_'])) { - $list_param = "domain='$fDomain'"; + $search_alias = array('domain' => $fDomain); } else { - $searchterm = escape_string($search['_']); - $list_param = "(address LIKE '%$searchterm%' OR goto LIKE '%$searchterm%')"; + $search_alias = array('_' => $search['_']); } $handler = new AliasHandler(0, $admin_username); @@ -153,8 +152,8 @@ $alias_data['struct']['on_vacation']['display_in_list'] = 0; $alias_data['msg']['show_simple_search'] = False; # hide search box -$handler->getList($list_param, array(), $page_size, $fDisplay); -$pagebrowser_alias = $handler->getPagebrowser($list_param, array()); +$handler->getList($search_alias, array(), $page_size, $fDisplay); +$pagebrowser_alias = $handler->getPagebrowser($search_alias, array()); $tAlias = $handler->result(); Modified: trunk/model/AliasHandler.php =================================================================== --- trunk/model/AliasHandler.php 2016-11-01 15:45:45 UTC (rev 1878) +++ trunk/model/AliasHandler.php 2016-11-01 17:43:32 UTC (rev 1879) @@ -42,7 +42,7 @@ /*options*/ '', /*not_in_db*/ 0, /*dont_write_to_db*/ 1, - /*select*/ 'coalesce(__is_mailbox,0) as is_mailbox, __mailbox_username', + /*select*/ 'coalesce(__is_mailbox,0) as is_mailbox', # __mailbox_username is unused, but needed as workaround for a MariaDB bug /*extrafrom*/ 'LEFT JOIN ( ' . ' SELECT 1 as __is_mailbox, username as __mailbox_username ' . @@ -50,6 +50,7 @@ ' WHERE username IS NOT NULL ' . ' AND ' . db_in_clause($this->domain_field, $this->allowed_domains) . ' ) AS __mailbox ON __mailbox_username = address' ), + '__mailbox_username' => pacol( 0, 0, 1, 'vtxt', '' , '' , 0), # filled via is_mailbox 'goto_mailbox' => pacol( $mbgoto, $mbgoto,$mbgoto,'bool', 'pEdit_alias_forward_and_store' , '' , 0, /*options*/ '', /*not_in_db*/ 1 ), # read_from_db_postprocess() sets the value @@ -304,22 +305,28 @@ return $db_result; } - public function getList($condition, $searchmode = array(), $limit=-1, $offset=-1) { + private function condition_ignore_mailboxes($condition, $searchmode) { # only list aliases that do not belong to mailboxes - # TODO: breaks if $condition is an array - if ($condition != '') { - $condition = " AND ( $condition ) "; + if (is_array($condition)) { + $condition['__mailbox_username'] = 1; + $searchmode['__mailbox_username'] = 'NULL'; + } else { + if ($condition != '') { + $condition = " ( $condition ) AND "; + } + $condition = " $condition __mailbox_username IS NULL "; } - return parent::getList( "__mailbox_username IS NULL $condition", $searchmode, $limit, $offset); + return array($condition, $searchmode); } + public function getList($condition, $searchmode = array(), $limit=-1, $offset=-1) { + list($condition, $searchmode) = $this->condition_ignore_mailboxes($condition, $searchmode); + return parent::getList($condition, $searchmode, $limit, $offset); + } + public function getPagebrowser($condition, $searchmode = array()) { - # only list aliases that do not belong to mailboxes - # TODO: breaks if $condition is an array - if ($condition != '') { - $condition = " AND ( $condition ) "; - } - return parent::getPagebrowser( "__mailbox_username IS NULL $condition", $searchmode); + list($condition, $searchmode) = $this->condition_ignore_mailboxes($condition, $searchmode); + return parent::getPagebrowser($condition, $searchmode); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |