From: <gem...@li...> - 2012-02-02 13:59:12
|
Revision: 444 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=444&view=rev Author: mennodekker Date: 2012-02-02 13:59:06 +0000 (Thu, 02 Feb 2012) Log Message: ----------- Extracted _runScript and _runScripts methods to the DbaModel to allow usage outside the DatabaseAction Modified Paths: -------------- branches/1.5.x/library/classes/Gems/Default/DatabaseAction.php branches/1.5.x/library/classes/Gems/Model/DbaModel.php Modified: branches/1.5.x/library/classes/Gems/Default/DatabaseAction.php =================================================================== --- branches/1.5.x/library/classes/Gems/Default/DatabaseAction.php 2012-02-02 12:39:24 UTC (rev 443) +++ branches/1.5.x/library/classes/Gems/Default/DatabaseAction.php 2012-02-02 13:59:06 UTC (rev 444) @@ -48,50 +48,6 @@ { public $sortKey = array('group' => SORT_ASC, 'type' => SORT_ASC, 'name' => SORT_ASC); - private function _runScript(array $data, $includeResultSets = false) - { - $results = array(); - $this->_runScripts($data, $results, $includeResultSets); - return $results; - } - - private function _runScripts(array $data, array &$results, $includeResultSets = false) - { - if ($data['script']) { - $queries = MUtil_Parser_Sql_WordsParser::splitStatements($data['script'], false); - $qCount = count($queries); - - $results[] = sprintf($this->_('Executed %2$s creation script %1$s:'), $data['name'], $this->_(strtolower($data['type']))); - $i = 1; - $resultSet = 1; - - foreach ($queries as $query) { - $sql = (string) $query; - try { - $stmt = $this->db->query($sql); - if ($rows = $stmt->rowCount()) { - if ($includeResultSets && ($data = $stmt->fetchAll())) { - $results[] = sprintf($this->_('%d record(s) returned as result set %d in step %d of %d.'), $rows, $resultSet, $i, $qCount); - $results[] = $data; - $resultSet++; - } else { - $results[] = sprintf($this->_('%d record(s) updated in step %d of %d.'), $rows, $i, $qCount); - } - } else { - $results[] = sprintf($this->_('Script ran step %d of %d succesfully.'), $i, $qCount); - } - } catch (Zend_Db_Statement_Exception $e) { - $results[] = $e->getMessage() . $this->_(' in step ') . $i . ':<pre>' . $sql . '</pre>'; - } - $i++; - } - } else { - $results[] = sprintf($this->_('No script for %1$s.'), $data['name']); - } - - return $results; - } - /** * Set the parameters needed by the menu. * @@ -168,10 +124,7 @@ $model->set('location', 'label', $this->_('Location')); } // $model->set('path', 'label', $this->_('Path')); - $model->set('state', 'label', $this->_('Status'), 'multiOptions', array( - Gems_Model_DbaModel::STATE_CREATED => $this->_('created'), - Gems_Model_DbaModel::STATE_DEFINED => $this->_('not created'), - Gems_Model_DbaModel::STATE_UNKNOWN => $this->_('unknown'))); + $model->set('state', 'label', $this->_('Status')); if ($detailed) { $model->set('script', 'label', $this->_('Script'), 'itemDisplay', 'pre'); @@ -482,7 +435,7 @@ $model = $this->getModel(); $data = $model->loadFirst(); - $results = $this->_runScript($data); + $results = $model->runScript($data); $this->addMessage($results); $this->_reroute(array('action' => 'show')); @@ -497,11 +450,13 @@ if ($this->_getParam('confirmed')) { if ($objects) { + $results = array(); $results[] = sprintf($this->_('Starting %d object creation scripts.'), $oCount) . '<br/>'; $i = 1; foreach ($objects as $data) { - $this->_runScripts($data, $results); + $result = $model->runScript($data); + $results = array_merge($results, $result); $results[] = sprintf($this->_('Finished %s creation script for object %d of %d'), $this->_(strtolower($data['type'])), $i, $oCount) . '<br/>'; $i++; } @@ -559,7 +514,8 @@ $data['name'] = ''; $data['type'] = $this->_('raw'); - $results = $this->_runScript($data, true); + $model = $this->getModel(); + $results = $model->runScript($data, true); $resultSet = 1; $echos = MUtil_Html::create()->array(); foreach ($results as $result) { Modified: branches/1.5.x/library/classes/Gems/Model/DbaModel.php =================================================================== --- branches/1.5.x/library/classes/Gems/Model/DbaModel.php 2012-02-02 12:39:24 UTC (rev 443) +++ branches/1.5.x/library/classes/Gems/Model/DbaModel.php 2012-02-02 13:59:06 UTC (rev 444) @@ -60,6 +60,10 @@ protected $file_encoding; protected $locations; protected $mainDirectory; + /** + * @var Zend_Translate_Adapter + */ + protected $translate; private $_sorts; @@ -73,6 +77,9 @@ $this->db = $db; + //Grab translate object from the Escort + $this->translate = GemsEscort::getInstance()->translate; + $this->set('group', 'maxlength', 40, 'type', MUtil_Model::TYPE_STRING); $this->set('name', 'key', true, 'maxlength', 40, 'type', MUtil_Model::TYPE_STRING); $this->set('type', 'maxlength', 40, 'type', MUtil_Model::TYPE_STRING); @@ -86,8 +93,25 @@ $this->set('script', 'type', MUtil_Model::TYPE_STRING); $this->set('lastChanged', 'type', MUtil_Model::TYPE_DATETIME); $this->set('location', 'maxlength', 12, 'type', MUtil_Model::TYPE_STRING); + $this->set('state', 'multiOptions', array( + Gems_Model_DbaModel::STATE_CREATED => $this->_('created'), + Gems_Model_DbaModel::STATE_DEFINED => $this->_('not created'), + Gems_Model_DbaModel::STATE_UNKNOWN => $this->_('unknown'))); } + /** + * proxy for easy access to translations + * + * @param string $messageId Translation string + * @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale + * identifier, @see Zend_Locale for more information + * @return string + */ + private function _($messageId, $locale = null) + { + return $this->translate->_($messageId, $locale); + } + private function _getGroupName($name) { if ($pos = strpos($name, '__')) { @@ -374,6 +398,56 @@ return $this->loadFirst(array('name' => $tableName), false); } + /** + * Run a sql statement from an object loaded through this model + * + * $data is an array with the following keys: + * script The sql statement to be executed + * name The name of the table, used in messages + * type Type of db element (table or view), used in messages + * + * @param array $data + * @param type $includeResultSets + * @return type + */ + public function runScript(array $data, $includeResultSets = false) + { + $results = array(); + if ($data['script']) { + $queries = MUtil_Parser_Sql_WordsParser::splitStatements($data['script'], false); + $qCount = count($queries); + + $results[] = sprintf($this->_('Executed %2$s creation script %1$s:'), $data['name'], $this->_(strtolower($data['type']))); + $i = 1; + $resultSet = 1; + + foreach ($queries as $query) { + $sql = (string) $query; + try { + $stmt = $this->db->query($sql); + if ($rows = $stmt->rowCount()) { + if ($includeResultSets && ($data = $stmt->fetchAll())) { + $results[] = sprintf($this->_('%d record(s) returned as result set %d in step %d of %d.'), $rows, $resultSet, $i, $qCount); + $results[] = $data; + $resultSet++; + } else { + $results[] = sprintf($this->_('%d record(s) updated in step %d of %d.'), $rows, $i, $qCount); + } + } else { + $results[] = sprintf($this->_('Script ran step %d of %d succesfully.'), $i, $qCount); + } + } catch (Zend_Db_Statement_Exception $e) { + $results[] = $e->getMessage() . $this->_(' in step ') . $i . ':<pre>' . $sql . '</pre>'; + } + $i++; + } + } else { + $results[] = sprintf($this->_('No script for %1$s.'), $data['name']); + } + + return $results; + } + public function save(array $newValues, array $filter = null) { // TODO: Save of data This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <gem...@li...> - 2012-02-15 13:07:35
|
Revision: 477 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=477&view=rev Author: mennodekker Date: 2012-02-15 13:07:26 +0000 (Wed, 15 Feb 2012) Log Message: ----------- Fxing sloppy commit, TrackCompletedEvent should work now Modified Paths: -------------- branches/1.5.x/library/classes/Gems/Event/TrackCompletedEventInterface.php branches/1.5.x/library/classes/Gems/Events.php branches/1.5.x/library/classes/Gems/Tracker/Model/TrackModel.php branches/1.5.x/library/classes/Gems/Tracker/RespondentTrack.php Modified: branches/1.5.x/library/classes/Gems/Event/TrackCompletedEventInterface.php =================================================================== --- branches/1.5.x/library/classes/Gems/Event/TrackCompletedEventInterface.php 2012-02-15 12:42:58 UTC (rev 476) +++ branches/1.5.x/library/classes/Gems/Event/TrackCompletedEventInterface.php 2012-02-15 13:07:26 UTC (rev 477) @@ -43,7 +43,7 @@ * @license New BSD License * @since Class available since version 1.5.1 */ -class Gems_Event_TrackCompletedEventInterface extends Gems_Event_EventInterface +interface Gems_Event_TrackCompletedEventInterface extends Gems_Event_EventInterface { /** * Process the data and return the answers that should be changed. @@ -56,4 +56,4 @@ * @return void */ public function processTrackCompletion(Gems_Tracker_RespondentTrack $track, &$values, $userId); -} +} Modified: branches/1.5.x/library/classes/Gems/Events.php =================================================================== --- branches/1.5.x/library/classes/Gems/Events.php 2012-02-15 12:42:58 UTC (rev 476) +++ branches/1.5.x/library/classes/Gems/Events.php 2012-02-15 13:07:26 UTC (rev 477) @@ -236,7 +236,7 @@ * @param string $eventName * @return Gems_Event_TrackCompletedEventInterface */ - public function loadTrackCompletionEvent($evetName) + public function loadTrackCompletionEvent($eventName) { return $this->_loadEvent($eventName, self::TRACK_COMPLETION_EVENT); } Modified: branches/1.5.x/library/classes/Gems/Tracker/Model/TrackModel.php =================================================================== --- branches/1.5.x/library/classes/Gems/Tracker/Model/TrackModel.php 2012-02-15 12:42:58 UTC (rev 476) +++ branches/1.5.x/library/classes/Gems/Tracker/Model/TrackModel.php 2012-02-15 13:07:26 UTC (rev 477) @@ -187,7 +187,7 @@ if (array_key_exists('gtr_completed_event', $track)) { if (!empty($track['gtr_completed_event'])) { - return $track['gtr_completed_event']; + return $this->loader->getEvents()->loadTrackCompletionEvent($track['gtr_completed_event']); } } } Modified: branches/1.5.x/library/classes/Gems/Tracker/RespondentTrack.php =================================================================== --- branches/1.5.x/library/classes/Gems/Tracker/RespondentTrack.php 2012-02-15 12:42:58 UTC (rev 476) +++ branches/1.5.x/library/classes/Gems/Tracker/RespondentTrack.php 2012-02-15 13:07:26 UTC (rev 477) @@ -633,11 +633,11 @@ */ public function handleTrackCompletion(&$values, $userId) { // Process any events - $trackEngine = $this->getTrackEngine(); + $trackModel = $this->tracker->getTrackModel(); //to be backward compatible, first check if the engine has a - if (is_callable(array($trackEngine, 'getTrackCompletionEvent'))) { - if ($event = $this->tracker->getTrackModel()->getTrackCompletionEvent($this->getTrackId())) { + if (is_callable(array($trackModel, 'getTrackCompletionEvent'))) { + if ($event = $trackModel->getTrackCompletionEvent($this->getTrackId())) { $event->processTrackCompletion($this, $values, $userId); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |