Introduced constants for publication status of articles
authorMarcel Werk <burntime@woltlab.com>
Mon, 13 Jun 2016 17:20:10 +0000 (19:20 +0200)
committerMarcel Werk <burntime@woltlab.com>
Mon, 13 Jun 2016 17:20:10 +0000 (19:20 +0200)
wcfsetup/install/files/lib/acp/form/ArticleAddForm.class.php
wcfsetup/install/files/lib/acp/form/ArticleEditForm.class.php
wcfsetup/install/files/lib/data/article/AccessibleArticleList.class.php
wcfsetup/install/files/lib/data/article/Article.class.php
wcfsetup/install/files/lib/data/article/CategoryArticleList.class.php
wcfsetup/install/files/lib/system/cronjob/ArticlePublicationCronjob.class.php
wcfsetup/install/files/lib/system/search/ArticleSearch.class.php

index 4df62712a20e599fc437d62db35a369e9db276fe..e944d04a485b373fdec4173ddc6680f01965ce83 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\acp\form;
+use wcf\data\article\Article;
 use wcf\data\article\category\ArticleCategory;
 use wcf\data\article\ArticleAction;
 use wcf\data\category\CategoryNodeTree;
@@ -84,7 +85,7 @@ class ArticleAddForm extends AbstractForm {
         * publication status
         * @var integer
         */
-       public $publicationStatus = 1;
+       public $publicationStatus = Article::PUBLISHED;
        
        /**
         * publication date (ISO 8601)
@@ -189,7 +190,7 @@ class ArticleAddForm extends AbstractForm {
                }
                if (!empty($_POST['enableComments'])) $this->enableComments = 1;
                if (isset($_POST['publicationStatus'])) $this->publicationStatus = intval($_POST['publicationStatus']);
-               if ($this->publicationStatus == 2 && isset($_POST['publicationDate'])) {
+               if ($this->publicationStatus == Article::DELAYED_PUBLICATION && isset($_POST['publicationDate'])) {
                        $this->publicationDate = $_POST['publicationDate'];
                        $this->publicationDateObj = \DateTime::createFromFormat('Y-m-d\TH:i:sP', $this->publicationDate);
                }
@@ -256,10 +257,10 @@ class ArticleAddForm extends AbstractForm {
                }
                
                // publication status
-               if ($this->publicationStatus < 0 || $this->publicationStatus > 2) {
+               if ($this->publicationStatus != Article::UNPUBLISHED && $this->publicationStatus != Article::PUBLISHED && $this->publicationStatus != Article::DELAYED_PUBLICATION) {
                        throw new UserInputException('publicationStatus');
                }
-               if ($this->publicationStatus == 2) {
+               if ($this->publicationStatus == Article::DELAYED_PUBLICATION) {
                        if (empty($this->publicationDate)) {
                                throw new UserInputException('publicationDate');
                        }
@@ -334,7 +335,7 @@ class ArticleAddForm extends AbstractForm {
                        'time' => $this->timeObj->getTimestamp(),
                        'categoryID' => $this->categoryID,
                        'publicationStatus' => $this->publicationStatus,
-                       'publicationDate' => ($this->publicationStatus == 2 ? $this->publicationDateObj->getTimestamp() : 0),
+                       'publicationDate' => ($this->publicationStatus == Article::DELAYED_PUBLICATION ? $this->publicationDateObj->getTimestamp() : 0),
                        'enableComments' => $this->enableComments,
                        'userID' => $this->author->userID,
                        'username' => $this->author->username,
@@ -353,7 +354,8 @@ class ArticleAddForm extends AbstractForm {
                // reset variables
                $this->publicationDate = '';
                $this->categoryID = 0;
-               $this->publicationStatus = $this->enableComments = 1;
+               $this->publicationStatus = Article::PUBLISHED;
+               $this->enableComments = ARTICLE_ENABLE_COMMENTS_DEFAULT_VALUE;
                $this->title = $this->teaser = $this->content = $this->images = $this->imageID = $this->tags = [];
                
                $this->setDefaultValues();
index 437ad04b873974e6c50c7ed9c30385f7ea021b3f..9ebf68e911fe7b03a720f292c18bdcb6a8aeb7a2 100644 (file)
@@ -90,7 +90,7 @@ class ArticleEditForm extends ArticleAddForm {
                $data = [
                        'categoryID' => $this->categoryID,
                        'publicationStatus' => $this->publicationStatus,
-                       'publicationDate' => ($this->publicationStatus == 2 ? $this->publicationDateObj->getTimestamp() : 0),
+                       'publicationDate' => ($this->publicationStatus == Article::DELAYED_PUBLICATION ? $this->publicationDateObj->getTimestamp() : 0),
                        'enableComments' => $this->enableComments,
                        'userID' => $this->author->userID,
                        'username' => $this->author->username,
index 147ff1318a5d049a095a7570adeb0c0478abd17d..ce215fa7ae44e1c0a2b0613098c004a299bff9b5 100644 (file)
@@ -27,7 +27,7 @@ class AccessibleArticleList extends ViewableArticleList {
                }
                else {
                        $this->getConditionBuilder()->add('article.categoryID IN (?)', [$accessibleCategoryIDs]);
-                       $this->getConditionBuilder()->add('article.publicationStatus = ?', [1]);
+                       $this->getConditionBuilder()->add('article.publicationStatus = ?', [Article::PUBLISHED]);
                }
        }
 }
index d3988d12821b5961e63a37e385d43512e472b7bf..e7884621005c674c00cf93c76ef6898ff17bc304 100644 (file)
@@ -42,6 +42,21 @@ class Article extends DatabaseObject implements ILinkableObject {
         */
        protected static $databaseTableIndexName = 'articleID';
        
+       /**
+        * indicates that article is unpublished
+        */
+       const UNPUBLISHED = 0;
+       
+       /**
+        * indicates that article is published
+        */
+       const PUBLISHED = 1;
+       
+       /**
+        * indicates that the publication of an article is delayed
+        */
+       const DELAYED_PUBLICATION = 2;
+       
        /**
         * article content grouped by language id
         * @var ArticleContent[]
index 4df347d21a392431386e14f4de4fe46e62ce6391..cae686705ed1026a9ab7d116a31deceb8e74ae49 100644 (file)
@@ -40,6 +40,6 @@ class CategoryArticleList extends AccessibleArticleList {
                }
                
                $this->getConditionBuilder()->add('article.categoryID IN (?)', [$categoryIDs]);
-               $this->getConditionBuilder()->add('article.publicationStatus = ?', [1]);
+               $this->getConditionBuilder()->add('article.publicationStatus = ?', [Article::PUBLISHED]);
        }
 }
index 1296b2c4d8895d6763d5c72c4c71c4c771f99dc7..d2f997b1f32b7811445c5441cd2ab610499ba385 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\cronjob;
+use wcf\data\article\Article;
 use wcf\data\article\ArticleEditor;
 use wcf\data\article\ArticleList;
 use wcf\data\cronjob\Cronjob;
@@ -23,7 +24,7 @@ class ArticlePublicationCronjob extends AbstractCronjob {
                parent::execute($cronjob);
                
                $articleList = new ArticleList();
-               $articleList->getConditionBuilder()->add('article.publicationStatus = ?', [2]);
+               $articleList->getConditionBuilder()->add('article.publicationStatus = ?', [Article::DELAYED_PUBLICATION]);
                $articleList->getConditionBuilder()->add('article.publicationDate > ?', [0]);
                $articleList->getConditionBuilder()->add('article.publicationDate <= ?', [TIME_NOW]);
                $articleList->decoratorClassName = ArticleEditor::class;
@@ -33,7 +34,7 @@ class ArticlePublicationCronjob extends AbstractCronjob {
                        /** @var ArticleEditor $editor */
                        $editor->update([
                                'time' => $editor->publicationDate,
-                               'publicationStatus' => 1,
+                               'publicationStatus' => Article::PUBLISHED,
                                'publicationDate' => 0
                        ]);
                }
index bed9e8c0c66d45369c6ead64f765a8b378f9ec50..93546a5ed15fa1c1ff178ae65a8b66c0e8943c22 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\search;
+use wcf\data\article\Article;
 use wcf\data\article\category\ArticleCategory;
 use wcf\data\article\content\SearchResultArticleContent;
 use wcf\data\article\content\SearchResultArticleContentList;
@@ -110,7 +111,7 @@ class ArticleSearch extends AbstractSearchableObjectType {
                }
                
                $conditionBuilder = new PreparedStatementConditionBuilder();
-               $conditionBuilder->add('wcf'.WCF_N.'_article.categoryID IN (?) AND wcf'.WCF_N.'_article.publicationStatus = ?', [$this->articleCategoryIDs, 1]);
+               $conditionBuilder->add('wcf'.WCF_N.'_article.categoryID IN (?) AND wcf'.WCF_N.'_article.publicationStatus = ?', [$this->articleCategoryIDs, Article::PUBLISHED]);
                
                return $conditionBuilder;
        }