Added cronjob execution
authorMarcel Werk <burntime@woltlab.com>
Wed, 30 May 2012 20:57:09 +0000 (22:57 +0200)
committerMarcel Werk <burntime@woltlab.com>
Wed, 30 May 2012 20:57:09 +0000 (22:57 +0200)
com.woltlab.wcf/template/headInclude.tpl
wcfsetup/install/files/lib/data/cronjob/CronjobAction.class.php
wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/files/lib/system/WCFACP.class.php
wcfsetup/install/files/lib/system/cronjob/CronjobScheduler.class.php

index e5070bb11ad979c3f471c2002970e1f3e1050d84..50da11794ed772924731bab23edd90c2d9b07e67 100644 (file)
                WCF.Dropdown.init();
                
                {event name='javascriptInit'}
+
+               {if $executeCronjobs}
+                       new WCF.Action.Proxy({
+                               autoSend: true,
+                               data: {
+                                       className: 'wcf\\data\\cronjob\\CronjobAction',
+                                       actionName: 'executeCronjobs'
+                               },
+                               showLoadingOverlay: false,
+                               failure: function() {
+                                       return false;
+                               }
+                       });
+               {/if}
        });
        //]]>
 </script>
index b2406050c6a7212c7e70c5b193d435d4c22199a2..e01e9577158ee1573581ac9b9949ef965ff12170 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\data\cronjob;
 use wcf\data\cronjob\log\CronjobLogEditor;
 use wcf\data\AbstractDatabaseObjectAction;
+use wcf\system\cronjob\CronjobScheduler;
 use wcf\system\exception\ValidateActionException;
 use wcf\system\WCF;
 use wcf\util\DateUtil;
@@ -37,6 +38,11 @@ class CronjobAction extends AbstractDatabaseObjectAction {
         */
        protected $permissionsUpdate = array('admin.system.cronjob.canEditCronjob');
        
+       /**
+        * @see wcf\data\AbstractDatabaseObjectAction::$allowGuestAccess
+        */
+       protected $allowGuestAccess = array('executeCronjobs');
+       
        /**
         * Validates permissions and parameters
         */
@@ -160,4 +166,16 @@ class CronjobAction extends AbstractDatabaseObjectAction {
                
                return $return;
        }
+       
+       /**
+        * Validates permissions and parameters
+        */
+       public function validateExecuteCronjobs() {}
+       
+       /**
+        * Executes open cronjobs.
+        */
+       public function executeCronjobs() {
+               CronjobScheduler::getInstance()->executeCronjobs();
+       }
 }
index 868ab29a107d0007d22d2729a2d4bdef71d55a47..b5d6478486f72150360cd165b57f6f1e4c11101d 100644 (file)
@@ -1,12 +1,11 @@
 <?php
 namespace wcf\system;
-use wcf\util\StringStack;
-
 use wcf\data\application\Application;
 use wcf\data\package\Package;
 use wcf\data\package\PackageCache;
 use wcf\system\application\ApplicationHandler;
 use wcf\system\cache\CacheHandler;
+use wcf\system\cronjob\CronjobScheduler;
 use wcf\system\database\statement\PreparedStatement;
 use wcf\system\language\LanguageFactory;
 use wcf\system\package\PackageInstallationDispatcher;
@@ -15,6 +14,7 @@ use wcf\system\session\SessionHandler;
 use wcf\system\template\TemplateEngine;
 use wcf\system\user\storage\UserStorageHandler;
 use wcf\system\exception;
+use wcf\util\StringStack;
 use wcf\util;
 
 // try to disable execution time limit
@@ -121,6 +121,7 @@ class WCF {
                $this->initSession();
                $this->initLanguage();
                $this->initTPL();
+               $this->initCronjobs();
                $this->initBlacklist();
                $this->initCoreObjects();
                $this->initApplications();
@@ -647,4 +648,13 @@ class WCF {
                
                return $baseHref . 'index.php' . $path . '#' . $fragment;
        }
+       
+       /**
+        * Initialises the cronjobs.
+        */
+       protected function initCronjobs() {
+               if (defined('PACKAGE_ID')) {
+                       self::getTPL()->assign('executeCronjobs', CronjobScheduler::getInstance()->getNextExec() < TIME_NOW);
+               }
+       }
 }
index f2f72d9939faf2372116d225cd8ce5c014a2a10e..6403d764d862b1fb93aa9d3aae543694d875397b 100644 (file)
@@ -38,6 +38,7 @@ class WCFACP extends WCF {
                $this->initSession();
                $this->initLanguage();
                $this->initTPL();
+               $this->initCronjobs();
                $this->initBlacklist();
                $this->initAuth();
                $this->initCoreObjects();
index 92875510b2148344771f18768977189c59f22259..ac3cfd97de61d83f7bc913f4da8b75c8f05c67e5 100644 (file)
@@ -91,6 +91,15 @@ class CronjobScheduler extends SingletonFactory {
                }
        }
        
+       /**
+        * Returns the next execution time.
+        * 
+        * @return      integer
+        */
+       public function getNextExec() {
+               return $this->cache['nextExec'];
+       }
+       
        /**
         * Loads outstanding cronjobs.
         */