Skip to content

Commit 8e58634

Browse files
committed
Compressing the View, preparing tested PgSQL Support
1 parent 24f7535 commit 8e58634

File tree

3 files changed

+23
-37
lines changed

3 files changed

+23
-37
lines changed

SQL/iredmail+alias.sql

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ VIEW `global_addressbook` AS
99
UNIX_TIMESTAMP(`vmail`.`mailbox`.`created`),
1010
-(8)) AS `ID`,
1111
`vmail`.`mailbox`.`name` AS `name`,
12-
SUBSTRING_INDEX(SUBSTRING_INDEX(`vmail`.`mailbox`.`name`, ' ', 1),
13-
' ',
14-
-(1)) AS `firstname`,
15-
SUBSTRING_INDEX(SUBSTRING_INDEX(`vmail`.`mailbox`.`name`, ' ', -(1)),
16-
' ',
17-
-(1)) AS `surname`,
1812
(SELECT
1913
GROUP_CONCAT(`vmail`.`alias`.`address`
2014
SEPARATOR ',')
@@ -23,12 +17,6 @@ VIEW `global_addressbook` AS
2317
WHERE
2418
((`vmail`.`alias`.`goto` = `vmail`.`mailbox`.`username`)
2519
AND (`vmail`.`alias`.`address` LIKE '%@%'))) AS `email`,
26-
`vmail`.`mailbox`.`domain` AS `domain`,
27-
(SELECT
28-
CONCAT_WS(' ',
29-
`vmail`.`mailbox`.`name`,
30-
REPLACE(`email`, ',', ' '),
31-
`vmail`.`mailbox`.`domain`)
32-
) AS `words`
20+
`vmail`.`mailbox`.`domain` AS `domain`
3321
FROM
3422
`vmail`.`mailbox`

SQL/iredmail.sql

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,7 @@ VIEW `global_addressbook` AS
99
UNIX_TIMESTAMP(`vmail`.`mailbox`.`created`),
1010
-(8)) AS `ID`,
1111
`vmail`.`mailbox`.`name` AS `name`,
12-
SUBSTRING_INDEX(SUBSTRING_INDEX(`vmail`.`mailbox`.`name`, ' ', 1),
13-
' ',
14-
-(1)) AS `firstname`,
15-
SUBSTRING_INDEX(SUBSTRING_INDEX(`vmail`.`mailbox`.`name`, ' ', -(1)),
16-
' ',
17-
-(1)) AS `surname`,
1812
`vmail`.`mailbox`.`username` AS `email`,
19-
`vmail`.`mailbox`.`domain` AS `domain`,
20-
(SELECT
21-
CONCAT_WS(' ',
22-
`vmail`.`mailbox`.`name`,
23-
`email`,
24-
`vmail`.`mailbox`.`domain`)
25-
) AS `words`
13+
`vmail`.`mailbox`.`domain` AS `domain`
2614
FROM
2715
`vmail`.`mailbox`;

sql_global_addressbooks/sql_global_backend.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ public function list_records($cols=null, $subset=0) {
8686

8787
while ($ret = $db->fetch_assoc()) {
8888
$ret['email'] = explode(',', $ret['email']);
89+
//$names = explode(' ', $ret['name']);
90+
//$ret['surname'] = array_push($names);
91+
//$ret['firsname']= implode(' ', $names);
8992
$this->result->add($ret);
9093
}
9194
return $this->result;
@@ -101,13 +104,13 @@ function list_groups($search = null, $mode=0) {
101104
if ($search) {
102105
switch (intval($mode)) {
103106
case 1:
104-
$x = $rc->db->ilike('name', $search);
107+
$x = $rc->db->ilike('domain', $search);
105108
break;
106109
case 2:
107-
$x = $rc->db->ilike('name', $search . '%');
110+
$x = $rc->db->ilike('domain', $search . '%');
108111
break;
109112
default:
110-
$x = $rc->db->ilike('name', '%' . $search . '%');
113+
$x = $rc->db->ilike('domain', '%' . $search . '%');
111114
}
112115
$x = ' WHERE ' . $x . ' ';
113116
} else { $x = ' '; }
@@ -138,7 +141,7 @@ public function search($fields, $value, $strict=false, $select=true, $nocount=fa
138141
foreach ($fields as $idx => $col) {
139142

140143
if ($col == 'ID' || $col == $this->primary_key) {
141-
$ids = !is_array($value) ? explode(self::SEPARATOR, $value) : $value;
144+
$ids = !is_array($value) ? explode(',', $value) : $value;
142145
$ids = $db->array2list($ids, 'integer');
143146
$where[] = 'c.' . $this->primary_key.' IN ('.$ids.')';
144147
continue;
@@ -147,23 +150,30 @@ public function search($fields, $value, $strict=false, $select=true, $nocount=fa
147150
foreach (explode($WS, rcube_utils::normalize_string($value)) as $word) {
148151
switch ($mode) {
149152
case 1: // Strict
150-
$words[] = '(' . $db->ilike('words', $word . '%')
151-
. ' OR ' . $db->ilike('words', '%' . $WS . $word . $WS . '%')
152-
. ' OR ' . $db->ilike('words', '%' . $WS . $word) . ')';
153+
$words[]='(' . $db->ilike('name', $word . '%')
154+
. ' OR ' . $db->ilike('email',$word . '%')
155+
. ' OR ' . $db->ilike('name', '%' . $WS . $word . $WS . '%')
156+
. ' OR ' . $db->ilike('email','%' . $WS . $word . $WS . '%')
157+
. ' OR ' . $db->ilike('name', '%' . $WS . $word)
158+
. ' OR ' . $db->ilike('email','%' . $WS . $word). ')';
153159
break;
154160

155161
case 2: // Prefix
156-
$words[] = '(' . $db->ilike('words', $word . '%')
157-
. ' OR ' . $db->ilike('words', '%' . $WS . $word . '%') . ')';
162+
$words[]='(' . $db->ilike('name', $word . '%')
163+
. ' OR ' . $db->ilike('email',$word . '%')
164+
. ' OR ' . $db->ilike('name', '%' . $WS . $word . '%')
165+
. ' OR ' . $db->ilike('email','%' . $WS . $word . '%') . ')';
158166
break;
159167

160168
default: // Partial
161-
$words[] = $db->ilike('words', '%' . $word . '%');
169+
$words[]='(' . $db->ilike('name', '%' . $word . '%')
170+
. ' OR ' . $db->ilike('email','%' . $word . '%') . ')';
162171
break;
163172
}
164173
}
165174
$where[] = '(' . join(' AND ', $words) . ')';
166-
} else {
175+
//} else {
176+
} elseif ($col !== 'firstname' && $col !== 'surname') {
167177
$val = is_array($value) ? $value[$idx] : $value;
168178

169179
switch ($mode) {

0 commit comments

Comments
 (0)