Moving to GitHub.
[platal.git] / bin / newsletter.send.php
index 15b3359..1d56351 100755 (executable)
@@ -1,7 +1,7 @@
-#!/usr/bin/php4 -q
+#!/usr/bin/php5 -q
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2006 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-require('./connect.db.inc.php');
-require("newsletter.inc.php");
+require_once 'connect.db.inc.php';
+require_once 'plmailer.php';
+require_once 'newsletter.inc.php';
+ini_set('memory_limit', '128M');
 
 $opt = getopt('i:h');
 
-if(empty($opt['i']) || isset($opt['h'])) {
+if (empty($opt['i']) || isset($opt['h'])) {
     echo <<<EOF
 usage: send_nl.php -i nl_id
        sends the NewsLetter of id "id"
@@ -34,30 +36,9 @@ EOF;
 }
 
 $id = intval($opt['i']);
-$nl = new NewsLetter($id);
-$nl->setSent();
-
-while(true) {
-    $res = $globals->xdb->iterRow(
-            "SELECT  ni.user_id, a.alias,
-                     u.prenom, IF(u.nom_usage='', u.nom, u.nom_usage),
-                     FIND_IN_SET('femme', u.flags),
-                    q.core_mail_fmt AS pref
-               FROM  newsletter_ins  AS ni
-         INNER JOIN  auth_user_md5   AS u  USING(user_id)
-        INNER JOIN  auth_user_quick AS q  ON(q.user_id = u.user_id)
-         INNER JOIN  aliases         AS a  ON(u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags))
-              WHERE  ni.last<{?}
-              LIMIT  60", $id);
-    if (!$res->total()) { exit; }
-
-    $sent = Array();
-    while (list($uid, $bestalias, $prenom, $nom, $sexe, $fmt) = $res->next()) {
-       $sent[] = "user_id='$uid'";
-       $nl->sendTo($prenom, $nom, $bestalias, $sexe, $fmt=='html');
-    }
-    $globals->xdb->execute('UPDATE newsletter_ins SET last={?} WHERE '.implode(' OR ', $sent), $id);
-    sleep(60);
-}
+$nl = NewsLetter::forGroup(NewsLetter::GROUP_XORG);
+$issue = $nl->getIssue($id);
+$issue->sendToAll();
 
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
 ?>