X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Femail.php;h=ece008d0f9b6001b4e40d58a571f31d2dfbd9e4b;hb=e23d21c1588a9ffa0697aef08e9ebdada4fe167e;hp=d412b2aded7479c503d50315417e04572920bccd;hpb=f036c8966e64d9f2bb3923bbeb278353bc7e1083;p=platal.git diff --git a/modules/email.php b/modules/email.php index d412b2a..ece008d 100644 --- a/modules/email.php +++ b/modules/email.php @@ -67,24 +67,32 @@ class EmailModule extends PLModule WHERE uid = {?}", $user->id()); // Then gives the bestalias flag to the given email. list($email, $domain) = explode('@', $email); - XDB::execute("UPDATE email_source_account AS s - INNER JOIN email_virtual_domains AS d ON (s.domain = d.id) - SET s.flags = CONCAT_WS(',', IF(s.flags = '', NULL, s.flags), 'bestalias') - WHERE s.uid = {?} AND s.email = {?} AND d.name = {?}", $user->id(), $email, $domain); + XDB::execute("UPDATE email_source_account + SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias') + WHERE uid = {?} AND email = {?}", $user->id(), $email); + XDB::execute('UPDATE accounts AS a + INNER JOIN email_virtual_domains AS d ON (d.name = {?}) + SET a.best_domain = d.id + WHERE a.uid = {?}', + $domain, $user->id()); // As having a non-null bestalias value is critical in // plat/al's code, we do an a posteriori check on the // validity of the bestalias. fix_bestalias($user); + // Then refetch the user to update its bestalias. + S::set('user', User::getWithUID(S::user()->id())); } // Fetch and display aliases. $aliases = XDB::iterator("SELECT CONCAT(s.email, '@', d.name) AS email, (s.type = 'forlife') AS forlife, - (s.email REGEXP '\\\\.[0-9]{2}$') AS hundred_year, - FIND_IN_SET('bestalias', s.flags) AS bestalias, s.expire, - (s.type = 'alias_aux') AS alias + (s.email REGEXP '\\\\.[0-9]{2}$') AS hundred_year, s.expire, + (FIND_IN_SET('bestalias', s.flags) AND a.best_domain = d.id) AS bestalias, + ((s.type = 'alias_aux') AND d.aliasing = d.id) AS alias FROM email_source_account AS s - INNER JOIN email_virtual_domains AS d ON (s.domain = d.id) + INNER JOIN accounts AS a ON (s.uid = a.uid) + INNER JOIN email_virtual_domains AS m ON (s.domain = m.id) + INNER JOIN email_virtual_domains AS d ON (d.aliasing = m.id) WHERE s.uid = {?} ORDER BY !alias, s.email", $user->id()); @@ -290,6 +298,7 @@ class EmailModule extends PLModule ORDER BY NOT(s.type = \'alias_aux\'), s.email, d.name', $user->id()); $page->assign('alias', $alias->fetchAllAssoc()); + $page->assign('best_email', $user->bestEmail()); $page->assign('emails', $redirect->emails);