Fixed worker progress (calculation mismatch)
authorAlexander Ebert <ebert@woltlab.com>
Wed, 14 Sep 2011 13:45:15 +0000 (15:45 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 14 Sep 2011 13:45:15 +0000 (15:45 +0200)
wcfsetup/install/files/lib/acp/action/WorkerProxyAction.class.php
wcfsetup/install/files/lib/system/worker/AbstractWorker.class.php

index 3bb3f904ad47a96b1e0b6d4842e7ca514926425b..ac0268b45b11bc6d58657e088578fe705093275c 100644 (file)
@@ -28,7 +28,7 @@ class WorkerProxyAction extends AbstractSecureAction {
         * loop counter
         * @var integer
         */
-       protected $loopCount = 0;
+       protected $loopCount = -1;
        
        /**
         * parameters for worker action
@@ -91,21 +91,22 @@ class WorkerProxyAction extends AbstractSecureAction {
        public function execute() {
                parent::execute();
                
-               // initialize worker
-               if ($this->loopCount == 0) {
+               if ($this->loopCount == -1) {
                        $this->sendResponse();
                }
                
+               // init worker
                $this->worker = new $this->className($this->parameters);
                $this->worker->setLoopCount($this->loopCount);
+               
+               // validate worker parameters
                $this->worker->validate();
-               $returnValues = array();
                
+               // calculate progress, triggers countObjects()
                $progress = $this->worker->getProgress();
-               $returnValues['progress'] = $progress;
-               if ($progress < 100) {
-                       $this->worker->execute();
-               }
+               
+               // execute worker
+               $this->worker->execute();
                
                // send current state
                $this->sendResponse($progress, $this->worker->getParameters());
@@ -124,13 +125,13 @@ class WorkerProxyAction extends AbstractSecureAction {
                // build return values
                $returnValues = array(
                        'className' => $this->className,
-                       'loopCount' => $this->loopCount,
+                       'loopCount' => ($this->loopCount + 1),
                        'parameters' => $parameters,
                        'progress' => $progress
                );
                
                // include template on startup
-               if ($progress == 0) {
+               if ($this->loopCount == -1) {
                        $returnValues['template'] = WCF::getTPL()->fetch('worker');
                }
                
index 7c65c8a7dc25fd73ba1ca11551ef819b8030f7dc..bd6c43a3c159b90bee0168500c81c336d26d7f08 100644 (file)
@@ -65,7 +65,8 @@ abstract class AbstractWorker implements IWorker {
                        return 100;
                }
                
-               return ceil(($this->loopCount / ceil($this->count / $this->limit)) * 100);
+               $progress = (($this->limit * ($this->loopCount + 1)) / $this->count) * 100;
+               return round($progress, 0);
        }
        
        /**