X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Femail.php;h=1496b04d247d42ccc73d3990308a9287b49384e2;hb=52da49d8d4fdaa614f51b5e86815d79f8619126f;hp=d412b2aded7479c503d50315417e04572920bccd;hpb=f036c8966e64d9f2bb3923bbeb278353bc7e1083;p=platal.git diff --git a/modules/email.php b/modules/email.php index d412b2a..1496b04 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); @@ -818,25 +827,33 @@ class EmailModule extends PLModule if ($list == '') { $page->trigError('La liste est vide.'); } else { + require_once 'notifs.inc.php'; + $broken_user_list = array(); + $broken_user_email_count = array(); $broken_list = explode("\n", $list); sort($broken_list); foreach ($broken_list as $email) { if ($user = mark_broken_email($email, true)) { - if ($user['nb_mails'] > 0) { + if ($user['nb_mails'] > 0 && $user['notify']) { $mail = new PlMailer('emails/broken.mail.tpl'); - $mail->addTo($user); + $dest = User::getSilentWithUID($user['uid']); + $mail->setTo($dest); $mail->assign('user', $user); $mail->assign('email', $email); $mail->send(); + } else { + $profile = Profile::get($user['alias']); + WatchProfileUpdate::register($profile, 'broken'); } - if (!isset($broken_user_list[$user['alias']])) { - $broken_user_list[$user['alias']] = array($email); + if (!isset($broken_user_list[$user['uid']])) { + $broken_user_list[$user['uid']] = array($email); } else { - $broken_user_list[$user['alias']][] = $email; + $broken_user_list[$user['uid']][] = $email; } + $broken_user_email_count[$user['uid']] = $user['nb_mails']; } } @@ -851,42 +868,28 @@ class EmailModule extends PLModule // Output the list of users with recently broken addresses, // along with the count of valid redirections. - require_once 'notifs.inc.php'; pl_cached_content_headers('text/x-csv', 1); $csv = fopen('php://output', 'w'); - fputcsv($csv, array('nom', 'promo', 'alias', 'bounce', 'nbmails', 'url', 'corps', 'job', 'networking'), ';'); - foreach ($broken_user_list as $alias => $mails) { - $sel = Xdb::query( - 'SELECT a.uid, count(DISTINCT(r.redirect)) AS nb_mails, - IFNULL(pd.public_name, a.full_name) AS fullname, - IFNULL(pd.promo, 0) AS promo, IFNULL(pce.name, \'Aucun\') AS corps, - IFNULL(pje.name, \'Aucun\') AS job, GROUP_CONCAT(pn.address SEPARATOR \', \') AS networking - FROM email_source_account AS s - INNER JOIN accounts AS a ON (s.uid = a.uid) - LEFT JOIN email_redirect_account AS r ON (a.uid = r.uid AND r.broken_level = 0 AND r.flags = \'active\' AND - (r.type = \'smtp\' OR r.type = \'googleapps\')) - LEFT JOIN account_profiles AS ap ON (a.uid = ap.uid AND FIND_IN_SET(\'owner\', ap.perms)) - LEFT JOIN profile_display AS pd ON (pd.pid = ap.pid) - LEFT JOIN profile_corps AS pc ON (pc.pid = ap.pid) - LEFT JOIN profile_corps_enum AS pce ON (pc.current_corpsid = pce.id) - LEFT JOIN profile_job AS pj ON (pj.pid = ap.pid) - LEFT JOIN profile_job_enum AS pje ON (pj.jobid = pje.id) - LEFT JOIN profile_networking AS pn ON (pn.pid = ap.pid) - WHERE s.email = {?} - GROUP BY a.uid', $alias); - - if ($x = $sel->fetchOneAssoc()) { - if ($x['nb_mails'] == 0) { - $user = User::getSilentWithUID($x['uid']); - $profile = $user->profile(); - WatchProfileUpdate::register($profile, 'broken'); - } - fputcsv($csv, array($x['fullname'], $x['promo'], $alias, - join(',', $mails), $x['nb_mails'], - 'https://www.polytechnique.org/marketing/broken/' . $alias, - $x['corps'], $x['job'], $x['networking']), ';'); + fputcsv($csv, array('nom', 'promo', 'bounces', 'nbmails', 'url', 'corps', 'job', 'networking'), ';'); + foreach ($broken_user_list as $uid => $mails) { + $profile = Profile::get($uid); + $corps = $profile->getCorps(); + $current_corps = ($corps && $corps->current) ? $corps->current : ''; + $jobs = $profile->getJobs(); + $companies = array(); + foreach ($jobs as $job) { + $companies[] = $job->company->name; + } + $networkings = $profile->getNetworking(Profile::NETWORKING_ALL); + $networking_list = array(); + foreach ($networkings as $networking) { + $networking_list[] = $networking['address']; } + fputcsv($csv, array($profile->fullName(), $profile->promo(), + join(',', $mails), $broken_user_email_count[$uid], + 'https://www.polytechnique.org/marketing/broken/' . $profile->hrid(), + $current_corps, implode(',', $companies), implode(',', $networking_list)), ';'); } fclose($csv); exit;