From: <gem...@li...> - 2012-02-02 14:47:24
|
Revision: 445 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=445&view=rev Author: mennodekker Date: 2012-02-02 14:47:15 +0000 (Thu, 02 Feb 2012) Log Message: ----------- Make upgrade action create new tables and run the sync sources + removed reference to session for userid Modified Paths: -------------- branches/1.5.x/library/classes/Gems/Default/SourceAction.php branches/1.5.x/library/classes/Gems/Upgrades.php branches/1.5.x/library/classes/Gems/UpgradesAbstract.php Modified: branches/1.5.x/library/classes/Gems/Default/SourceAction.php =================================================================== --- branches/1.5.x/library/classes/Gems/Default/SourceAction.php 2012-02-02 13:59:06 UTC (rev 444) +++ branches/1.5.x/library/classes/Gems/Default/SourceAction.php 2012-02-02 14:47:15 UTC (rev 445) @@ -231,7 +231,7 @@ { $source = $this->getSourceById(); - if ($source->checkSourceActive($this->session->user_id)) { + if ($source->checkSourceActive($this->loader->getCurrentUser()->getUserId())) { $this->addMessage($this->_('This installation is active.')); } else { $this->addMessage($this->_('Inactive installation.')); @@ -244,7 +244,7 @@ { $source = $this->getSourceById(); - if ($messages = $source->synchronizeSurveys($this->session->user_id)) { + if ($messages = $source->synchronizeSurveys($this->loader->getCurrentUser()->getUserId())) { $this->addMessage($messages); } else { $this->addMessage($this->_('No changes.')); @@ -263,7 +263,7 @@ $source = $this->getSourceById($row['gso_id_source']); $this->addMessage(sprintf($this->_('Synchronization of source %s:'), $row['gso_source_name'])); - if ($messages = $source->synchronizeSurveys($this->session->user_id)) { + if ($messages = $source->synchronizeSurveys($this->loader->getCurrentUser()->getUserId())) { $this->addMessage($messages); } else { $this->addMessage($this->_('No changes.')); Modified: branches/1.5.x/library/classes/Gems/Upgrades.php =================================================================== --- branches/1.5.x/library/classes/Gems/Upgrades.php 2012-02-02 13:59:06 UTC (rev 444) +++ branches/1.5.x/library/classes/Gems/Upgrades.php 2012-02-02 14:47:15 UTC (rev 445) @@ -61,16 +61,38 @@ /** * To upgrade from 143 to 15 we need to do some work: - * 1. execute db patches + * 1. execute db patches 42 and 43 + * 2. create new tables */ public function Upgrade143to15() - { + { $this->patcher->executePatch(42); $this->patcher->executePatch(43); - //Also create new tables or do so in patches... - + $this->invalidateCache(); + $this->createNewTables(); + + $this->invalidateCache(); + + //Now sync the db sources to allow limesurvey source to add a field to the tokentable + $model = new MUtil_Model_TableModel('gems__sources'); + $data = $model->load(false); + + $tracker = $this->loader->getTracker(); + + foreach ($data as $row) { + $source = $tracker->getSource($row['gso_id_source']); + + if ($messages = $source->synchronizeSurveys($this->loader->getCurrentUser()->getUserId())) { + foreach ($messages as $message) { + $this->addMessage($message); + } + } + } + + $this->invalidateCache(); + return true; } } \ No newline at end of file Modified: branches/1.5.x/library/classes/Gems/UpgradesAbstract.php =================================================================== --- branches/1.5.x/library/classes/Gems/UpgradesAbstract.php 2012-02-02 13:59:06 UTC (rev 444) +++ branches/1.5.x/library/classes/Gems/UpgradesAbstract.php 2012-02-02 14:47:15 UTC (rev 445) @@ -64,6 +64,11 @@ public $db; /** + * @var Gems_Model_DbaModel + */ + public $dbaModel; + + /** * @var GemsEscort */ public $escort; @@ -80,6 +85,11 @@ public $patcher; /** + * @var Gems_Project_ProjectSettings + */ + public $project; + + /** * @var Zend_Translate_Adapter */ public $translate; @@ -126,9 +136,18 @@ public function checkRegistryRequestsAnswers() { //As an upgrade almost always includes executing db patches, make a DatabasePatcher object available $this->patcher = new Gems_Util_DatabasePatcher($this->db, 'patches.sql', $this->escort->getDatabasePaths()); - //No load all patches, and save the resulting changed patches for later (not used yet) + //Now load all patches, and save the resulting changed patches for later (not used yet) $changed = $this->patcher->uploadPatches($this->loader->getVersions()->getBuild()); + //Load the dbaModel + $paths = $this->escort->getDatabasePaths(); + $model = new Gems_Model_DbaModel($this->db, array_values($paths)); + $model->setLocations(array_keys($paths)); + if ($this->project->databaseFileEncoding) { + $model->setFileEncoding($this->project->databaseFileEncoding); + } + $this->dbaModel = $model; + return true; } @@ -141,6 +160,29 @@ } /** + * Create all new tables according to the dba model + */ + protected function createNewTables() + { + //Now create all new tables + $todo = $this->dbaModel->load(array('state'=> Gems_Model_DbaModel::STATE_DEFINED)); + $i = 1; + $oCount = count($todo); + $results = array(); + foreach($todo as $tableData) { + $result = $this->dbaModel->runScript($tableData); + $results = array_merge($results, $result); + $results[] = sprintf($this->_('Finished %s creation script for object %d of %d'), $this->_(strtolower($tableData['type'])), $i, $oCount) . '<br/>'; + $i++; + } + + foreach ($results as $result) + { + $this->addMessage($result); + } + } + + /** * Execute upgrades for the given $context * * When no $to or $from are given, the given $context will be upgraded from the current level This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |