|
From: <gem...@li...> - 2012-03-12 12:15:38
|
Revision: 546
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=546&view=rev
Author: mennodekker
Date: 2012-03-12 12:15:27 +0000 (Mon, 12 Mar 2012)
Log Message:
-----------
-Moved to 1.5.3
-Added 'charset' to source database, to fix sync errors with external db
-Migrated the last batch to the task system, also fixing a couple of errors with inserting new surveys
Modified Paths:
--------------
trunk/library/classes/Gems/Default/SourceAction.php
trunk/library/classes/Gems/Task/Tracker/SourceSyncSurveys.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.php
trunk/library/classes/Gems/Versions.php
trunk/library/configs/db/patches.sql
trunk/library/configs/db/tables/gems__sources.20.sql
Added Paths:
-----------
trunk/library/classes/Gems/Task/Tracker/SourceCommand.php
Modified: trunk/library/classes/Gems/Default/SourceAction.php
===================================================================
--- trunk/library/classes/Gems/Default/SourceAction.php 2012-03-12 09:20:59 UTC (rev 545)
+++ trunk/library/classes/Gems/Default/SourceAction.php 2012-03-12 12:15:27 UTC (rev 546)
@@ -169,6 +169,7 @@
$model->set('gso_ls_dbhost', 'label', $this->_('Database host'));
$model->set('gso_ls_database', 'label', $this->_('Database'));
+ $model->set('gso_ls_charset', 'label', $this->_('Charset'));
}
$model->set('gso_ls_table_prefix', 'label', $this->_('Table prefix'), 'default', 'ls__');
@@ -238,26 +239,9 @@
$batch = $this->loader->getTracker()->synchronizeSourcesBatch($sourceId, $this->loader->getCurrentUser()->getUserId());
- 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.'));
- }
- }
- }
+ $title = sprintf($this->_('Synchronize the %s source.'),
+ $this->db->fetchOne("SELECT gso_source_name FROM gems__sources WHERE gso_id_source = ?", $sourceId));
+ $this->_helper->BatchRunner($batch, $title);
}
/**
@@ -268,59 +252,9 @@
//*
$batch = $this->loader->getTracker()->synchronizeSourcesBatch(null, $this->loader->getCurrentUser()->getUserId());
- if ($batch->run($this->getRequest())) {
- exit;
- } else {
- $this->html->h3($this->_('Synchronize 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->plural('Check %s source', 'Check %s sources', $batch->getSourceCounter()), $batch->getSourceCounter())));
- $this->html->append($batch->getPanel($this->view, $batch->getProgressPercentage() . '%'));
- } else {
- $this->html->pInfo($this->_('No sources to check.'));
- }
- }
- } // */
-
- /*
- $batch = new MUtil_Batch_WaitBatch();
- $batch->setMethodPush(5);
- $batch->progressParameterName = 'waitprogress';
- // $batch->autoStart = true;
- // $batch->minimalStepDurationMs = 2000;
- if ($batch->run($this->getRequest())) {
- exit;
- } else {
- if ($batch->isFinished()) {
- $this->addMessage($batch->getMessages(true));
- $this->html->pInfo($batch->getRestartButton($this->_('Prepare restart'), array('class' => 'actionlink')));
- } else {
- // Populate the batch (from scratch).
- $batch->reset();
- if (true) {
- $batch->addWaitsMs(400, 20);
- $batch->addWaits(2, 1, 'Har har');
- $batch->addWaitsMs(20, 50);
- } else {
- $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%'));
- }
- } // */
-
+ $title = $this->_('Synchronize all sources.');
+ $this->_helper->BatchRunner($batch, $title);
+
$this->html->actionLink(array('action' => 'index'), $this->_('Cancel'));
}
}
Added: trunk/library/classes/Gems/Task/Tracker/SourceCommand.php
===================================================================
--- trunk/library/classes/Gems/Task/Tracker/SourceCommand.php (rev 0)
+++ trunk/library/classes/Gems/Task/Tracker/SourceCommand.php 2012-03-12 12:15:27 UTC (rev 546)
@@ -0,0 +1,58 @@
+<?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: SourceSyncSurveys.php 528 2012-03-01 14:06:23Z mennodekker $
+ */
+
+/**
+ * Executes any command in a source for a given $sourceId
+ *
+ * @package Gems
+ * @subpackage Task_Tracker
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5.3
+ */
+class Gems_Task_Tracker_SourceCommand extends Gems_Task_TaskAbstract
+{
+ public function execute($sourceId = null, $command = null)
+ {
+ $params = array_slice(func_get_args(), 2);
+ $source = $this->loader->getTracker()->getSource($sourceId);
+ $source->setBatch($this->_batch);
+
+ if ($messages = call_user_func_array(array($source, $command), $params)) {
+ foreach ($messages as $message) {
+ $this->_batch->addMessage($command . ': ' . $message);
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/library/classes/Gems/Task/Tracker/SourceSyncSurveys.php
===================================================================
--- trunk/library/classes/Gems/Task/Tracker/SourceSyncSurveys.php 2012-03-12 09:20:59 UTC (rev 545)
+++ trunk/library/classes/Gems/Task/Tracker/SourceSyncSurveys.php 2012-03-12 12:15:27 UTC (rev 546)
@@ -46,10 +46,14 @@
public function execute($id = null, $userId = null)
{
$source = $this->loader->getTracker()->getSource($id);
+ $source->setBatch($this->_batch);
if (is_null($userId)) {
$userId = $this->loader->getCurrentUser()->getUserId();
}
+
+ $surveyCount = $this->_batch->addToCounter('sourceSyncSources');
+ $this->_batch->setMessage('sourceSyncSources', sprintf($this->translate->plural('Check %s source', 'Check %s sources', $surveyCount), $surveyCount));
if ($messages = $source->synchronizeSurveys($userId)) {
foreach ($messages as $message) {
Modified: trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php
===================================================================
--- trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php 2012-03-12 09:20:59 UTC (rev 545)
+++ trunk/library/classes/Gems/Tracker/Source/LimeSurvey1m9Database.php 2012-03-12 12:15:27 UTC (rev 546)
@@ -399,7 +399,7 @@
{
$messages = array();
$survey = $this->tracker->getSurvey($surveyId);
-
+
if (null === $sourceSurveyId) {
// Was removed
$values['gsu_active'] = 0;
@@ -526,6 +526,8 @@
$values['gsu_surveyor_active'] = $surveyor_active ? 1 : 0;
$values['gsu_active'] = 0;
$values['gsu_status'] = $surveyor_status;
+ $values['gsu_surveyor_id'] = $sourceSurveyId;
+ $values['gsu_id_source'] = $this->getId();
$messages[] = sprintf($this->translate->_('Imported the \'%s\' survey.'), $surveyor_title);
}
@@ -1110,6 +1112,51 @@
*/
public function synchronizeSurveys($userId, $updateTokens = true)
{
+ // Surveys in LS
+ $lsDb = $this->getSourceDatabase();
+ $select = $lsDb->select();
+ $select->from($this->_getSurveysTableName(), 'sid')
+ ->order('sid');
+ $lsSurveys = $lsDb->fetchCol($select);
+ $lsSurveys = array_combine($lsSurveys, $lsSurveys);
+
+ // Surveys in Gems
+ $gemsSurveys = $this->_getGemsSurveysForSynchronisation();
+
+ foreach ($gemsSurveys as $surveyId => $sourceSurveyId) {
+ if (isset($lsSurveys[$sourceSurveyId])) {
+ if ($this->hasBatch()) {
+ $this->_batch->addTask('Tracker_SourceCommand', $this->getId(), 'CheckSurvey', $sourceSurveyId, $surveyId, $userId);
+ } else {
+ $this->checkSurvey($sourceSurveyId, $surveyId, $userId);
+ }
+ } else {
+ if ($this->hasBatch()) {
+ $this->_batch->addTask('Tracker_SourceCommand', $this->getId(), 'CheckSurvey', null, $surveyId, $userId);
+ } else {
+ $this->checkSurvey(null, $surveyId, $userId);
+ }
+ }
+ }
+
+ foreach (array_diff($lsSurveys, $gemsSurveys) as $sourceSurveyId) {
+ if ($this->hasBatch()) {
+ $this->_batch->addTask('Tracker_SourceCommand', $this->getId(), 'CheckSurvey', $sourceSurveyId, null, $userId);
+ } else {
+ $this->checkSurvey($sourceSurveyId, null, $userId);
+ }
+ }
+ }
+
+ /**
+ * Updates the gems database with the latest information about the surveys in this source adapter
+ *
+ * @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
+ * @return array Returns an array of messages
+ */
+ public function synchronizeSurveysOld($userId, $updateTokens = true)
+ {
$lsDb = $this->getSourceDatabase();
$messages = array();
$source_id = $this->getId();
Modified: trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php
===================================================================
--- trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php 2012-03-12 09:20:59 UTC (rev 545)
+++ trunk/library/classes/Gems/Tracker/Source/SourceAbstract.php 2012-03-12 12:15:27 UTC (rev 546)
@@ -48,6 +48,13 @@
abstract class Gems_Tracker_Source_SourceAbstract extends Gems_Registry_TargetAbstract implements Gems_Tracker_Source_SourceInterface
{
/**
+ * Holds the current batch if there is any
+ *
+ * @var Gems_Task_TaskRunnerBatch
+ */
+ protected $_batch = null;
+
+ /**
* The database connection to Gems itself
*
* @var Zend_Db_Adapter_Abstract
@@ -272,6 +279,10 @@
if (($dbConfig['dbname'] != $gemsName) &&
($adapter = $this->_sourceData['gso_ls_adapter'])) {
+ //If upgrade has run and we have a 'charset' use it
+ if (array_key_exists('gso_ls_charset', $this->_sourceData)) {
+ $dbConfig['charset'] = $this->_sourceData['gso_ls_charset'] ? $this->_sourceData['gso_ls_charset'] : $gemsConfig['charset'];
+ }
$dbConfig['host'] = $this->_sourceData['gso_ls_dbhost'] ? $this->_sourceData['gso_ls_dbhost'] : $gemsConfig['host'];
$dbConfig['username'] = $this->_sourceData['gso_ls_username'] ? $this->_sourceData['gso_ls_username'] : $gemsConfig['username'];
$dbConfig['password'] = $this->_sourceData['gso_ls_password'] ? $this->_sourceData['gso_ls_password'] : $gemsConfig['password'];
@@ -316,6 +327,16 @@
}
/**
+ * Returns true if a batch is set
+ *
+ * @return boolean
+ */
+ public function hasBatch()
+ {
+ return ($this->_batch instanceof Gems_Task_TaskRunnerBatch);
+ }
+
+ /**
* Updates the gems__tokens table so all tokens stick to the (possibly) new token name rules.
*
* @param int $userId Id of the user who takes the action (for logging)
@@ -334,4 +355,16 @@
return $this->_gemsDb->query($sql)->rowCount();
}
+
+ /**
+ * Set the batch to be used by this source
+ *
+ * Use $this->hasBatch to check for existence
+ *
+ * @param Gems_Task_TaskRunnerBatch $batch
+ */
+ public function setBatch(Gems_Task_TaskRunnerBatch $batch)
+ {
+ $this->_batch = $batch;
+ }
}
Modified: trunk/library/classes/Gems/Tracker/Source/SourceInterface.php
===================================================================
--- trunk/library/classes/Gems/Tracker/Source/SourceInterface.php 2012-03-12 09:20:59 UTC (rev 545)
+++ trunk/library/classes/Gems/Tracker/Source/SourceInterface.php 2012-03-12 12:15:27 UTC (rev 546)
@@ -55,14 +55,6 @@
public function __construct(array $sourceData, Zend_Db_Adapter_Abstract $gemsDb);
/**
- * Add the commands to update this source to a source synchornization batch
- *
- * @param Gems_Tracker_Batch_SynchronizeSourcesBatch $batch
- * @param int $userId Id of the user who takes the action (for logging)
- */
- 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.
*
* @param Gems_Tracker_Token $token
@@ -233,6 +225,13 @@
public function getTokenUrl(Gems_Tracker_Token $token, $language, $surveyId, $sourceSurveyId);
/**
+ * Returns true if a batch is set
+ *
+ * @return boolean
+ */
+ public function hasBatch();
+
+ /**
* Checks whether the token is in the source.
*
* @param Gems_Tracker_Token $token Gems token object
@@ -255,6 +254,15 @@
public function isCompleted(Gems_Tracker_Token $token, $surveyId, $sourceSurveyId = null);
/**
+ * Set the batch to be used by this source
+ *
+ * Use $this->hasBatch to check for existence
+ *
+ * @param Gems_Task_TaskRunnerBatch $batch
+ */
+ public function setBatch(Gems_Task_TaskRunnerBatch $batch);
+
+ /**
* Sets the answers passed on.
*
* @param Gems_Tracker_Token $token Gems token object
Modified: trunk/library/classes/Gems/Tracker.php
===================================================================
--- trunk/library/classes/Gems/Tracker.php 2012-03-12 09:20:59 UTC (rev 545)
+++ trunk/library/classes/Gems/Tracker.php 2012-03-12 12:15:27 UTC (rev 546)
@@ -469,7 +469,7 @@
$surveyId = $surveyData;
}
- if (! isset($this->_surveys[$surveyId])) {
+ if ($surveyId == null || ! isset($this->_surveys[$surveyId])) {
$this->_surveys[$surveyId] = $this->_loadClass('survey', true, array($surveyData));
}
@@ -877,7 +877,7 @@
public function synchronizeSourcesBatch($sourceId = null, $userId = null)
{
$batch_id = 'source_synch' . ($sourceId ? '_' . $sourceId : '');
- $batch = $this->_loadClass('Batch_SynchronizeSourcesBatch', true, array($batch_id));
+ $batch = $this->loader->getTaskRunnerBatch($batch_id);
if (! $batch->isLoaded()) {
if ($sourceId) {
@@ -890,7 +890,7 @@
}
foreach ($sources as $source) {
- $batch->addSource($source, $userId);
+ $batch->addTask('Tracker_SourceSyncSurveys', $source, $userId);
}
}
Modified: trunk/library/classes/Gems/Versions.php
===================================================================
--- trunk/library/classes/Gems/Versions.php 2012-03-12 09:20:59 UTC (rev 545)
+++ trunk/library/classes/Gems/Versions.php 2012-03-12 12:15:27 UTC (rev 546)
@@ -43,12 +43,12 @@
{
public final function getBuild()
{
- return 45;
+ return 46;
}
public final function getGemsVersion()
{
- return '1.5.2';
+ return '1.5.3';
}
public function getProjectVersion()
Modified: trunk/library/configs/db/patches.sql
===================================================================
--- trunk/library/configs/db/patches.sql 2012-03-12 09:20:59 UTC (rev 545)
+++ trunk/library/configs/db/patches.sql 2012-03-12 12:15:27 UTC (rev 546)
@@ -379,3 +379,7 @@
-- GEMS VERSION: 45
-- PATCH: Assign attribute sync to super role
UPDATE gems__roles SET grl_privileges = CONCAT(grl_privileges,',pr.source.check-attributes') WHERE grl_name = 'super' AND grl_privileges NOT LIKE '%pr.source.check-attributes%';
+
+-- GEMS VERSION: 46
+-- PATCH: Add charset attribute for source database
+ALTER TABLE `gems__sources` ADD `gso_ls_charset` VARCHAR( 8 ) NOT NULL AFTER `gso_ls_password`;
\ No newline at end of file
Modified: trunk/library/configs/db/tables/gems__sources.20.sql
===================================================================
--- trunk/library/configs/db/tables/gems__sources.20.sql 2012-03-12 09:20:59 UTC (rev 545)
+++ trunk/library/configs/db/tables/gems__sources.20.sql 2012-03-12 12:15:27 UTC (rev 546)
@@ -1,30 +1,31 @@
-CREATE TABLE if not exists gems__sources (
- gso_id_source int unsigned not null auto_increment,
- gso_source_name varchar(40) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' unique key not null,
+CREATE TABLE IF NOT EXISTS `gems__sources` (
+ `gso_id_source` int(10) unsigned NOT NULL auto_increment,
+ `gso_source_name` varchar(40) NOT NULL,
- gso_ls_url varchar(255) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' unique key not null,
- gso_ls_class varchar(60) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' not null default 'Gems_Source_LimeSurvey1m8Database',
- gso_ls_adapter varchar(20) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null,
- gso_ls_dbhost varchar(127) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null,
- gso_ls_database varchar(127) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null,
- gso_ls_table_prefix varchar(127) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null,
- gso_ls_username varchar(64) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null,
- gso_ls_password varchar(255) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null,
+ `gso_ls_url` varchar(255) NOT NULL,
+ `gso_ls_class` varchar(60) NOT NULL default 'Gems_Source_LimeSurvey1m9Database',
+ `gso_ls_adapter` varchar(20) default NULL,
+ `gso_ls_dbhost` varchar(127) default NULL,
+ `gso_ls_database` varchar(127) default NULL,
+ `gso_ls_table_prefix` varchar(127) default NULL,
+ `gso_ls_username` varchar(64) default NULL,
+ `gso_ls_password` varchar(255) default NULL,
+ `gso_ls_charset` varchar(8) NOT NULL,
- gso_active boolean not null default 1,
+ `gso_active` tinyint(1) NOT NULL default '1',
- gso_status varchar(20) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' null,
- gso_last_synch timestamp null,
+ `gso_status` varchar(20) default NULL,
+ `gso_last_synch` timestamp NULL default NULL,
- gso_changed timestamp not null default current_timestamp on update current_timestamp,
- gso_changed_by bigint unsigned not null,
- gso_created timestamp not null,
- gso_created_by bigint unsigned not null,
+ `gso_changed` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
+ `gso_changed_by` bigint(20) unsigned NOT NULL,
+ `gso_created` timestamp NOT NULL default '0000-00-00 00:00:00',
+ `gso_created_by` bigint(20) unsigned NOT NULL,
- PRIMARY KEY(gso_id_source)
- )
- ENGINE=InnoDB
- auto_increment = 60
- CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
-
+ PRIMARY KEY (`gso_id_source`),
+ UNIQUE KEY `gso_source_name` (`gso_source_name`),
+ UNIQUE KEY `gso_ls_url` (`gso_ls_url`)
+)
+ENGINE=InnoDB
+DEFAULT CHARSET=utf8;
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|