mirror of
https://github.com/mailcow/mailcow-dockerized.git
synced 2024-12-09 08:50:05 +08:00
[Web] optimizing update_sogo_static_view function
This commit is contained in:
parent
d9d958356a
commit
4121509ceb
@ -1021,74 +1021,41 @@ function update_sogo_static_view($mailbox = null) {
|
|||||||
}
|
}
|
||||||
global $pdo;
|
global $pdo;
|
||||||
global $lang;
|
global $lang;
|
||||||
$stmt = $pdo->query("SELECT 'OK' FROM INFORMATION_SCHEMA.TABLES
|
|
||||||
WHERE TABLE_NAME = 'sogo_view'");
|
$query = "REPLACE INTO _sogo_static_view (`c_uid`, `domain`, `c_name`, `c_password`, `c_cn`, `mail`, `aliases`, `ad_aliases`, `ext_acl`, `kind`, `multiple_bookings`)
|
||||||
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
|
SELECT
|
||||||
if ($num_results != 0) {
|
mailbox.username,
|
||||||
if ($mailbox == null){
|
mailbox.domain,
|
||||||
$stmt = $pdo->query("REPLACE INTO _sogo_static_view (`c_uid`, `domain`, `c_name`, `c_password`, `c_cn`, `mail`, `aliases`, `ad_aliases`, `ext_acl`, `kind`, `multiple_bookings`)
|
mailbox.username,
|
||||||
SELECT
|
IF(JSON_UNQUOTE(JSON_VALUE(attributes, '$.force_pw_update')) = '0',
|
||||||
mailbox.username,
|
IF(JSON_UNQUOTE(JSON_VALUE(attributes, '$.sogo_access')) = 1, password, '{SSHA256}A123A123A321A321A321B321B321B123B123B321B432F123E321123123321321'),
|
||||||
mailbox.domain,
|
'{SSHA256}A123A123A321A321A321B321B321B123B123B321B432F123E321123123321321'),
|
||||||
mailbox.username,
|
mailbox.name,
|
||||||
IF(JSON_UNQUOTE(JSON_VALUE(attributes, '$.force_pw_update')) = '0', IF(JSON_UNQUOTE(JSON_VALUE(attributes, '$.sogo_access')) = 1, password, '{SSHA256}A123A123A321A321A321B321B321B123B123B321B432F123E321123123321321'), '{SSHA256}A123A123A321A321A321B321B321B123B123B321B432F123E321123123321321'),
|
mailbox.username,
|
||||||
mailbox.name,
|
IFNULL(GROUP_CONCAT(ga.aliases ORDER BY ga.aliases SEPARATOR ' '), ''),
|
||||||
mailbox.username,
|
IFNULL(gda.ad_alias, ''),
|
||||||
IFNULL(GROUP_CONCAT(ga.aliases ORDER BY ga.aliases SEPARATOR ' '), ''),
|
IFNULL(external_acl.send_as_acl, ''),
|
||||||
IFNULL(gda.ad_alias, ''),
|
mailbox.kind,
|
||||||
IFNULL(external_acl.send_as_acl, ''),
|
mailbox.multiple_bookings
|
||||||
mailbox.kind,
|
FROM
|
||||||
mailbox.multiple_bookings
|
mailbox
|
||||||
FROM
|
LEFT OUTER JOIN grouped_mail_aliases ga ON ga.username REGEXP CONCAT('(^|,)', mailbox.username, '($|,)')
|
||||||
mailbox
|
LEFT OUTER JOIN grouped_domain_alias_address gda ON gda.username = mailbox.username
|
||||||
LEFT OUTER JOIN
|
LEFT OUTER JOIN grouped_sender_acl_external external_acl ON external_acl.username = mailbox.username
|
||||||
grouped_mail_aliases ga
|
WHERE
|
||||||
ON ga.username REGEXP CONCAT('(^|,)', mailbox.username, '($|,)')
|
mailbox.active = '1'";
|
||||||
LEFT OUTER JOIN
|
|
||||||
grouped_domain_alias_address gda
|
if ($mailbox !== null) {
|
||||||
ON gda.username = mailbox.username
|
$query .= " AND mailbox.username = :mailbox";
|
||||||
LEFT OUTER JOIN
|
$stmt = $pdo->prepare($query);
|
||||||
grouped_sender_acl_external external_acl
|
$stmt->execute(array(':mailbox' => $mailbox));
|
||||||
ON external_acl.username = mailbox.username
|
} else {
|
||||||
WHERE
|
$query .= " GROUP BY mailbox.username";
|
||||||
mailbox.active = '1'
|
$stmt = $pdo->query($query);
|
||||||
GROUP BY
|
|
||||||
mailbox.username;");
|
|
||||||
} else {
|
|
||||||
$stmt = $pdo->prepare("REPLACE INTO _sogo_static_view (`c_uid`, `domain`, `c_name`, `c_password`, `c_cn`, `mail`, `aliases`, `ad_aliases`, `ext_acl`, `kind`, `multiple_bookings`)
|
|
||||||
SELECT `c_uid`, `domain`, `c_name`, `c_password`, `c_cn`, `mail`, `aliases`, `ad_aliases`, `ext_acl`, `kind`, `multiple_bookings` from sogo_view where `c_uid` = :mailbox
|
|
||||||
SELECT
|
|
||||||
mailbox.username,
|
|
||||||
mailbox.domain,
|
|
||||||
mailbox.username,
|
|
||||||
IF(JSON_UNQUOTE(JSON_VALUE(attributes, '$.force_pw_update')) = '0', IF(JSON_UNQUOTE(JSON_VALUE(attributes, '$.sogo_access')) = 1, password, '{SSHA256}A123A123A321A321A321B321B321B123B123B321B432F123E321123123321321'), '{SSHA256}A123A123A321A321A321B321B321B123B123B321B432F123E321123123321321'),
|
|
||||||
mailbox.name,
|
|
||||||
mailbox.username,
|
|
||||||
IFNULL(GROUP_CONCAT(ga.aliases ORDER BY ga.aliases SEPARATOR ' '), ''),
|
|
||||||
IFNULL(gda.ad_alias, ''),
|
|
||||||
IFNULL(external_acl.send_as_acl, ''),
|
|
||||||
mailbox.kind,
|
|
||||||
mailbox.multiple_bookings
|
|
||||||
FROM
|
|
||||||
mailbox
|
|
||||||
LEFT OUTER JOIN
|
|
||||||
grouped_mail_aliases ga
|
|
||||||
ON ga.username REGEXP CONCAT('(^|,)', mailbox.username, '($|,)')
|
|
||||||
LEFT OUTER JOIN
|
|
||||||
grouped_domain_alias_address gda
|
|
||||||
ON gda.username = mailbox.username
|
|
||||||
LEFT OUTER JOIN
|
|
||||||
grouped_sender_acl_external external_acl
|
|
||||||
ON external_acl.username = mailbox.username
|
|
||||||
WHERE
|
|
||||||
mailbox.active = '1' AND
|
|
||||||
mailbox.username = :mailbox
|
|
||||||
GROUP BY
|
|
||||||
mailbox.username;");
|
|
||||||
$stmt->execute(array(':mailbox' => $mailbox));
|
|
||||||
}
|
|
||||||
$stmt = $pdo->query("DELETE FROM _sogo_static_view WHERE `c_uid` NOT IN (SELECT `username` FROM `mailbox` WHERE `active` = '1');");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$stmt = $pdo->query("DELETE FROM _sogo_static_view WHERE `c_uid` NOT IN (SELECT `username` FROM `mailbox` WHERE `active` = '1');");
|
||||||
|
|
||||||
flush_memcached();
|
flush_memcached();
|
||||||
}
|
}
|
||||||
function edit_user_account($_data) {
|
function edit_user_account($_data) {
|
||||||
|
Loading…
Reference in New Issue
Block a user