From ffbd2df6b510b1544dd621690866fae56e4bdd7c Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 14 Sep 2011 15:45:15 +0200 Subject: [PATCH] Fixed worker progress (calculation mismatch) --- .../acp/action/WorkerProxyAction.class.php | 21 ++++++++++--------- .../system/worker/AbstractWorker.class.php | 3 ++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/action/WorkerProxyAction.class.php b/wcfsetup/install/files/lib/acp/action/WorkerProxyAction.class.php index 3bb3f904ad..ac0268b45b 100644 --- a/wcfsetup/install/files/lib/acp/action/WorkerProxyAction.class.php +++ b/wcfsetup/install/files/lib/acp/action/WorkerProxyAction.class.php @@ -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'); } diff --git a/wcfsetup/install/files/lib/system/worker/AbstractWorker.class.php b/wcfsetup/install/files/lib/system/worker/AbstractWorker.class.php index 7c65c8a7dc..bd6c43a3c1 100644 --- a/wcfsetup/install/files/lib/system/worker/AbstractWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/AbstractWorker.class.php @@ -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); } /** -- 2.20.1