From: <gem...@li...> - 2012-02-16 14:34:28
|
Revision: 496 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=496&view=rev Author: matijsdejong Date: 2012-02-16 14:34:19 +0000 (Thu, 16 Feb 2012) Log Message: ----------- Removed batched variables as we no longer use them (no longer using $updateTokens). Synchronize all sources now works Modified Paths: -------------- trunk/library/classes/Gems/Default/SourceAction.php trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourcesBatch.php trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php trunk/library/classes/Gems/Tracker/Source/SourceInterface.php trunk/library/classes/Gems/Tracker/TrackerInterface.php trunk/library/classes/Gems/Tracker.php trunk/library/classes/MUtil/Batch/BatchAbstract.php Modified: trunk/library/classes/Gems/Default/SourceAction.php =================================================================== --- trunk/library/classes/Gems/Default/SourceAction.php 2012-02-16 13:45:27 UTC (rev 495) +++ trunk/library/classes/Gems/Default/SourceAction.php 2012-02-16 14:34:19 UTC (rev 496) @@ -253,7 +253,7 @@ { $sourceId = $this->getSourceId(); - $batch = $this->loader->getTracker()->synchronizeSourcesBatch($sourceId, $this->loader->getCurrentUser()->getUserId(), false); + $batch = $this->loader->getTracker()->synchronizeSourcesBatch($sourceId, $this->loader->getCurrentUser()->getUserId()); if ($batch->run($this->getRequest())) { exit; @@ -275,45 +275,39 @@ } } } - /* - $source = $this->getSourceById(); - - if ($messages = $source->synchronizeSurveys($this->loader->getCurrentUser()->getUserId())) { - $this->addMessage($messages); - } else { - $this->addMessage($this->_('No changes.')); - } - - $this->afterSaveRoute($this->getRequest()); - // */ } + /** + * Synchronize survey status for the surveys in all sources + */ public function synchronizeAllAction() { - $model = $this->getModel(); - $data = $model->load(null, $this->sortKey); + //* + $batch = $this->loader->getTracker()->synchronizeSourcesBatch(null, $this->loader->getCurrentUser()->getUserId()); - if ($this->_getParam('confirmed')) { - foreach ($data as $row) { - $source = $this->getSourceById($row['gso_id_source']); + if ($batch->run($this->getRequest())) { + exit; + } else { + $this->html->h3($this->_('Synchronize all sources.')); - $this->addMessage(sprintf($this->_('Synchronization of source %s:'), $row['gso_source_name'])); - if ($messages = $source->synchronizeSurveys($this->loader->getCurrentUser()->getUserId())) { - $this->addMessage($messages); + if ($batch->isFinished()) { + $this->addMessage($batch->getMessages(true)); + $this->html->pInfo($batch->getRestartButton($this->_('Prepare recheck'), array('class' => 'actionlink'))); + } else { + if ($batch->count()) { + // Batch is loaded by Tracker + $this->html->pInfo($batch->getStartButton(sprintf($this->plural('Check %s source', 'Check %s sources', $batch->getSourceCounter()), $batch->getSourceCounter()))); + $this->html->append($batch->getPanel($this->view, $batch->getProgressPercentage() . '%')); } else { - $this->addMessage($this->_('No changes.')); + $this->html->pInfo($this->_('No sources to check.')); } } + } // */ - $this->afterSaveRoute($this->getRequest()); - } - - $this->html->h3($this->_('Synchronize all sources of surveys')); - $this->html->pInfo($this->_('Synchronization will update the status of all surveys imported into this project to the status at the sources.')); - /* $batch = new MUtil_Batch_WaitBatch(); - // $batch->setMethodPush(5); + $batch->setMethodPush(5); + $batch->progressParameterName = 'waitprogress'; // $batch->autoStart = true; // $batch->minimalStepDurationMs = 2000; if ($batch->run($this->getRequest())) { @@ -325,7 +319,7 @@ } else { // Populate the batch (from scratch). $batch->reset(); - if (! true) { + if (true) { $batch->addWaitsMs(400, 20); $batch->addWaits(2, 1, 'Har har'); $batch->addWaitsMs(20, 50); @@ -344,18 +338,6 @@ } } // */ - if ($data) { - $rdata = MUtil_Lazy::repeat($data); - $table = $this->html->table($rdata, array('class' => 'browser')); - $table->th($this->getTopicTitle()); - $table->td()->a(array('action' => 'show', MUtil_Model::REQUEST_ID => $rdata->gso_id_source), $rdata->gso_source_name); - - $this->html->h4($this->_('Are you sure you want to synchronize all survey sources?')); - $this->html->actionLink(array('confirmed' => 1), $this->_('Yes')); - $this->html->actionLink(array('action' => 'index'), $this->_('No')); - } else { - $this->html->pInfo(sprintf($this->_('No %s found'), $this->getTopic(0))); - } $this->html->actionLink(array('action' => 'index'), $this->_('Cancel')); } } Modified: trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourcesBatch.php =================================================================== --- trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourcesBatch.php 2012-02-16 13:45:27 UTC (rev 495) +++ trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourcesBatch.php 2012-02-16 14:34:19 UTC (rev 496) @@ -72,8 +72,9 @@ public function addSource($sourceData, $userId) { $this->_currentSource = $this->tracker->getSource($sourceData); - $this->_currentSource->addSynchronizeSurveyCommands($this, $userId, $this->getTokenUpdate()); + $this->_currentSource->addSynchronizeSurveyCommands($this, $userId); $this->_currentSource = null; + $this->addToSourceCounter(); } /** @@ -92,6 +93,17 @@ } /** + * Add one to the number of sources checked + * + * @param int $add + * @return int + */ + public function addToSourceCounter($add = 1) + { + return $this->addToCounter('sources', $add); + } + + /** * Add one to the number of surveys checked * * @param int $add @@ -113,46 +125,44 @@ */ public function getMessages($reset = false) { - $scounter = $this->getSurveyCounter(); + $cSources = $this->getSourceCounter(); + $cSurveys = $this->getSurveyCounter(); + $messages = parent::getMessages($reset); if (! $messages) { $messages[] = $this->translate->_('No surveys were changed.'); } - array_unshift($messages, sprintf($this->translate->_('%d surveys checked.'), $scounter)); + array_unshift($messages, sprintf($this->translate->_('%d surveys checked.'), $cSurveys)); + if ($cSources > 1) { + array_unshift($messages, sprintf($this->translate->_('%d sources checked.'), $cSources)); + } return $messages; } + /** - * Get the number of surveys checked + * Get the number of sources checked * * @return int */ - public function getSurveyCounter() + public function getSourceCounter() { - return $this->getCounter('surveys'); + return $this->getCounter('sources'); } /** - * Is tokenUpdate on or off. + * Get the number of surveys checked * - * @return boolean + * @return int */ - public function getTokenUpdate() + public function getSurveyCounter() { - return $this->getVar('tokenUpdate'); + return $this->getCounter('surveys'); } /** - * Set tokenUpdate on or off. - */ - public function setTokenUpdate($value = true) - { - $this->setVar('tokenUpdate', $value); - } - - /** * The basic steps * * @param int $sourceId Modified: trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php =================================================================== --- trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php 2012-02-16 13:45:27 UTC (rev 495) +++ trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php 2012-02-16 14:34:19 UTC (rev 496) @@ -300,9 +300,8 @@ * * @param Gems_Tracker_Batch_SynchronizeSourcesBatch $batch * @param int $userId Id of the user who takes the action (for logging) - * @param bool $updateTokens Wether the tokens should be updated or not, default is true */ - public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizeSourcesBatch $batch, $userId, $updateTokens = true) + public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizeSourcesBatch $batch, $userId) { // Surveys in LS $lsDb = $this->getSourceDatabase(); @@ -317,15 +316,15 @@ foreach ($gemsSurveys as $surveyId => $sourceSurveyId) { if (isset($lsSurveys[$sourceSurveyId])) { - $batch->addSourceFunction('checkSurvey', $sourceSurveyId, $surveyId, $userId, $updateTokens); + $batch->addSourceFunction('checkSurvey', $sourceSurveyId, $surveyId, $userId); } else { - $batch->addSourceFunction('checkSurvey', null, $surveyId, $userId, $updateTokens); + $batch->addSourceFunction('checkSurvey', null, $surveyId, $userId); } $batch->addToSurveyCounter(); } foreach (array_diff($lsSurveys, $gemsSurveys) as $sourceSurveyId) { - $batch->addSourceFunction('checkSurvey', $sourceSurveyId, null, $userId, $updateTokens); + $batch->addSourceFunction('checkSurvey', $sourceSurveyId, null, $userId); $batch->addToSurveyCounter(); } } @@ -362,9 +361,8 @@ * @param int $sourceSurveyId * @param int $surveyId * @param int $userId - * @param boolean $updateTokens */ - public function checkSurvey($sourceSurveyId, $surveyId, $userId, $updateTokens) + public function checkSurvey($sourceSurveyId, $surveyId, $userId) { $messages = array(); $survey = $this->tracker->getSurvey($surveyId); Modified: trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php =================================================================== --- trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php 2012-02-16 13:45:27 UTC (rev 495) +++ trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php 2012-02-16 14:34:19 UTC (rev 496) @@ -227,11 +227,13 @@ * * @param Gems_Tracker_Batch_SynchronizeSourcesBatch $batch * @param int $userId Id of the user who takes the action (for logging) - * @param bool $updateTokens Wether the tokens should be updated or not, default is true */ - public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizeSourcesBatch $batch, $userId, $updateTokens = true) + public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizeSourcesBatch $batch, $userId) { - // Do nothing is default + // Do nothing or add the old method is the default + if (method_exists($this, 'synchronizeSurveys')) { + $batch->addSourceFunction('synchronizeSurveys', $userId); + } } /** Modified: trunk/library/classes/Gems/Tracker/Source/SourceInterface.php =================================================================== --- trunk/library/classes/Gems/Tracker/Source/SourceInterface.php 2012-02-16 13:45:27 UTC (rev 495) +++ trunk/library/classes/Gems/Tracker/Source/SourceInterface.php 2012-02-16 14:34:19 UTC (rev 496) @@ -59,9 +59,8 @@ * * @param Gems_Tracker_Batch_SynchronizeSourcesBatch $batch * @param int $userId Id of the user who takes the action (for logging) - * @param bool $updateTokens Wether the tokens should be updated or not, default is true */ - public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizeSourcesBatch $batch, $userId, $updateTokens = true); + public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizeSourcesBatch $batch, $userId); /** * Inserts the token in the source (if needed) and sets those attributes the source wants to set. Modified: trunk/library/classes/Gems/Tracker/TrackerInterface.php =================================================================== --- trunk/library/classes/Gems/Tracker/TrackerInterface.php 2012-02-16 13:45:27 UTC (rev 495) +++ trunk/library/classes/Gems/Tracker/TrackerInterface.php 2012-02-16 14:34:19 UTC (rev 496) @@ -285,11 +285,10 @@ * * @param int $sourceId A source identifier * @param int $userId Id of the user who takes the action (for logging) - * @param boolean $updateTokens When true each individual token must be synchronized as well * @return Gems_Tracker_Batch_SynchronizeSourcesBatch A batch to process the synchronization */ - public function synchronizeSourcesBatch($sourceId = null, $userId = null, $updateTokens = false); - + public function synchronizeSourcesBatch($sourceId = null, $userId = null); + /** * Recalculates all token dates, timing and results * and outputs text messages. Modified: trunk/library/classes/Gems/Tracker.php =================================================================== --- trunk/library/classes/Gems/Tracker.php 2012-02-16 13:45:27 UTC (rev 495) +++ trunk/library/classes/Gems/Tracker.php 2012-02-16 14:34:19 UTC (rev 496) @@ -862,19 +862,13 @@ * * @param int $sourceId A source identifier * @param int $userId Id of the user who takes the action (for logging) - * @param boolean $updateTokens When true each individual token must be synchronized as well * @return Gems_Tracker_Batch_SynchronizeSourcesBatch A batch to process the synchronization */ - public function synchronizeSourcesBatch($sourceId = null, $userId = null, $updateTokens = false) + public function synchronizeSourcesBatch($sourceId = null, $userId = null) { $batch_id = 'source_synch' . ($sourceId ? '_' . $sourceId : ''); $batch = $this->_loadClass('Batch_SynchronizeSourcesBatch', true, array($batch_id)); - if ($updateTokens != $batch->getTokenUpdate()) { - $batch->reset(); - } - $batch->setTokenUpdate($updateTokens); - if (! $batch->isLoaded()) { if ($sourceId) { $sources = array($sourceId); Modified: trunk/library/classes/MUtil/Batch/BatchAbstract.php =================================================================== --- trunk/library/classes/MUtil/Batch/BatchAbstract.php 2012-02-16 13:45:27 UTC (rev 495) +++ trunk/library/classes/MUtil/Batch/BatchAbstract.php 2012-02-16 14:34:19 UTC (rev 496) @@ -203,7 +203,7 @@ $command['parameters'] = $params; // MUtil_Echo::track($command); - + return $command; } @@ -477,30 +477,6 @@ } /** - * Batch duration variable storage for the process - * - * @param string $name Name - * @return mixed The scalar value, if any - */ - protected function getVar($name) - { - if (isset($this->_session->vars[$name])) { - return $this->_session->vars[$name]; - } - } - - /** - * Batch duration variable storage for the process - * - * @param string $name Name - * @return boolean - */ - protected function hasVar($name) - { - return array_key_exists($name, $this->_session->vars); - } - - /** * Return true after commands all have been ran. * * @return boolean @@ -553,7 +529,6 @@ $this->_session->finished = false; $this->_session->messages = array(); $this->_session->processed = 0; - $this->_session->vars = array(); return $this; } @@ -771,21 +746,6 @@ } /** - * Batch duration variable storage for the process - * - * @param string $name Name - * @param mixed $value Scalar value - */ - protected function setVar($name, $value) - { - if (! MUtil_Ra::isScalar($value)) { - throw new MUtil_Batch_BatchException("Non scalar batch value named '$name'."); - } - - $this->_session->vars[$name] = $value; - } - - /** * Progress a single step on the command stack * * @return boolean @@ -810,14 +770,4 @@ return false; } } - - /** - * Batch duration variable storage for the process - * - * @param string $name Name - */ - protected function unsetVar($name) - { - unset($this->_session->vars[$name]); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |