|
From: <gem...@li...> - 2012-01-20 17:06:15
|
Revision: 413
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=413&view=rev
Author: matijsdejong
Date: 2012-01-20 17:06:04 +0000 (Fri, 20 Jan 2012)
Log Message:
-----------
Applied progressBar (#45) for all source checks.
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/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-01-19 17:17:39 UTC (rev 412)
+++ trunk/library/classes/Gems/Default/SourceAction.php 2012-01-20 17:06:04 UTC (rev 413)
@@ -107,20 +107,52 @@
$sourceId = $this->getSourceId();
$where = $this->db->quoteInto('gto_id_survey IN (SELECT gsu_id_survey FROM gems__surveys WHERE gsu_id_source = ?)', $sourceId);
- $this->addMessage(sprintf($this->_(
- 'Checking survey results for %s source.'),
+ $batch = $this->loader->getTracker()->recalculateTokensBatch('sourceCheck' . $sourceId, $this->loader->getCurrentUser()->getUserId(), $where);
+
+ if ($batch->run($this->getRequest())) {
+ exit;
+ } 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->addMessage($this->loader->getTracker()->recalculateTokens($this->session->user_id, $where));
-
- $this->afterSaveRoute($this->getRequest());
+ 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 tokens'), $batch->count())));
+ $this->html->append($batch->getPanel($this->view, '0%'));
+ } else {
+ $this->html->pInfo($this->_('No tokens to check.'));
+ }
+ }
+ }
}
public function checkAllAction()
{
- $this->addMessage($this->loader->getTracker()->recalculateTokens($this->session->user_id));
+ $batch = $this->loader->getTracker()->recalculateTokensBatch('surveyCheckAll', $this->loader->getCurrentUser()->getUserId());
- $this->afterSaveRoute($this->getRequest());
+ if ($batch->run($this->getRequest())) {
+ exit;
+ } else {
+ $this->html->h3($this->_('Checking survey results for all sources.'));
+
+ 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 tokens'), $batch->count())));
+ $this->html->append($batch->getPanel($this->view, '0%'));
+ } else {
+ $this->html->pInfo($this->_('No tokens to check.'));
+ }
+ }
+ }
}
/**
@@ -258,18 +290,19 @@
} 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);
} else {
- $batch->addWaits(4, 2);
- $batch->addWaits(2, 1);
- $batch->addWaitsLater(15, 1);
- $batch->addWait(4, 'That took some time!');
- $batch->addWait(4, 'So we see the message. :)');
- $batch->addWaitsLater(1, 2);
- $batch->addWaits(4);
+ $batch->addWaits(1440, 10);
+ //$batch->addWaits(4, 2);
+ //$batch->addWaits(2, 1);
+ //$batch->addWaitsLater(15, 1);
+ //$batch->addWait(4, 'That took some time!');
+ //$batch->addWait(4, 'So we see the message. :)');
+ //$batch->addWaitsLater(1, 2);
+ //$batch->addWaits(4);
}
$this->html->pInfo($batch->getStartButton($this->_('Start synchronization')));
$this->html->append($batch->getPanel($this->view, '0%'));
Modified: trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php
===================================================================
--- trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php 2012-01-19 17:17:39 UTC (rev 412)
+++ trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php 2012-01-20 17:06:04 UTC (rev 413)
@@ -268,7 +268,7 @@
$surveyId = $this->_getParam(MUtil_Model::REQUEST_ID);
$where = $this->db->quoteInto('gto_id_survey = ?', $surveyId);
- $batch = $this->loader->getTracker()->recalculateTokensBatch($this->loader->getCurrentUser()->getUserId(), $where);
+ $batch = $this->loader->getTracker()->recalculateTokensBatch('surveyCheck' . $surveyId, $this->loader->getCurrentUser()->getUserId(), $where);
if ($batch->run($this->getRequest())) {
exit;
@@ -294,7 +294,7 @@
public function checkAllAction()
{
- $batch = $this->loader->getTracker()->recalculateTokensBatch($this->loader->getCurrentUser()->getUserId());
+ $batch = $this->loader->getTracker()->recalculateTokensBatch('surveyCheckAll', $this->loader->getCurrentUser()->getUserId());
if ($batch->run($this->getRequest())) {
exit;
Modified: trunk/library/classes/Gems/Tracker/Batch/ProcessTokensBatch.php
===================================================================
--- trunk/library/classes/Gems/Tracker/Batch/ProcessTokensBatch.php 2012-01-19 17:17:39 UTC (rev 412)
+++ trunk/library/classes/Gems/Tracker/Batch/ProcessTokensBatch.php 2012-01-20 17:06:04 UTC (rev 413)
@@ -134,7 +134,7 @@
}
if ($this->getCounter('createdTokens')) {
$messages[] = sprintf($this->translate->_('%d tokens created to by round changes.'), $this->getCounter('createdTokens'));
- }
+ }
} else {
$messages[] = $this->translate->_('No tokens were changed.');
}
Modified: trunk/library/classes/Gems/Tracker/TrackerInterface.php
===================================================================
--- trunk/library/classes/Gems/Tracker/TrackerInterface.php 2012-01-19 17:17:39 UTC (rev 412)
+++ trunk/library/classes/Gems/Tracker/TrackerInterface.php 2012-01-20 17:06:04 UTC (rev 413)
@@ -295,10 +295,10 @@
*
* Does not reflect changes to tracks or rounds.
*
- * @param Zend_Translate $t
+ * @param string $batch_id A unique identifier for the current batch
* @param int $userId Id of the user who takes the action (for logging)
* @param string $cond
* @return Gems_Tracker_Batch_ProcessTokensBatch A batch to process the changes
*/
- public function recalculateTokensBatch($userId = null, $cond = null);
+ public function recalculateTokensBatch($batch_id, $userId = null, $cond = null);
}
Modified: trunk/library/classes/Gems/Tracker.php
===================================================================
--- trunk/library/classes/Gems/Tracker.php 2012-01-19 17:17:39 UTC (rev 412)
+++ trunk/library/classes/Gems/Tracker.php 2012-01-20 17:06:04 UTC (rev 413)
@@ -830,15 +830,16 @@
*
* Does not reflect changes to tracks or rounds.
*
+ * @param string $batch_id A unique identifier for the current batch
* @param Gems_Tracker_Token_TokenSelect Select statements selecting tokens
* @param int $userId Id of the user who takes the action (for logging)
* @return Gems_Tracker_Batch_ProcessTokensBatch A batch to process the changes
*/
- protected function processTokensBatch(Gems_Tracker_Token_TokenSelect $tokenSelect, $userId)
+ protected function processTokensBatch($batch_id, Gems_Tracker_Token_TokenSelect $tokenSelect, $userId)
{
$where = implode(' ', $tokenSelect->getSelect()->getPart(Zend_Db_Select::WHERE));
- $batch = $this->_loadClass('Batch_ProcessTokensBatch', true); //, array($where, $this));
+ $batch = $this->_loadClass('Batch_ProcessTokensBatch', true, array($batch_id));
if (! $batch->isLoaded()) {
$tokenRows = $tokenSelect->fetchAll();
@@ -886,12 +887,12 @@
*
* 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 $batch_id A unique identifier for the current batch
+ * @param int $userId Id of the user who takes the action (for logging)
* @param string $cond
* @return Gems_Tracker_Batch_ProcessTokensBatch A batch to process the changes
*/
- public function recalculateTokensBatch($userId = null, $cond = null)
+ public function recalculateTokensBatch($batch_id, $userId = null, $cond = null)
{
$userId = $this->_checkUserId($userId);
$tokenSelect = $this->getTokenSelect();
@@ -904,6 +905,6 @@
$tokenSelect->forWhere('gsu_surveyor_active = 1');
self::$verbose = true;
- return $this->processTokensBatch($tokenSelect, $userId);
+ return $this->processTokensBatch($batch_id, $tokenSelect, $userId);
}
}
Modified: trunk/library/classes/MUtil/Batch/BatchAbstract.php
===================================================================
--- trunk/library/classes/MUtil/Batch/BatchAbstract.php 2012-01-19 17:17:39 UTC (rev 412)
+++ trunk/library/classes/MUtil/Batch/BatchAbstract.php 2012-01-20 17:06:04 UTC (rev 413)
@@ -420,6 +420,16 @@
}
/**
+ * Get the current progress percentage
+ *
+ * @return float
+ */
+ public function getProgressPercentage()
+ {
+ return round($this->_session->processed / (count($this->_session->commands) + $this->_session->processed) * 100, 2);
+ }
+
+ /**
* Returns a button that can be clicked to restart the progress bar.
*
* @param mixed $arg_array MUtil_Ra::args() arguments to populate link with
@@ -548,10 +558,8 @@
// error_log('Cur: ' . microtime(true) . ' report is '. (microtime(true) > $reportRun ? 'true' : 'false'));
if (microtime(true) > $reportRun) {
// Communicate progress
- $percent = round($this->_session->processed / (count($this->_session->commands) + $this->_session->processed) * 100, 2);
+ $bar->update($this->getProgressPercentage(), end($this->_session->messages));
- $bar->update($percent, end($this->_session->messages));
-
// INFO: When using PULL $bar->update() should exit the program,
// but just let us make sure.
if ($isPull) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|