should work as a nl sender
authorx2000habouzit <x2000habouzit>
Wed, 20 Oct 2004 19:31:17 +0000 (19:31 +0000)
committerx2000habouzit <x2000habouzit>
Wed, 20 Oct 2004 19:31:17 +0000 (19:31 +0000)
scripts/cron/send_nl.php [new file with mode: 0755]
scripts/migration/0.9.1/newsleter.sql

diff --git a/scripts/cron/send_nl.php b/scripts/cron/send_nl.php
new file mode 100755 (executable)
index 0000000..00afb34
--- /dev/null
@@ -0,0 +1,68 @@
+#!/usr/bin/php4 -q
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2004 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************
+        $Id: send_nl.php,v 1.1 2004-10-20 19:31:17 x2000habouzit Exp $
+ ***************************************************************************/
+
+require('./connect.db.inc.php');
+require("../../include/newsletter.inc.php");
+
+function query ($sql) {
+    mysql_query($sql);
+    if (mysql_errno() != 0) {
+       echo "error in \"$sql\" :\n", mysql_error(),"\n";
+    }
+}
+
+$opts = getopt('i:h');
+
+if(empty($opt['i']) || isset($opt['h'])) {
+    echo <<<EOF
+usage: send_nl.php -i nl_id
+       sends the NewsLetter of id "id"
+EOF;
+    exit;
+}
+
+$id = intval($opt['i']);
+$nl = new NewsLetter($id);
+$nl->setSent();
+
+while(true) {
+    $sql = mysql_query("SELECT  ni.user_id,ni.pref, a.alias, u.prenom,u.nom, FIND_IN_SET(i.flags, 'femme')
+                         FROM  newsletter_ins AS ni
+                   INNER JOIN  auth_user_md5  AS u  USING(user_id)
+                   INNER JOIN  identification AS i  USING(matricule)
+                   INNER JOIN  aliases        AS a  ON(u.user_id=a.id AND a.type='a_vie')
+                        WHERE  ni.last<$id
+                        LIMIT  60");
+    if(!mysql_num_rows($res)) exit(0);
+    $sent = Array();
+    while(list($uid,$fmt,$forlife,$prenom,$nom,$sexe) = mysql_fetch_row($sql)) {
+       $sent[] = "user_id='$uid'";
+       $nl->sendTo($prenom,$nom,$forlife,$sexe,$html=='html');
+    }
+    mysql_free_result($res);
+    mysql_query("UPDATE newsletter_ins SET last=$id WHERE ".implode(' OR ',$sent));
+    sleep(60);
+}
+
+?>
index 81fd142..7ef071a 100644 (file)
@@ -6,7 +6,7 @@ alter table newsletter add column head mediumtext default '' not null;
 alter table newsletter add column bits enum('old','sent','new') default 'new' not null;
 update newsletter set bits='old';
 
-alter table newsletter_ins add column last int;
+alter table newsletter_ins add column last int not null default 0;
 alter table newsletter_ins add index (last);
 --
 -- -----------------------------------------------------------------------------