From: <gem...@li...> - 2012-03-01 13:46:54
|
Revision: 527 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=527&view=rev Author: mennodekker Date: 2012-03-01 13:46:43 +0000 (Thu, 01 Mar 2012) Log Message: ----------- Ported RefreshTokenAttributesBatch to the Task system Modified Paths: -------------- trunk/library/classes/Gems/Tracker.php Added Paths: ----------- trunk/library/classes/Gems/Task/Tracker/RefreshTokenAttributes.php Removed Paths: ------------- trunk/library/classes/Gems/Tracker/Batch/RefreshTokenAttributesBatch.php Added: trunk/library/classes/Gems/Task/Tracker/RefreshTokenAttributes.php =================================================================== --- trunk/library/classes/Gems/Task/Tracker/RefreshTokenAttributes.php (rev 0) +++ trunk/library/classes/Gems/Task/Tracker/RefreshTokenAttributes.php 2012-03-01 13:46:43 UTC (rev 527) @@ -0,0 +1,69 @@ +<?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 Task_Tracker + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id: ProcessTokenCompletion.php 502 2012-02-20 14:13:20Z mennodekker $ + */ + +/** + * Refresh the attributes of the token + * + * @package Gems + * @subpackage Task_Tracker + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.6 + */ +class Gems_Task_Tracker_RefreshTokenAttributes extends Gems_Task_TaskAbstract +{ + /** + * @var Gems_Tracker + */ + public $tracker; + + public function execute($tokenId = null) + { + $this->tracker = $this->loader->getTracker(); + $token = $this->tracker->getToken($tokenId); + + $checked = $this->_batch->addToCounter('ta-checkedTokens'); + if ($token->inSource()) { + $survey = $token->getSurvey(); + if ($survey->copyTokenToSource($token, '')) { + $this->_batch->addToCounter('ta-changedTokens'); + } + } + + $cTokens = $this->_batch->getCounter('ta-changedTokens'); + + $this->_batch->setMessage('ta-check', sprintf($this->translate->plural('%d token out of %d tokens changed.', '%d tokens out of %d tokens changed.', $cTokens), $cTokens, $checked)); + } +} \ No newline at end of file Deleted: trunk/library/classes/Gems/Tracker/Batch/RefreshTokenAttributesBatch.php =================================================================== --- trunk/library/classes/Gems/Tracker/Batch/RefreshTokenAttributesBatch.php 2012-03-01 13:22:33 UTC (rev 526) +++ trunk/library/classes/Gems/Tracker/Batch/RefreshTokenAttributesBatch.php 2012-03-01 13:46:43 UTC (rev 527) @@ -1,133 +0,0 @@ -<?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 <COPYRIGHT HOLDER> 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 Tracker - * @author Matijs de Jong <mj...@ma...> - * @copyright Copyright (c) 2011 Erasmus MC - * @license New BSD License - * @version $Id$ - */ - -/** - * Refresh the attributes of all tokens - * - * @package Gems - * @subpackage Tracker - * @copyright Copyright (c) 2011 Erasmus MC - * @license New BSD License - * @since Class available since version 1.5 - */ -class Gems_Tracker_Batch_RefreshTokenAttributesBatch extends MUtil_Batch_BatchAbstract -{ - /** - * - * @var Gems_Tracker - */ - protected $tracker; - - /** - * - * @var Zend_Translate - */ - protected $translate; - - /** - * Add a token check step to the batch - * - * @param string $tokenId A token id - * @return Gems_Tracker_Batch_UpdateAttributesBatch (Continuation pattern) - */ - public function addToken($tokenId) - { - $this->addStep('updateAttributes', $tokenId); - - return $this; - } - - /** - * Add token check steps to the batch - * - * @param array $tokenIds An array of token ids - * @return Gems_Tracker_Batch_UpdateAttributesBatch (Continuation pattern) - */ - public function addTokens(array $tokenIds) - { - foreach ($tokenIds as $tokenId) { - $this->addStep('updateAttributes', $tokenId); - } - - return $this; - } - - /** - * 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) - { - - $cAll = $this->count(); - $cTokens = $this->getCounter('changedTokens'); - - $messages = parent::getMessages($reset); - - array_unshift($messages, sprintf($this->translate->_('Checked %d token.'), $cAll)); - if ($cTokens == 0) { - $messages[] = $this->translate->_('No attributes were updated.'); - } else { - $messages[] = sprintf($this->translate->plural('%d token changed.', '%d tokens changed.', $cTokens), $cTokens); - } - - return $messages; - } - - /** - * Update the attributes of a token, if the token is - * already in the source. - * - * @param string $tokenId A token id - */ - protected function updateAttributes($tokenId) - { - $token = $this->tracker->getToken($tokenId); - - if ($token->inSource()) { - $survey = $token->getSurvey(); - if ($survey->copyTokenToSource($token, '')) { - $this->addToCounter('changedTokens'); - } - } - } -} Modified: trunk/library/classes/Gems/Tracker.php =================================================================== --- trunk/library/classes/Gems/Tracker.php 2012-03-01 13:22:33 UTC (rev 526) +++ trunk/library/classes/Gems/Tracker.php 2012-03-01 13:46:43 UTC (rev 527) @@ -933,11 +933,11 @@ * * @param string $batch_id A unique identifier for the current batch * @param string $cond An optional where statement - * @return Gems_Tracker_Batch_RefreshTokenAttributesBatch A batch to process the changes + * @return Gems_Task_TaskRunnerBatch A batch to process the changes */ public function refreshTokenAttributesBatch($batch_id, $cond = null) { - $batch = $this->_loadClass('Batch_RefreshTokenAttributesBatch', true, array($batch_id)); + $batch = $this->loader->getTaskRunnerBatch($batch_id); if (! $batch->isLoaded()) { $tokenSelect = $this->getTokenSelect(array('gto_id_token')); @@ -954,7 +954,9 @@ ->forWhere($cond); } - $batch->addTokens($this->db->fetchCol($tokenSelect->getSelect())); + foreach ($this->db->fetchCol($tokenSelect->getSelect()) as $token) { + $batch->addTask('Tracker_RefreshTokenAttributes', $token); + } } self::$verbose = true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |