866f1333 |
1 | #!/usr/bin/php4 -q |
2 | <?php |
3 | /*************************************************************************** |
4 | * Copyright (C) 2003-2006 Polytechnique.org * |
5 | * http://opensource.polytechnique.org/ * |
6 | * * |
7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * |
11 | * * |
12 | * This program is distributed in the hope that it will be useful, * |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
15 | * GNU General Public License for more details. * |
16 | * * |
17 | * You should have received a copy of the GNU General Public License * |
18 | * along with this program; if not, write to the Free Software * |
19 | * Foundation, Inc., * |
20 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
21 | ***************************************************************************/ |
22 | |
23 | require('./connect.db.inc.php'); |
24 | |
25 | $sql = "SELECT a1.alias, a2.alias, e1.email |
26 | FROM emails AS e1 |
27 | INNER JOIN emails AS e2 ON (e1.email = e2.email AND e1.uid != e2.uid |
28 | AND (e1.uid < e2.uid OR NOT FIND_IN_SET(e2.flags, 'active'))) |
29 | LEFT JOIN emails_watch AS w ON (e1.email = w.email) |
30 | INNER JOIN aliases AS a1 ON (a1.id = e1.uid AND a1.type = 'a_vie') |
31 | INNER JOIN aliases AS a2 ON (a2.id = e2.uid AND a2.type = 'a_vie') |
32 | INNER JOIN auth_user_md5 AS u1 ON (a1.id = u1.user_id) |
33 | INNER JOIN auth_user_md5 AS u2 ON (a2.id = u2.user_id) |
34 | WHERE FIND_IN_SET(e1.flags, 'active') AND u1.nom != u2.nom_usage AND u2.nom != u1.nom_usage AND w.email IS NULL |
35 | ORDER BY a1.alias"; |
36 | |
37 | $it = Xdb::iterRow($sql); |
38 | |
39 | $insert = array(); |
40 | $conflits = array(); |
41 | while (list($alias1, $alias2, $mail) = $it->next()) { |
42 | $insert[] = "('$mail', 'pending', CURDATE(), NOW())"; |
43 | $conflits[] = "* $mail sur $alias1 et $alias2"; |
44 | } |
45 | |
46 | if (count($conflits) > 0) { |
47 | echo "Nouvelles adresses en doublon détectées :\n" . join("\n", $conflits) |
48 | . "\n\nVous pouvez entrer les informations collectées à ce sujet sur la page :\n" |
9e570fe0 |
49 | . "http://www.polytechnique.org/admin/emails/duplicated"; |
866f1333 |
50 | |
51 | echo "\n\n"; |
52 | $sql = "INSERT IGNORE INTO emails_watch (email, state, detection, last) |
53 | VALUES " . join(", ", $insert); |
54 | Xdb::execute($sql); |
55 | if (mysql_errno() != 0) { |
56 | echo 'Error : ' . mysql_error() . "\n$sql"; |
57 | } |
58 | } |
59 | |
60 | |
61 | |
62 | ?> |