From b8bcbe021ba5e7464897a0701a5f78fb8a6d3c0f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Sun, 6 Feb 2011 23:00:46 +0100 Subject: [PATCH 1/1] Automatically create a new pending issue if it doesn't exist when committing an article for the NL MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- include/newsletter.inc.php | 6 +++++- include/validations/nl.inc.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 1f42a2d..97f57eb 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -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; } diff --git a/include/validations/nl.inc.php b/include/validations/nl.inc.php index 0a385ac..2c17f2b 100644 --- a/include/validations/nl.inc.php +++ b/include/validations/nl.inc.php @@ -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; } -- 2.1.4