Skip to content

Commit

Permalink
Dev: New db version 261, creating seed column in active surveys
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Sep 1, 2016
1 parent 9d27351 commit 28272c6
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
2 changes: 1 addition & 1 deletion application/config/version.php
Expand Up @@ -13,7 +13,7 @@
*/

$config['versionnumber'] = '2.50';
$config['dbversionnumber'] = 260;
$config['dbversionnumber'] = 261;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['assetsversionnumber'] = '31';
Expand Down
2 changes: 0 additions & 2 deletions application/helpers/common_helper.php
Expand Up @@ -1810,15 +1810,13 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
$fieldmap["startlanguage"]['group_name']="";
}

/*
$fieldmap['seed'] = array('fieldname' => 'seed', 'sid' => $surveyid, 'type' => 'seed', 'gid' => '', 'qid' => '', 'aid' => '');
if ($style == 'full')
{
$fieldmap["seed"]['title']="";
$fieldmap["seed"]['question']=gT("Seed");
$fieldmap["seed"]['group_name']="";
}
*/

//Check for any additional fields for this survey and create necessary fields (token and datestamp and ipaddr)
$prow = Survey::model()->findByPk($surveyid)->getAttributes(); //Checked
Expand Down
48 changes: 46 additions & 2 deletions application/helpers/update/updatedb_helper.php
Expand Up @@ -27,7 +27,7 @@ function db_upgrade_all($iOldDBVersion, $bSilent=false) {
* @link https://manual.limesurvey.org/Database_versioning for explanations
* @var array $aCriticalDBVersions An array of cricital database version.
*/
$aCriticalDBVersions=array();
$aCriticalDBVersions=array(261);
$aAllUpdates=range($iOldDBVersion+1,Yii::app()->getConfig('dbversionnumber'));
// If trying to update silenty check if it is really possible
if ($bSilent && ($iOldDBVersion<258 || count(array_intersect($aCriticalDBVersions,$aAllUpdates))>0))
Expand Down Expand Up @@ -1433,16 +1433,60 @@ function db_upgrade_all($iOldDBVersion, $bSilent=false) {
$oDB->createCommand()->createIndex('notif_index', '{{notifications}}', 'entity, entity_id, status', false);
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>259),"stg_name='DBVersion'");
}

if ($iOldDBVersion < 260) {
alterColumn('{{participant_attribute_names}}','defaultname',"string(255)",false);
alterColumn('{{participant_attribute_names_lang}}','attribute_name',"string(255)",false);
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>260),"stg_name='DBVersion'");
}

/**
* Add seed column in all active survey tables
* Might take time to execute
* @since 2016-09-01
*/
if ($iOldDBVersion < 261) {

// Loop all surveys
$surveys = Survey::model()->findAll();
foreach ($surveys as $survey)
{
$prefix = Yii::app()->getDb()->tablePrefix;
$tableName = $prefix . 'survey_' . $survey->sid;

// If survey has active table, create seed column
$table = Yii::app()->db->schema->getTable($tableName);
if ($table)
{
if (!isset($table->columns['seed']))
{
Yii::app()->db->createCommand()->addColumn($tableName, 'seed', 'string(31)');
}
else
{
continue;
}

// RAND is RANDOM in Postgres
switch (Yii::app()->db->driverName)
{
case 'pgsql':
Yii::app()->db->createCommand("UPDATE $tableName SET seed = ROUND(RANDOM() * 10000000)")->execute();
break;
default:
Yii::app()->db->createCommand("UPDATE $tableName SET seed = ROUND(RAND() * 10000000, 0)")->execute();
break;
}
}
}
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>261),"stg_name='DBVersion'");
}

// Inform superadmin about update
$superadmins = User::model()->getSuperAdmins();
Notification::broadcast(array(
'title' => gT('Database update'),
'message' => sprintf(gT('The database has been updated from version %s to version %s.'), $iOldDBVersion, '260')
'message' => sprintf(gT('The database has been updated from version %s to version %s.'), $iOldDBVersion, '261')
), $superadmins);


Expand Down
2 changes: 1 addition & 1 deletion installer/sql/create-mssql.sql
Expand Up @@ -610,4 +610,4 @@ CREATE INDEX [notif_index] ON [prefix_notifications] ([entity_id],[entity],[stat
--
-- Version Info
--
INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '260');
INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '261');
2 changes: 1 addition & 1 deletion installer/sql/create-mysql.sql
Expand Up @@ -616,4 +616,4 @@ CREATE TABLE IF NOT EXISTS `prefix_notifications` (
--
-- Version Info
--
INSERT INTO `prefix_settings_global` VALUES ('DBVersion', '260');
INSERT INTO `prefix_settings_global` VALUES ('DBVersion', '261');
2 changes: 1 addition & 1 deletion installer/sql/create-pgsql.sql
Expand Up @@ -619,4 +619,4 @@ CREATE INDEX prefix_index ON prefix_notifications USING btree (entity, entity_id
--
-- Version Info
--
INSERT INTO prefix_settings_global VALUES ('DBVersion', '260');
INSERT INTO prefix_settings_global VALUES ('DBVersion', '261');

0 comments on commit 28272c6

Please sign in to comment.