Merge branch 'xorg/master' into xorg/f/xnet-accounts
[platal.git] / bin / cron / cron_ml_moderate.php
index 268cdd3..e77643d 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/php5 -q
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -26,20 +26,25 @@ ini_set('memory_limit', '128M');
 $sent_mails = 0;
 $handler    = time();
 
+/* Cleanup dead locks */
+XDB::execute('UPDATE  email_list_moderate
+                 SET  handler = NULL
+               WHERE  handler < NOW() - 300');
+
 while ($sent_mails < $globals->lists->max_mail_per_min
        && time() - $handler < 60) {
     // take a lock on a mail
-    XDB::execute("UPDATE  email_list_moderate
+    XDB::execute('UPDATE  email_list_moderate
                      SET  handler = {?}
                    WHERE  handler IS NULL
                 ORDER BY  ts
-                LIMIT  1", $handler);
+                LIMIT  1', $handler);
     if (XDB::affectedRows() == 0) {
         break;
     }
-    $query = XDB::query('SELECT  a.fullname, a.uid, a.password,
+    $query = XDB::query('SELECT  a.full_name, a.uid, a.password,
                                  ml.ml, ml.domain, ml.mid, ml.action, ml.message
-                           FROM  accounts    AS a
+                           FROM  accounts            AS a
                      INNER JOIN  email_list_moderate AS ml ON (a.uid = ml.uid)
                           WHERE  ml.handler = {?}', $handler);
     list($fullname, $uid, $password, $list, $domain, $mid, $action, $reason) = $query->fetchOneRow();
@@ -48,7 +53,7 @@ while ($sent_mails < $globals->lists->max_mail_per_min
     $client = new MMList($uid, $password, $domain);
 
     // send the mail
-    $mail    = $client->get_pending_mail($list, $mid);
+    $mail = $client->get_pending_mail($list, $mid);
     list($det,$mem,$own) = $client->get_members($list);
     $count = 0;
     switch ($action) {
@@ -70,7 +75,7 @@ while ($sent_mails < $globals->lists->max_mail_per_min
         $action = 3;    /** 3 = DISCARD **/
         $subject = "Message supprimé";
         $append  = "a été supprimé par $fullname.\n\n"
-                 . "Rappel: il ne faut utiliser cette opération "
+                 . "Rappel : il ne faut utiliser cette opération "
                  . "que dans le cas de spams ou de virus !\n";
         $type = 'spam';
         $count += count($own);
@@ -115,7 +120,8 @@ while ($sent_mails < $globals->lists->max_mail_per_min
     }
 
     // release the lock
-    XDB::execute("DELETE FROM email_list_moderate WHERE handler = {?}",
+    XDB::execute('DELETE FROM  email_list_moderate
+                        WHERE  handler = {?}',
                  $handler);
     sleep(60 * $count / $globals->lists->max_mail_per_min);
 }