From: <gem...@li...> - 2012-02-16 13:45:34
|
Revision: 495 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=495&view=rev Author: matijsdejong Date: 2012-02-16 13:45:27 +0000 (Thu, 16 Feb 2012) Log Message: ----------- Added improved error reporting to BatchAbstract.php Restarting after failure shows correct starting percentage. (Though bar display still inadequate.) Source synchronization works, but does not yet the update tokens attributes. Modified Paths: -------------- trunk/library/classes/Gems/Default/SourceAction.php trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php trunk/library/classes/Gems/Tracker/Batch/ProcessTokensBatch.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/Survey.php trunk/library/classes/Gems/Tracker/TrackerInterface.php trunk/library/classes/Gems/Tracker.php trunk/library/classes/MUtil/Batch/BatchAbstract.php trunk/library/classes/MUtil/Batch/BatchPull.js Modified: trunk/library/classes/Gems/Default/SourceAction.php =================================================================== --- trunk/library/classes/Gems/Default/SourceAction.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Default/SourceAction.php 2012-02-16 13:45:27 UTC (rev 495) @@ -102,6 +102,9 @@ $bridge->addExhibitor('gso_last_synch'); } + /** + * Check all the tokens for a single source + */ public function checkAction() { $sourceId = $this->getSourceId(); @@ -114,7 +117,7 @@ } else { $this->html->h3( sprintf($this->_('Checking survey results for %s source.'), - $this->db->fetchOne("SELECT gso_source_name FROM gems__sources WHERE gso_id_source = ?", $sourceId))); + $this->db->fetchOne("SELECT gso_source_name FROM gems__sources WHERE gso_id_source = ?", $sourceId))); if ($batch->isFinished()) { $this->addMessage($batch->getMessages(true)); @@ -122,8 +125,8 @@ } else { if ($batch->count()) { // Batch is loaded by Tracker - $this->html->pInfo($batch->getStartButton(sprintf($this->_('Check %s tokens'), $batch->count()))); - $this->html->append($batch->getPanel($this->view, '0%')); + $this->html->pInfo($batch->getStartButton(sprintf($this->_('Check %s tokens'), $batch->getTokenCount()))); + $this->html->append($batch->getPanel($this->view, $batch->getProgressPercentage() . '%')); } else { $this->html->pInfo($this->_('No tokens to check.')); } @@ -131,6 +134,9 @@ } } + /** + * Check all the tokens for all sources + */ public function checkAllAction() { $batch = $this->loader->getTracker()->recalculateTokensBatch('surveyCheckAll', $this->loader->getCurrentUser()->getUserId()); @@ -146,8 +152,8 @@ } else { if ($batch->count()) { // Batch is loaded by Tracker - $this->html->pInfo($batch->getStartButton(sprintf($this->_('Check %s tokens'), $batch->count()))); - $this->html->append($batch->getPanel($this->view, '0%')); + $this->html->pInfo($batch->getStartButton(sprintf($this->_('Check %s tokens'), $batch->getTokenCount()))); + $this->html->append($batch->getPanel($this->view, $batch->getProgressPercentage() . '%')); } else { $this->html->pInfo($this->_('No tokens to check.')); } @@ -240,8 +246,36 @@ $this->afterSaveRoute($this->getRequest()); } + /** + * Synchronize survey status for the surveys in a source + */ public function synchronizeAction() { + $sourceId = $this->getSourceId(); + + $batch = $this->loader->getTracker()->synchronizeSourcesBatch($sourceId, $this->loader->getCurrentUser()->getUserId(), false); + + if ($batch->run($this->getRequest())) { + exit; + } else { + $this->html->h3( + sprintf($this->_('Synchronize the %s source.'), + $this->db->fetchOne("SELECT gso_source_name FROM gems__sources WHERE gso_id_source = ?", $sourceId))); + + 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->_('Check %s surveys'), $batch->getSurveyCounter()))); + $this->html->append($batch->getPanel($this->view, $batch->getProgressPercentage() . '%')); + } else { + $this->html->pInfo($this->_('No surveys to check.')); + } + } + } + /* $source = $this->getSourceById(); if ($messages = $source->synchronizeSurveys($this->loader->getCurrentUser()->getUserId())) { @@ -251,6 +285,7 @@ } $this->afterSaveRoute($this->getRequest()); + // */ } public function synchronizeAllAction() Modified: trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php =================================================================== --- trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php 2012-02-16 13:45:27 UTC (rev 495) @@ -263,6 +263,9 @@ return true; } + /** + * Check the tokens for a single survey + */ public function checkAction() { $surveyId = $this->_getParam(MUtil_Model::REQUEST_ID); @@ -283,8 +286,8 @@ } else { if ($batch->count()) { // Batch is loaded by Tracker - $this->html->pInfo($batch->getStartButton(sprintf($this->_('Check %s tokens'), $batch->count()))); - $this->html->append($batch->getPanel($this->view, '0%')); + $this->html->pInfo($batch->getStartButton(sprintf($this->_('Check %s tokens'), $batch->getTokenCount()))); + $this->html->append($batch->getPanel($this->view, $batch->getProgressPercentage() . '%')); } else { $this->html->pInfo($this->_('No tokens to check.')); } @@ -292,6 +295,9 @@ } } + /** + * Check the tokens for all surveys + */ public function checkAllAction() { $batch = $this->loader->getTracker()->recalculateTokensBatch('surveyCheckAll', $this->loader->getCurrentUser()->getUserId()); @@ -307,8 +313,8 @@ } else { if ($batch->count()) { // Batch is loaded by Tracker - $this->html->pInfo($batch->getStartButton(sprintf($this->_('Check %s tokens'), $batch->count()))); - $this->html->append($batch->getPanel($this->view, '0%')); + $this->html->pInfo($batch->getStartButton(sprintf($this->_('Check %s tokens'), $batch->getTokenCount()))); + $this->html->append($batch->getPanel($this->view, $batch->getProgressPercentage() . '%')); } else { $this->html->pInfo($this->_('No tokens to check.')); } Modified: trunk/library/classes/Gems/Tracker/Batch/ProcessTokensBatch.php =================================================================== --- trunk/library/classes/Gems/Tracker/Batch/ProcessTokensBatch.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Tracker/Batch/ProcessTokensBatch.php 2012-02-16 13:45:27 UTC (rev 495) @@ -63,6 +63,13 @@ */ public $minimalStepDurationMs = 3000; + /** + * Add the check of a single token to the batch. + * + * @param mixed $tokenData Array or token id + * @param int $userId Gems user id + * @return Gems_Tracker_Batch_ProcessTokensBatch (Continuation pattern) + */ public function addToken($tokenData, $userId) { if (is_array($tokenData)) { @@ -75,11 +82,18 @@ } // MUtil_Echo::track($tokenData); - $this->setStep('checkTokenCompletion', 'tokchk-' . $tokenId, $tokenData, $userId); + $this->setStep('checkTokenCompletion', 'tokchk-' . $tokenId, $tokenId, $userId); + $this->addToCounter('tokens'); return $this; } + /** + * Check a single track for the effects of token completion. + * + * @param mixed $respTrackData Data array or a respondent track id + * @param int $userId Gems user id + */ protected function checkTrackTokens($respTrackData, $userId) { $respTrack = $this->tracker->getRespondentTrack($respTrackData); @@ -90,6 +104,18 @@ } } + /** + * Check for token completion and adds the processTokenCompletion + * command when the token is indeed completed. + * + * NOTE: The reasons to add the extra commands in this process are + * (1) that we are not sure in advance for which tokens we should + * process and (2) the processing commands should be executed + * AFTER all tokens have been checked for completion. + * + * @param mixed $tokenData Array or token id + * @param int $userId Gems user id + */ protected function checkTokenCompletion($tokenData, $userId) { $this->addToCounter('checkedTokens'); @@ -109,6 +135,11 @@ } } + /** + * Returns a description of what was changed during this batch. + * + * @return array Of message strings + */ public function getCounterMessages() { if ($this->getCounter('checkedRespondentTracks')) { @@ -161,6 +192,21 @@ return array_merge($this->getCounterMessages(), parent::getMessages($reset)); } + /** + * The number of tokens to check + * + * @return int + */ + public function getTokenCount() + { + return $this->getCounter('tokens'); + } + + /** + * True when the batch changed anything. + * + * @return boolean + */ public function hasChanged() { return $this->getCounter('resultDataChanges') || @@ -171,6 +217,18 @@ $this->getCounter('createdTokens'); } + /** + * Processes token completion and adds the checkTrackTokens + * command when the token is indeed completed. + * + * NOTE: The reasons we add the checkTrackTokens command are + * that (1) we do not know in advance which tracks to check + * and (2) the tracks should be checked AFTER all tokens have + * been processed. + * + * @param mixed $tokenData Array or token id + * @param int $userId Gems user id + */ protected function processTokenCompletion($tokenData, $userId) { $token = $this->tracker->getToken($tokenData); Modified: trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourcesBatch.php =================================================================== --- trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourcesBatch.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Tracker/Batch/SynchronizeSourcesBatch.php 2012-02-16 13:45:27 UTC (rev 495) @@ -44,7 +44,7 @@ * @license New BSD License * @since Class available since version 1.5 */ -class Gems_Tracker_Batch_SynchronizesSourceBatch extends MUtil_Batch_BatchAbstract +class Gems_Tracker_Batch_SynchronizeSourcesBatch extends MUtil_Batch_BatchAbstract { /** * @@ -60,12 +60,19 @@ /** * + * @var Zend_Translate + */ + protected $translate; + + /** + * * @param mixed $sourceData Source Id or array containing source data + * @param int $userId Gems user id */ - public function addSource($sourceData, $userId, $updateTokens = true) + public function addSource($sourceData, $userId) { $this->_currentSource = $this->tracker->getSource($sourceData); - $this->_currentSource->addSynchronizeSurveyCommands($this, $userId, $updateTokens); + $this->_currentSource->addSynchronizeSurveyCommands($this, $userId, $this->getTokenUpdate()); $this->_currentSource = null; } @@ -85,6 +92,67 @@ } /** + * Add one to the number of surveys checked + * + * @param int $add + * @return int + */ + public function addToSurveyCounter($add = 1) + { + return $this->addToCounter('surveys', $add); + } + + /** + * String of messages from the batch + * + * Do not forget to reset() the batch if you're done with it after + * displaying the report. + * + * @param boolean $reset When true the batch is reset afterwards + * @return array + */ + public function getMessages($reset = false) + { + $scounter = $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)); + + return $messages; + } + /** + * Get the number of surveys checked + * + * @return int + */ + public function getSurveyCounter() + { + return $this->getCounter('surveys'); + } + + /** + * Is tokenUpdate on or off. + * + * @return boolean + */ + public function getTokenUpdate() + { + return $this->getVar('tokenUpdate'); + } + + /** + * Set tokenUpdate on or off. + */ + public function setTokenUpdate($value = true) + { + $this->setVar('tokenUpdate', $value); + } + + /** * The basic steps * * @param int $sourceId @@ -93,7 +161,7 @@ */ protected function sourceStep($sourceId, $function, array $params) { - $source = $this->tracker->getSource($sourceData); + $source = $this->tracker->getSource($sourceId); $messages = call_user_func_array(array($source, $function), $params); Modified: trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php =================================================================== --- trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php 2012-02-16 13:45:27 UTC (rev 495) @@ -298,11 +298,11 @@ /** * Add the commands to update this source to a source synchornization batch * - * @param Gems_Tracker_Batch_SynchronizesSourceBatch $batch + * @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_SynchronizesSourceBatch $batch, $userId, $updateTokens = true) + */ + public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizeSourcesBatch $batch, $userId, $updateTokens = true) { // Surveys in LS $lsDb = $this->getSourceDatabase(); @@ -321,10 +321,12 @@ } else { $batch->addSourceFunction('checkSurvey', null, $surveyId, $userId, $updateTokens); } + $batch->addToSurveyCounter(); } foreach (array_diff($lsSurveys, $gemsSurveys) as $sourceSurveyId) { $batch->addSourceFunction('checkSurvey', $sourceSurveyId, null, $userId, $updateTokens); + $batch->addToSurveyCounter(); } } @@ -365,7 +367,7 @@ public function checkSurvey($sourceSurveyId, $surveyId, $userId, $updateTokens) { $messages = array(); - $survey = $this->tracker->getSurveyBySourceId($surveyId, $sourceSurveyId); + $survey = $this->tracker->getSurvey($surveyId); if (null === $sourceSurveyId) { // Was removed @@ -431,6 +433,7 @@ } else { $tokenLength = 0; } + $token_library = $this->tracker->getTokenLibrary(); if ($tokenLength < $token_library->getLength()) { $surveyor_status .= 'Token field length is too short. '; } @@ -442,7 +445,7 @@ } } if ($missingFields) { - $sql = "ALTER TABLE " . $this->_getTokenTableName($sid) . " " . implode(', ', $missingFields); + $sql = "ALTER TABLE " . $this->_getTokenTableName($sourceSurveyId) . " " . implode(', ', $missingFields); try { $lsDb->query($sql); $messages[] = sprintf($this->translate->_("Added attribute fields to token table for '%s'"), $surveyor_title); @@ -451,7 +454,7 @@ $surveyor_status .= $e->getMessage() . ' '; $messages[] = sprintf($this->translate->_("Attribute fields not created for token table for '%s'"), $surveyor_title); - $messages[] = sprintf($this->translate->_('Required fields: %s', implode($this->_(', '), array_keys($missingFields)))); + $messages[] = sprintf($this->translate->_('Required fields: %s', implode($this->translate->_(', '), array_keys($missingFields)))); $messages[] = $e->getMessage(); // Maximum reporting for this case @@ -489,7 +492,7 @@ if ($surveyor_status) { $values['gsu_status'] = substr($surveyor_status, 0, 127); $messages[] = sprintf($this->translate->_('The status of the \'%s\' survey has changed to \'%s\'.'), $survey->getName(), $values['gsu_status']); - } else { + } elseif ($survey->getStatus() != 'OK') { $values['gsu_status'] = 'OK'; $messages[] = sprintf($this->translate->_('The status warning for the \'%s\' survey was removed.'), $survey->getName()); } @@ -508,9 +511,11 @@ $messages[] = sprintf($this->translate->_('Imported the \'%s\' survey.'), $surveyor_title); } - $values['gsu_survey_description'] = strtr(substr($surveyor_survey['description'], 0, 100), "\xA0\xC2", ' '); + $values['gsu_survey_description'] = strtr(substr($lsSurvey['surveyls_description'], 0, 100), "\xA0\xC2", ' '); $survey->saveSurvey($values, $userId); } + + return $messages; } /** Modified: trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php =================================================================== --- trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php 2012-02-16 13:45:27 UTC (rev 495) @@ -95,7 +95,7 @@ { $select = $this->_gemsDb->select(); $select->from('gems__surveys', array('gsu_id_survey', 'gsu_surveyor_id')) - ->where('gsu_id_source = ', $this->getId()) + ->where('gsu_id_source = ?', $this->getId()) ->order('gsu_surveyor_id'); return $this->_gemsDb->fetchPairs($select); @@ -225,11 +225,11 @@ /** * Add the commands to update this source to a source synchornization batch * - * @param Gems_Tracker_Batch_SynchronizesSourceBatch $batch + * @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_SynchronizesSourceBatch $batch, $userId, $updateTokens = true) + public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizeSourcesBatch $batch, $userId, $updateTokens = true) { // Do nothing is default } Modified: trunk/library/classes/Gems/Tracker/Source/SourceInterface.php =================================================================== --- trunk/library/classes/Gems/Tracker/Source/SourceInterface.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Tracker/Source/SourceInterface.php 2012-02-16 13:45:27 UTC (rev 495) @@ -57,11 +57,11 @@ /** * Add the commands to update this source to a source synchornization batch * - * @param Gems_Tracker_Batch_SynchronizesSourceBatch $batch + * @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_SynchronizesSourceBatch $batch, $userId, $updateTokens = true); + public function addSynchronizeSurveyCommands(Gems_Tracker_Batch_SynchronizeSourcesBatch $batch, $userId, $updateTokens = true); /** * Inserts the token in the source (if needed) and sets those attributes the source wants to set. Modified: trunk/library/classes/Gems/Tracker/Survey.php =================================================================== --- trunk/library/classes/Gems/Tracker/Survey.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Tracker/Survey.php 2012-02-16 13:45:27 UTC (rev 495) @@ -1,4 +1,5 @@ <?php + /** * Copyright (c) 2011, Erasmus MC * All rights reserved. Modified: trunk/library/classes/Gems/Tracker/TrackerInterface.php =================================================================== --- trunk/library/classes/Gems/Tracker/TrackerInterface.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Tracker/TrackerInterface.php 2012-02-16 13:45:27 UTC (rev 495) @@ -54,7 +54,7 @@ * extension) and TokenValidator. * * Other functions are general utility functions, e.g. checkTrackRounds(), createToken(), - * processCompletedTokens() and recalculateTokens(). + * processCompletedTokens() and recalculateTokensBatch(). * * @package Gems * @subpackage Tracker @@ -283,12 +283,13 @@ * * Does not reflect changes to tracks or rounds. * - * @param int $userId Id of the user who takes the action (for logging) - * @param string $cond - * @return array of translated messages + * @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 recalculateTokens($userId = null, $cond = null); - + public function synchronizeSourcesBatch($sourceId = null, $userId = null, $updateTokens = false); + /** * 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:36:44 UTC (rev 494) +++ trunk/library/classes/Gems/Tracker.php 2012-02-16 13:45:27 UTC (rev 495) @@ -48,7 +48,7 @@ * extension) and TokenValidator. * * Other functions are general utility functions, e.g. checkTrackRounds(), createToken(), - * processCompletedTokens() and recalculateTokens(). + * processCompletedTokens() and recalculateTokensBatch(). * * @package Gems * @subpackage Tracker @@ -304,13 +304,15 @@ */ public function filterChangesOnly(array $oldValues, array &$newValues) { - if ($newValues) { + if ($newValues && $oldValues) { // MUtil_Echo::track($newValues); // Remove up unchanged values foreach ($newValues as $name => $value) { - // Extra condition for empty time in date values - if (($value === $oldValues[$name]) || ($value === $oldValues[$name] . ' 00:00:00')) { - unset($newValues[$name]); + if (array_key_exists($name, $oldValues)) { + // Extra condition for empty time in date values + if (($value === $oldValues[$name]) || ($value === $oldValues[$name] . ' 00:00:00')) { + unset($newValues[$name]); + } } } } @@ -858,32 +860,39 @@ * * Does not reflect changes to tracks or rounds. * - * @param Zend_Translate $t - * @param int $userId Id of the user who takes the action (for logging) - * @param string $cond - * @return array of translated messages + * @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 recalculateTokens($userId = null, $cond = null) + public function synchronizeSourcesBatch($sourceId = null, $userId = null, $updateTokens = false) { - $userId = $this->_checkUserId($userId); - $tokenSelect = $this->getTokenSelect(); - $tokenSelect->andReceptionCodes() - ->andRespondents() - ->andRespondentOrganizations() - ->andConsents(); - if ($cond) { - $tokenSelect->forWhere($cond); + $batch_id = 'source_synch' . ($sourceId ? '_' . $sourceId : ''); + $batch = $this->_loadClass('Batch_SynchronizeSourcesBatch', true, array($batch_id)); + + if ($updateTokens != $batch->getTokenUpdate()) { + $batch->reset(); } - //Only select surveys that are active in the source (so we can recalculate inactive in Gems) - $tokenSelect->andSurveys(); - $tokenSelect->forWhere('gsu_surveyor_active = 1'); + $batch->setTokenUpdate($updateTokens); - self::$verbose = true; - $changes = $this->processTokens($tokenSelect, $userId); + if (! $batch->isLoaded()) { + if ($sourceId) { + $sources = array($sourceId); + } else { + $select = $this->db->select(); + $select->from('gems__sources', array('gso_id_source')) + ->where('gso_active = 1'); + $sources = $this->db->fetchCol($select); + } - return $changes->getMessages($this->translate); + foreach ($sources as $source) { + $batch->addSource($source, $userId); + } + } + + return $batch; + } - /** * Recalculates all token dates, timing and results * and outputs text messages. Modified: trunk/library/classes/MUtil/Batch/BatchAbstract.php =================================================================== --- trunk/library/classes/MUtil/Batch/BatchAbstract.php 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/MUtil/Batch/BatchAbstract.php 2012-02-16 13:45:27 UTC (rev 495) @@ -202,6 +202,8 @@ $command['method'] = $method; $command['parameters'] = $params; + // MUtil_Echo::track($command); + return $command; } @@ -284,7 +286,7 @@ */ public function getCounter($name) { - MUtil_Echo::track($this->_session->counters); + // MUtil_Echo::track($this->_session->counters); if (isset($this->_session->counters[$name])) { return $this->_session->counters[$name]; } @@ -475,6 +477,30 @@ } /** + * 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 @@ -527,6 +553,7 @@ $this->_session->finished = false; $this->_session->messages = array(); $this->_session->processed = 0; + $this->_session->vars = array(); return $this; } @@ -744,6 +771,21 @@ } /** + * 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 @@ -758,12 +800,24 @@ call_user_func_array(array($this, $command['method']), $command['parameters']); } catch (Exception $e) { $this->addMessage('ERROR!!!'); - $this->addMessage('While calling:' . $command['method'] . '(', implode(',', MUtil_Ra::flatten($command['parameters'])), ')'); + $this->addMessage('While calling:' . $command['method'] . '(' . implode(',', MUtil_Ra::flatten($command['parameters'])) . ')'); $this->addMessage($e->getMessage()); + + MUtil_Echo::r($e); } return true; } else { return false; } } + + /** + * Batch duration variable storage for the process + * + * @param string $name Name + */ + protected function unsetVar($name) + { + unset($this->_session->vars[$name]); + } } Modified: trunk/library/classes/MUtil/Batch/BatchPull.js =================================================================== --- trunk/library/classes/MUtil/Batch/BatchPull.js 2012-02-16 13:36:44 UTC (rev 494) +++ trunk/library/classes/MUtil/Batch/BatchPull.js 2012-02-16 13:45:27 UTC (rev 495) @@ -34,6 +34,8 @@ error: function (request, status, error) { alert('Communication error: ' + status); + this.progressTarget.after('<p>' + request.responseText + '</p>'); + // console.log(request); }, progressTarget: null, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |