Skip to content

Commit

Permalink
Fixed issue: Database not completely updated if updating from an earl…
Browse files Browse the repository at this point in the history
…ier version than 2.6.x
  • Loading branch information
c-schmitz committed Oct 18, 2017
1 parent d0ae870 commit 4ced966
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 3 deletions.
103 changes: 102 additions & 1 deletion application/helpers/update/updatedb_helper.php
Expand Up @@ -34,7 +34,7 @@ function db_upgrade_all($iOldDBVersion, $bSilent=false) {
return false;
}
// If DBVersion is older than 258 don't allow database update
If ($iOldDBVersion<258)
If ($iOldDBVersion<184)
{
return false;
}
Expand All @@ -51,6 +51,107 @@ function db_upgrade_all($iOldDBVersion, $bSilent=false) {
Yii::app()->setConfig('Updating',true);

try{
// LS 2.5 table start at 250
if ($iOldDBVersion < 250)
{
$oTransaction = $oDB->beginTransaction();
createBoxes250();
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>250),"stg_name='DBVersion'");
$oTransaction->commit();
}

if ( $iOldDBVersion < 251 )
{
$oTransaction = $oDB->beginTransaction();
upgradeBoxesTable251();

// Update DBVersion
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>251),"stg_name='DBVersion'");
$oTransaction->commit();
}

if ( $iOldDBVersion < 252 )
{
$oTransaction = $oDB->beginTransaction();
Yii::app()->db->createCommand()->addColumn('{{questions}}','modulename','string');
// Update DBVersion
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>252),"stg_name='DBVersion'");
$oTransaction->commit();
}
if ( $iOldDBVersion < 253 )
{
$oTransaction = $oDB->beginTransaction();
upgradeSurveyTables253();

// Update DBVersion
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>253),"stg_name='DBVersion'");
$oTransaction->commit();
}
if ( $iOldDBVersion < 254 )
{
$oTransaction = $oDB->beginTransaction();
upgradeSurveyTables254();
// Update DBVersion
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>254),"stg_name='DBVersion'");
$oTransaction->commit();
}
if ( $iOldDBVersion < 255 )
{
$oTransaction = $oDB->beginTransaction();
upgradeSurveyTables255();
// Update DBVersion
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>255),"stg_name='DBVersion'");
$oTransaction->commit();
}
if ( $iOldDBVersion < 256 )
{
$oTransaction = $oDB->beginTransaction();
upgradeTokenTables256();
alterColumn('{{participants}}', 'email', "text", false);
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>256),"stg_name='DBVersion'");
$oTransaction->commit();
}

if ($iOldDBVersion < 257) {
$oTransaction = $oDB->beginTransaction();
switch (Yii::app()->db->driverName){
case 'pgsql':
$sSubstringCommand='substr';
break;
default:
$sSubstringCommand='substring';
}
$oDB->createCommand("UPDATE {{templates}} set folder={$sSubstringCommand}(folder,1,50)")->execute();
dropPrimaryKey('templates');
alterColumn('{{templates}}', 'folder', "string(50)", false);
addPrimaryKey('templates', 'folder');
dropPrimaryKey('participant_attribute_names_lang');
alterColumn('{{participant_attribute_names_lang}}', 'lang', "string(20)", false);
addPrimaryKey('participant_attribute_names_lang', array('attribute_id','lang'));
//Fixes the collation for the complete DB, tables and columns
if (Yii::app()->db->driverName=='mysql')
{
fixMySQLCollations('utf8mb4','utf8mb4_unicode_ci');
// Also apply again fixes from DBVersion 181 again for case sensitive token fields
upgradeSurveyTables181('utf8mb4_bin');
upgradeTokenTables181('utf8mb4_bin');
}
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>257),"stg_name='DBVersion'");
$oTransaction->commit();
}

/**
* Remove adminimageurl from global settings
*/
if ($iOldDBVersion < 258) {
$oTransaction = $oDB->beginTransaction();
Yii::app()->getDb()->createCommand(
"DELETE FROM {{settings_global}} WHERE stg_name='adminimageurl'"
)->execute();
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>258),"stg_name='DBVersion'");
$oTransaction->commit();
}

/**
* Add table for notifications
* @since 2016-08-04
Expand Down
4 changes: 2 additions & 2 deletions application/views/admin/databaseupdate/verify.php
Expand Up @@ -15,11 +15,11 @@
</div>
</div>

<?php if ((int)GetGlobalSetting('DBVersion')<258) { ?>
<?php if ((int)GetGlobalSetting('DBVersion')<184) { ?>
<div class="alert alert-danger" role="alert">
<strong><?php echo eT("Error:"); ?></strong> <?php eT("You will not be able to update because your previous LimeSurvey version is too old.");?>
<br>
<?php eT("Please first update to Version 2.6.x or later before you update to Version 3.x."); ?>
<?php eT("Please first update to Version 2.6.4 or any later 2.x version before you update to Version 3.x."); ?>
</div>


Expand Down

0 comments on commit 4ced966

Please sign in to comment.