From: <gem...@li...> - 2012-06-07 15:54:14
|
Revision: 747 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=747&view=rev Author: matijsdejong Date: 2012-06-07 15:54:06 +0000 (Thu, 07 Jun 2012) Log Message: ----------- TrackRounds checking now done through BatchRunner Still working on the messages though Modified Paths: -------------- trunk/library/classes/Gems/Default/TrackMaintenanceAction.php trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php trunk/library/classes/Gems/Tracker/Engine/TrackEngineInterface.php trunk/library/classes/Gems/Tracker/RespondentTrack.php trunk/library/classes/Gems/Tracker/TrackerInterface.php trunk/library/classes/Gems/Tracker.php Added Paths: ----------- trunk/library/classes/Gems/Task/Tracker/CheckTrackRounds.php Modified: trunk/library/classes/Gems/Default/TrackMaintenanceAction.php =================================================================== --- trunk/library/classes/Gems/Default/TrackMaintenanceAction.php 2012-06-07 14:32:08 UTC (rev 746) +++ trunk/library/classes/Gems/Default/TrackMaintenanceAction.php 2012-06-07 15:54:06 UTC (rev 747) @@ -149,45 +149,27 @@ return true; } + /** + * Action for checking all assigned rounds using a batch + */ public function checkAllAction() { - $model = $this->getModel(); - $data = $model->load(null, $this->sortKey); - - if ($this->_getParam('confirmed')) { - $this->checkTrack(); - $this->afterSaveRoute($this->getRequest()); - } - - $this->addMessage($this->_('This may take a while!')); - $this->html->h3($this->_('Check all tracks')); - $this->html->pInfo($this->_('Checking all tracks will update all existing rounds to the current surveys in the tracks instead of those in use when the track was created.')); - $this->html->pInfo($this->_('Completed tracks will not be changed. No new tokens will be created when later tokens were completed.')); - 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->gtr_id_track), $rdata->gtr_track_name); - - $this->html->h4('Are you sure you want to check all tracks?'); - $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')); + $batch = $this->loader->getTracker()->checkTrackRoundsBatch('trackCheckRoundsAll', $this->loader->getCurrentUser()->getUserId()); + $this->_helper->BatchRunner($batch, $this->_('Checking round assignments for all tracks.')); } - public function checkTrack($cond = null) - { - $tracker = $this->loader->getTracker(); - $this->addMessage($tracker->checkTrackRounds($this->session->user_id, $cond)); - } - + /** + * Action for checking all assigned rounds for a single track using a batch + */ public function checkTrackAction() { - $this->checkTrack($this->db->quoteInto('gr2t_id_track = ?', $this->_getIdParam())); - $this->afterSaveRoute($this->getRequest()); + $id = $this->_getIdParam(); + $track = $this->loader->getTracker()->getTrackEngine($id); + $where = $this->db->quoteInto('gr2t_id_track = ?', $id); + $batch = $this->loader->getTracker()->checkTrackRoundsBatch('trackCheckRounds' . $id, $this->loader->getCurrentUser()->getUserId(), $where); + + $title = sprintf($this->_("Checking round assignments for track '%s'."), $track->getTrackName()); + $this->_helper->BatchRunner($batch, $title); } public function createAction() Added: trunk/library/classes/Gems/Task/Tracker/CheckTrackRounds.php =================================================================== --- trunk/library/classes/Gems/Task/Tracker/CheckTrackRounds.php (rev 0) +++ trunk/library/classes/Gems/Task/Tracker/CheckTrackRounds.php 2012-06-07 15:54:06 UTC (rev 747) @@ -0,0 +1,65 @@ +<?php + +/** + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * @package Gems + * @subpackage TaskTracker + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: CheckTokenCompletion.php 528 2012-03-01 14:06:23Z mennodekker $ + */ + +/** + * Check token completion in a batch job + * + * This task handles the token completion check, adding tasks to the queue + * when needed. + * + * @package Gems + * @subpackage Task_Tracker + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5.5 + */ +class Gems_Task_Tracker_CheckTrackRounds extends Gems_Task_TaskAbstract +{ + /** + * @var Gems_Tracker + */ + public $tracker; + + public function execute($respTrackData = null, $userId = null) + { + $this->tracker = $this->loader->getTracker(); + $respTrack = $this->tracker->getRespondentTrack($respTrackData); + $engine = $respTrack->getTrackEngine(); + + $engine->checkRoundsFor($respTrack, $userId, $this->_batch); + $this->_batch->addToCounter('checkedRespondentTracks'); + } +} \ No newline at end of file Modified: trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php =================================================================== --- trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php 2012-06-07 14:32:08 UTC (rev 746) +++ trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php 2012-06-07 15:54:06 UTC (rev 747) @@ -405,32 +405,25 @@ * * @param Gems_Tracker_RespondentTrack $respTrack The respondent track to check * @param int $userId Id of the user who takes the action (for logging) - * @param Gems_Tracker_ChangeTracker $changes Optional change tracker - * @return Gems_Tracker_ChangeTracker detailed info on changes + * @param Gems_Task_TaskRunnerBatch $changes batch for counters */ - public function checkRoundsFor(Gems_Tracker_RespondentTrack $respTrack, $userId, Gems_Tracker_ChangeTracker $changes = null) + public function checkRoundsFor(Gems_Tracker_RespondentTrack $respTrack, $userId, Gems_Task_TaskRunnerBatch $batch) { - if (null === $changes) { - $changes = new Gems_Tracker_ChangeTracker(); - } - //Step one: update existing tokens - $changes->roundChangeUpdates += $this->checkExistingRoundsFor($respTrack, $userId); + $batch->addToCounter('roundChangeUpdates', $this->checkExistingRoundsFor($respTrack, $userId)); //Step two: deactivate inactive rounds - $changes->deletedTokens += $this->removeInactiveRounds($respTrack, $userId); + $batch->addToCounter('deletedTokens', $this->removeInactiveRounds($respTrack, $userId)); // Step three: create lacking tokens - $changes->createdTokens += $this->addNewTokens($respTrack, $userId); + $batch->addToCounter('createdTokens', $this->addNewTokens($respTrack, $userId)); // Step four: set the dates and times $changed = $this->checkTokensFromStart($respTrack, $userId); if ($changed) { - $changes->tokenDateCauses++; - $changes->tokenDateChanges += $changed; + $batch->addToCounter('tokenDateCauses'); + $batch->addToCounter('tokenDateChanges', $changed); } - - return $changes; } /** Modified: trunk/library/classes/Gems/Tracker/Engine/TrackEngineInterface.php =================================================================== --- trunk/library/classes/Gems/Tracker/Engine/TrackEngineInterface.php 2012-06-07 14:32:08 UTC (rev 746) +++ trunk/library/classes/Gems/Tracker/Engine/TrackEngineInterface.php 2012-06-07 15:54:06 UTC (rev 747) @@ -79,10 +79,9 @@ * * @param Gems_Tracker_RespondentTrack $respTrack The respondent track to check * @param int $userId Id of the user who takes the action (for logging) - * @param Gems_Tracker_ChangeTracker $changes Optional change tracker - * @return Gems_Tracker_ChangeTracker detailed info on changes + * @param Gems_Task_TaskRunnerBatch $changes batch for counters */ - public function checkRoundsFor(Gems_Tracker_RespondentTrack $respTrack, $userId, Gems_Tracker_ChangeTracker $changes = null); + public function checkRoundsFor(Gems_Tracker_RespondentTrack $respTrack, $userId, Gems_Task_TaskRunnerBatch $batch); /** * Check the valid from and until dates in the track starting at a specified token Modified: trunk/library/classes/Gems/Tracker/RespondentTrack.php =================================================================== --- trunk/library/classes/Gems/Tracker/RespondentTrack.php 2012-06-07 14:32:08 UTC (rev 746) +++ trunk/library/classes/Gems/Tracker/RespondentTrack.php 2012-06-07 15:54:06 UTC (rev 747) @@ -318,20 +318,6 @@ } /** - * Check for the existence of all tokens and create them otherwise - * - * @param int $userId Id of the user who takes the action (for logging) - * @param Gems_Tracker_ChangeTracker $changes Optional change tracker - * @return Gems_Tracker_ChangeTracker detailed info on changes - */ - public function checkRounds($userId, Gems_Tracker_ChangeTracker $changes = null) - { - $engine = $this->getTrackEngine(); - - return $engine->checkRoundsFor($this, $userId, $changes); - } - - /** * Check this respondent track for changes to the tokens * * @param int $userId Id of the user who takes the action (for logging) @@ -504,7 +490,7 @@ { return $this->_respTrackData['gr2t_id_organization']; } - + public function getReceptionCode() { return $this->_respTrackData['gr2t_reception_code']; Modified: trunk/library/classes/Gems/Tracker/TrackerInterface.php =================================================================== --- trunk/library/classes/Gems/Tracker/TrackerInterface.php 2012-06-07 14:32:08 UTC (rev 746) +++ trunk/library/classes/Gems/Tracker/TrackerInterface.php 2012-06-07 15:54:06 UTC (rev 747) @@ -53,8 +53,8 @@ * how tokens are created and checked), TokenSelect (Gems_Tracker_Token_TokenSelect * extension) and TokenValidator. * - * Other functions are general utility functions, e.g. checkTrackRounds(), createToken(), - * processCompletedTokens() and recalculateTokensBatch(). + * Other functions are general utility functions, e.g. checkTrackRoundsBatch(), createToken(), + * processCompletedTokensBatch() and recalculateTokensBatch(). * * @package Gems * @subpackage Tracker @@ -62,18 +62,20 @@ * @license New BSD License * @since Class available since version 1.4 */ -interface Gems_Tracker_TrackerInterface { +interface Gems_Tracker_TrackerInterface +{ /** * Checks tracks for changes to the the track and round definitions * and corrects them. * * Does recalculate changed tracks * - * @param int $userId - * @param string $cond - * @return array of translated messages + * @param string $batchId A unique identifier for the current batch + * @param int $userId Id of the user who takes the action (for logging) + * @param string $cond Optional where statement for selecting tracks + * @return Gems_Task_TaskRunnerBatch A batch to process the changes */ - public function checkTrackRounds($userId = null, $cond = null); + public function checkTrackRoundsBatch($batchId, $userId = null, $cond = null); /** * Create a new track for a patient Modified: trunk/library/classes/Gems/Tracker.php =================================================================== --- trunk/library/classes/Gems/Tracker.php 2012-06-07 14:32:08 UTC (rev 746) +++ trunk/library/classes/Gems/Tracker.php 2012-06-07 15:54:06 UTC (rev 747) @@ -47,8 +47,8 @@ * how tokens are created and checked), TokenSelect (Gems_Tracker_Token_TokenSelect * extension) and TokenValidator. * - * Other functions are general utility functions, e.g. checkTrackRounds(), createToken(), - * processCompletedTokens() and recalculateTokensBatch(). + * Other functions are general utility functions, e.g. checkTrackRoundsBatch(), createToken(), + * processCompletedTokensBatch() and recalculateTokensBatch(). * * @package Gems * @subpackage Tracker @@ -194,17 +194,18 @@ * * Does recalculate changed tracks * - * @param int $userId - * @param string $cond - * @return array of translated messages + * @param string $batchId A unique identifier for the current batch + * @param int $userId Id of the user who takes the action (for logging) + * @param string $cond Optional where statement for selecting tracks + * @return Gems_Task_TaskRunnerBatch A batch to process the changes */ - public function checkTrackRounds($userId = null, $cond = null) + public function checkTrackRoundsBatch($batchId, $userId = null, $cond = null) { $userId = $this->_checkUserId($userId); $respTrackSelect = $this->db->select(); - $respTrackSelect->from('gems__respondent2track'); - $respTrackSelect->join('gems__reception_codes', 'gr2t_reception_code = grc_id_reception_code'); - $respTrackSelect->join('gems__tracks', 'gr2t_id_track = gtr_id_track'); + $respTrackSelect->from('gems__respondent2track', array('gr2t_id_respondent_track')); + $respTrackSelect->join('gems__reception_codes', 'gr2t_reception_code = grc_id_reception_code', array()); + $respTrackSelect->join('gems__tracks', 'gr2t_id_track = gtr_id_track', array()); if ($cond) { $respTrackSelect->where($cond); @@ -214,21 +215,21 @@ $respTrackSelect->where('gtr_active = 1'); $respTrackSelect->where('gr2t_count != gr2t_completed'); - self::$verbose = true; + $batch = $this->loader->getTaskRunnerBatch($batchId); + //Now set the step duration + $batch->minimalStepDurationMs = 3000; - $changes = new Gems_Tracker_ChangeTracker(); - $respTracks = $respTrackSelect->query()->fetchAll(); - - foreach ($respTracks as $respTrackData) { - $respTrack = $this->getRespondentTrack($respTrackData); - - $respTrack->checkRounds($userId, $changes); - $changes->checkedRespondentTracks++; - - unset($respTrack); + if (! $batch->isLoaded()) { + $statement = $respTrackSelect->query(); + //Process one item at a time to prevent out of memory errors for really big resultsets + while ($respTrackData = $statement->fetch()) { + $respTrackId = $respTrackData['gr2t_id_respondent_track']; + $batch->setTask('Tracker_CheckTrackRounds', 'trkchk-' . $respTrackId, $respTrackId, $userId); + $batch->addToCounter('resptracks'); + } } - return $changes->getMessages($this->translate); + return $batch; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |