Get rid of useless class attribute CronjobScheduler::$cronjobEditors
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 30 Jun 2020 12:16:42 +0000 (14:16 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 30 Jun 2020 13:00:25 +0000 (15:00 +0200)
Just use a simple return value here. It avoids having to carefully manage
class state.

wcfsetup/install/files/lib/system/cronjob/CronjobScheduler.class.php

index 784ecf3c8d2c5efc8052be6681d6caa117eb89bc..d36d2aec3d16887df1ede5f6ec3bd4e984a17d58 100644 (file)
@@ -24,12 +24,6 @@ class CronjobScheduler extends SingletonFactory {
         */
        protected $cache = [];
        
-       /**
-        * list of editors for outstanding cronjobs
-        * @var CronjobEditor[]
-        */
-       protected $cronjobEditors = [];
-       
        /**
         * @inheritDoc
         */
@@ -49,12 +43,12 @@ class CronjobScheduler extends SingletonFactory {
                $this->resetFailedCronjobs();
                
                // get outstanding cronjobs
-               $this->loadCronjobs();
+               $cronjobEditors = $this->loadCronjobs();
                
                // clear cache
                self::clearCache();
                
-               foreach ($this->cronjobEditors as $cronjobEditor) {
+               foreach ($cronjobEditors as $cronjobEditor) {
                        // mark cronjob as being executed
                        $cronjobEditor->update([
                                'state' => Cronjob::EXECUTING
@@ -199,6 +193,8 @@ class CronjobScheduler extends SingletonFactory {
                                Cronjob::READY,
                                TIME_NOW
                        ]);
+                       
+                       $cronjobEditors = [];
                        /** @var Cronjob $cronjob */
                        while ($cronjob = $statement->fetchObject(Cronjob::class)) {
                                $cronjobEditor = new CronjobEditor($cronjob);
@@ -217,15 +213,16 @@ class CronjobScheduler extends SingletonFactory {
                                
                                $cronjobEditor->update($data);
                                
-                               $this->cronjobEditors[] = $cronjobEditor;
+                               $cronjobEditors[] = $cronjobEditor;
                        }
                        WCF::getDB()->commitTransaction();
                        $committed = true;
+                       
+                       return $cronjobEditors;
                }
                finally {
                        if (!$committed) {
                                WCF::getDB()->rollBackTransaction();
-                               $this->cronjobEditors = [];
                        }
                }
        }