Add options support for cronjobs
authorMatthias Schmidt <gravatronics@live.com>
Fri, 22 May 2015 16:37:05 +0000 (18:37 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 22 May 2015 16:37:05 +0000 (18:37 +0200)
This implementation is as close to the case where the options
would be checked in the cronjob itself.

CHANGELOG.md
wcfsetup/install/files/lib/data/cronjob/Cronjob.class.php
wcfsetup/install/files/lib/data/cronjob/CronjobAction.class.php
wcfsetup/install/files/lib/system/cronjob/CronjobScheduler.class.php
wcfsetup/install/files/lib/system/package/plugin/CronjobPackageInstallationPlugin.class.php
wcfsetup/setup/db/install.sql

index 8307cdf49194dd45adaaa07a40ba54bd10ff70a0..5a66480d610451628309b528ff81300ae7ab5165 100644 (file)
@@ -4,6 +4,7 @@
 
 ### 2.2.0 Alpha 1 (XXXX-YY-ZZ)
 
+* `options` support for cronjobs.
 * `permissions` and `options` support for event listeners.
 * `permissions` and `options` support for template listeners.
 * `wcf\data\TDatabaseObjectOptions` and `wcf\data\TDatabaseObjectPermissions` for database object-bound options and permissions validation.
index 4bc9e888f8824364cb640a46850e78c8446b680d..0a270a9cd0704acec53ef4bbf1e69ec7e074a0a4 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\data\cronjob;
 use wcf\data\DatabaseObject;
+use wcf\data\TDatabaseObjectOptions;
 use wcf\util\CronjobUtil;
 
 /**
@@ -14,6 +15,8 @@ use wcf\util\CronjobUtil;
  * @category   Community Framework
  */
 class Cronjob extends DatabaseObject {
+       use TDatabaseObjectOptions;
+       
        /**
         * @see \wcf\data\DatabaseObject::$databaseTableName
         */
index beb4276969548ffac459588cc2c04c541c4bd451..205d17486deddba88e7df20447661e7569671f34 100644 (file)
@@ -126,10 +126,17 @@ class CronjobAction extends AbstractDatabaseObjectAction implements IToggleActio
                        
                        // execute cronjob
                        $exception = null;
-                       try {
-                               $executable->execute(new Cronjob($cronjob->cronjobID));
+                       
+                       // check if all required options are set for cronjob to be executed
+                       // note: a general log is created to avoid confusion why a cronjob
+                       // apperently is not executed while that is indeed the correct internal
+                       // behavior
+                       if ($cronjob->validateOptions()) {
+                               try {
+                                       $executable->execute(new Cronjob($cronjob->cronjobID));
+                               }
+                               catch (\Exception $exception) { }
                        }
-                       catch (\Exception $exception) { }
                        
                        CronjobLogEditor::create(array(
                                'cronjobID' => $cronjob->cronjobID,
index ea460c5b9d2a85eca8cc52ae7826286466d9c7e3..0bd1430e3f66dc85261d93f1b96ccc777aa03092 100644 (file)
@@ -67,11 +67,20 @@ class CronjobScheduler extends SingletonFactory {
                        ));
                        $logEditor = new CronjobLogEditor($log);
                        
-                       try {
-                               $this->executeCronjob($cronjobEditor, $logEditor);
+                       // check if all required options are set for cronjob to be executed
+                       // note: a general log is created to avoid confusion why a cronjob
+                       // apperently is not executed while that is indeed the correct internal
+                       // behavior
+                       if ($cronjobEditor->validateOptions()) {
+                               try {
+                                       $this->executeCronjob($cronjobEditor, $logEditor);
+                               }
+                               catch (SystemException $e) {
+                                       $this->logResult($logEditor, $e);
+                               }
                        }
-                       catch (SystemException $e) {
-                               $this->logResult($logEditor, $e);
+                       else {
+                               $this->logResult($logEditor);
                        }
                        
                        // get time of next execution
index 1364bd0223e6d4d1bd383ae803232186ebfb1aa9..f8545ac681af0422c56e5020395f30bbde98b218 100644 (file)
@@ -61,6 +61,7 @@ class CronjobPackageInstallationPlugin extends AbstractXMLPackageInstallationPlu
                        'className' => (isset($data['elements']['classname'])) ? $data['elements']['classname'] : '',
                        'description' => (isset($data['elements']['description'])) ? $data['elements']['description'] : '',
                        'isDisabled' => (isset($data['elements']['isdisabled'])) ? intval($data['elements']['isdisabled']) : 0,
+                       'options' => (isset($data['elements']['options'])) ? $data['elements']['options'] : '',
                        'startDom' => $data['elements']['startdom'],
                        'startDow' => $data['elements']['startdow'],
                        'startHour' => $data['elements']['starthour'],
index 3e66b04853de0e74a36adbb6df83a187c8d04059..e38e02c01a16b2fc57d5b641504901d0d52158cd 100644 (file)
@@ -321,7 +321,8 @@ CREATE TABLE wcf1_cronjob (
        canBeEdited TINYINT(1) NOT NULL DEFAULT 1,
        canBeDisabled TINYINT(1) NOT NULL DEFAULT 1,
        state TINYINT(1) NOT NULL DEFAULT 0,
-       failCount TINYINT(1) NOT NULL DEFAULT 0
+       failCount TINYINT(1) NOT NULL DEFAULT 0,
+       options TEXT
 );
 
 DROP TABLE IF EXISTS wcf1_cronjob_log;