Automatically create a new pending issue if it doesn't exist when committing an artic...
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Sun, 6 Feb 2011 22:00:46 +0000 (23:00 +0100)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Sun, 6 Feb 2011 22:00:46 +0000 (23:00 +0100)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
include/newsletter.inc.php
include/validations/nl.inc.php

index 1f42a2d..97f57eb 100644 (file)
@@ -231,9 +231,10 @@ class NewsLetter
     }
 
     /** Return the latest pending issue of the newsletter.
+     * @p $create Whether to create an empty issue if no pending issue exist.
      * @return Either null, or a NL object.
      */
-    public function getPendingIssue()
+    public function getPendingIssue($create = false)
     {
         $res = XDB::query('SELECT  MAX(id)
                              FROM  newsletter_issues
@@ -242,6 +243,9 @@ class NewsLetter
         if ($res->numRows()) {
             $id = $res->fetchOneCell();
             return new NLIssue($id, $this);
+        } else if ($create) {
+            $id = $this->createPending();
+            return new NLIssue($id, $this);
         } else {
             return null;
         }
index 0a385ac..2c17f2b 100644 (file)
@@ -106,7 +106,7 @@ class NLReq extends Validate
 
     public function commit()
     {
-        $nl = NewsLetter::forGroup(NewsLetter::GROUP_XORG)->getPendingIssue();
+        $nl = NewsLetter::forGroup(NewsLetter::GROUP_XORG)->getPendingIssue(true);
         $nl->saveArticle($this->art);
         return true;
     }