Prevent sending of empty NLs.
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Sun, 20 Feb 2011 01:07:36 +0000 (02:07 +0100)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Sun, 20 Feb 2011 15:53:07 +0000 (16:53 +0100)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
bin/cron/newsletters.send.php
include/newsletter.inc.php

index e9e4ab5..f9fa74b 100755 (executable)
@@ -24,13 +24,17 @@ require_once './connect.db.inc.php';
 require_once 'newsletter.inc.php';
 ini_set('memory_limit', '128M');
 
-$nls = NewsLetter::getIssuesToSend();
-foreach ($nls as $nl) {
-    echo "Envoi de la lettre \"{$nl->title()}\" (Groupe {$nl->group})\n\n";
-    echo ' ' . date("H:i:s") . " -> début de l'envoi\n";
-    $emailsCount = $nl->sendToAll();
-    echo ' ' . date("H:i:s") . " -> fin de l'envoi\n\n";
-    echo $emailsCount . " emails ont été envoyés lors de cet envoi.\n\n";
+$issues = NewsLetter::getIssuesToSend();
+foreach ($issues as $issue) {
+    if ($issue->isEmpty()) {
+        echo "Lettre \"{$issue->title()}\" (Groupe {$issue->nl->group}) ignorée car vide.";
+    } else {
+        echo "Envoi de la lettre \"{$issue->title()}\" (Groupe {$issue->nl->group})\n\n";
+        echo ' ' . date("H:i:s") . " -> début de l'envoi\n";
+        $emailsCount = $issue->sendToAll();
+        echo ' ' . date("H:i:s") . " -> fin de l'envoi\n\n";
+        echo $emailsCount . " emails ont été envoyés lors de cet envoi.\n\n";
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
index 3df810f..26f648f 100644 (file)
@@ -689,7 +689,7 @@ class NLIssue
     {
         if ($this->state == self::STATE_PENDING) {
             $success = XDB::execute('UPDATE  newsletter_issues
-                                        SET  send_before = NULL, state = \'new\'
+                                        SET  state = \'new\'
                                       WHERE  id = {?}', $this->id);
             if ($success) {
                 $this->refresh();
@@ -999,7 +999,7 @@ class NLIssue
      */
     public function isEmpty()
     {
-        return $this->mail_title == '' || $this->mail_title == 'to be continued' || (count($this->arts == 0 && strlen($this->head) == 0));
+        return $this->title_mail == '' || $this->title_mail == 'to be continued' || (count($this->arts) == 0 && strlen($this->head) == 0);
     }
 
     /** Retrieve the 'Send before' date, in a clean format.