3 /***************************************************************************
4 * Copyright (C) 2003-2011 Polytechnique.org *
5 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
21 ***************************************************************************/
22 /* Checks inconsistances in tables and joins. */
24 require './connect.db.inc.php';
25 require 'Console/Getopt.php';
27 function check($sql, $comment = '')
29 $it = XDB
::iterRow($sql);
30 if ($err = XDB
::error()) {
33 if ($it->total() > 0) {
34 echo "Erreur pour la vérification : $comment\n$sql\n\n";
36 while($col = $it->nextField()) {
37 echo "\t" . $col->name
. "\t|";
41 while ($arr = $it->next()) {
43 foreach ($arr as $val) {
52 function checkCount($sql, $comment = '')
54 $count = XDB
::rawFetchOneCell($sql);
55 if ($err = XDB
::error()) {
59 echo "Erreur pour la vérification : $comment\n$sql\n\n";
60 echo "|\tTotal\t|\n|\t$count\t|\n\n";
64 function info($sql, $comment = '', $onlyCounts = false
) {
68 checkCount($sql, $comment);
70 check($sql, $comment);
76 $opts = Console_GetOpt
::getopt($argv, 'v');
79 if (PEAR
::isError($opts)) {
80 echo $opts->getMessage();
83 foreach ($opts as $opt) {
92 /* Checks rewriting on deleted aliases. */
93 check("SELECT a.alias, e.email, e.rewrite AS broken
95 INNER JOIN emails AS e ON (a.uid = e.uid AND rewrite != '')
96 LEFT JOIN aliases AS b ON (b.uid = a.uid AND rewrite LIKE CONCAT(b.alias, '@%') AND b.type != 'homonyme')
97 WHERE a.type = 'a_vie' AND b.type IS NULL",
98 "Personnes qui ont des rewrite sur un alias perdu.");
100 /* Lists unsound emails that remain unprocessed by the administrators. */
101 check("SELECT a1.alias, a2.alias, e1.email, e2.flags
103 INNER JOIN emails AS e2 ON (e1.email = e2.email AND e1.uid != e2.uid AND
104 (e1.uid < e2.uid OR NOT FIND_IN_SET('active', e2.flags)))
105 INNER JOIN email_watch AS w ON (w.email = e1.email AND w.state = 'pending')
106 INNER JOIN aliases AS a1 ON (a1.uid = e1.uid AND a1.type = 'a_vie')
107 INNER JOIN aliases AS a2 ON (a2.uid = e2.uid AND a2.type = 'a_vie')
108 WHERE FIND_IN_SET('active', e1.flags)
110 "Donne la liste des emails douteux actuellement non traites par les administrateurs.");
112 /* Lists dangerous and unsound emails. */
113 info("SELECT a1.alias, a2.alias, e1.email, e2.flags, w.state
115 INNER JOIN emails AS e2 ON (e1.email = e2.email AND e1.uid != e2.uid AND
116 (e1.uid < e2.uid OR NOT FIND_IN_SET('active', e2.flags)))
117 INNER JOIN email_watch AS w ON (w.email = e1.email AND w.state != 'safe')
118 INNER JOIN aliases AS a1 ON (a1.uid = e1.uid AND a1.type = 'a_vie')
119 INNER JOIN aliases AS a2 ON (a2.uid = e2.uid AND a2.type = 'a_vie')
120 WHERE FIND_IN_SET('active', e1.flags)
122 "Donne la liste des emails dangereux ou douteux.");
124 /* Lists homonyms who have an alias equals to their loginbis for more than a month. */
125 check("SELECT a.alias AS username, b.alias AS loginbis, b.expire
127 INNER JOIN aliases AS b ON (a.uid=b.uid AND b.type != 'homonyme' and b.expire < NOW())
128 WHERE a.type = 'a_vie'",
129 "Donne la liste des homonymes qui ont un alias égal à leur loginbis depuis plus d'un mois, il est temps de supprimer leur alias.");
131 // XXX: counts the number of remaining issues due to the merge (to be removed once all merge related issues have been fixed)
132 info('SELECT COUNT(*)
133 FROM profile_merge_issues
134 WHERE issues IS NULL OR issues = \'\'',
135 'Dénombre les erreurs dues à la fusion restantes.',
138 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: