Added publication cronjob for delayed articles
authorMarcel Werk <burntime@woltlab.com>
Thu, 9 Jun 2016 10:32:28 +0000 (12:32 +0200)
committerMarcel Werk <burntime@woltlab.com>
Thu, 9 Jun 2016 10:32:28 +0000 (12:32 +0200)
com.woltlab.wcf/cronjob.xml
wcfsetup/install/files/lib/system/cronjob/ArticlePublicationCronjob.class.php [new file with mode: 0644]

index b8bab7a83ed5bc4c642e17d38733b38fd69f936a..ee7d596c120ac1428166a957881dc8fc7a19fc78 100644 (file)
                        <canbeedited>1</canbeedited>
                        <canbedisabled>1</canbedisabled>
                </cronjob>
+               
+               <cronjob name="articlePublication">
+                       <classname>wcf\system\cronjob\ArticlePublicationCronjob</classname>
+                       <description><![CDATA[Publishes delayed articles]]></description>
+                       <description language="de"><![CDATA[Veröffentlicht Artikel]]></description>
+                       <startminute>*/5</startminute>
+                       <starthour>*</starthour>
+                       <startdom>*</startdom>
+                       <startmonth>*</startmonth>
+                       <startdow>*</startdow>
+                       <canbeedited>1</canbeedited>
+                       <canbedisabled>1</canbedisabled>
+               </cronjob>
        </import>
        
        <delete>
diff --git a/wcfsetup/install/files/lib/system/cronjob/ArticlePublicationCronjob.class.php b/wcfsetup/install/files/lib/system/cronjob/ArticlePublicationCronjob.class.php
new file mode 100644 (file)
index 0000000..1296b2c
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+namespace wcf\system\cronjob;
+use wcf\data\article\ArticleEditor;
+use wcf\data\article\ArticleList;
+use wcf\data\cronjob\Cronjob;
+
+/**
+ * Publishes delayed articles.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.cronjob
+ * @category   Community Framework
+ * @since       2.2
+ */
+class ArticlePublicationCronjob extends AbstractCronjob {
+       /**
+        * @inheritDoc
+        */
+       public function execute(Cronjob $cronjob) {
+               parent::execute($cronjob);
+               
+               $articleList = new ArticleList();
+               $articleList->getConditionBuilder()->add('article.publicationStatus = ?', [2]);
+               $articleList->getConditionBuilder()->add('article.publicationDate > ?', [0]);
+               $articleList->getConditionBuilder()->add('article.publicationDate <= ?', [TIME_NOW]);
+               $articleList->decoratorClassName = ArticleEditor::class;
+               $articleList->readObjects();
+               
+               foreach ($articleList as $editor) {
+                       /** @var ArticleEditor $editor */
+                       $editor->update([
+                               'time' => $editor->publicationDate,
+                               'publicationStatus' => 1,
+                               'publicationDate' => 0
+                       ]);
+               }
+       }
+}