Skip to content

Commit

Permalink
Fixed issue #9339: Duplicate questions IDs used when new survey that …
Browse files Browse the repository at this point in the history
…has different based language than previous surveys
  • Loading branch information
c-schmitz committed Nov 7, 2014
1 parent 0a0633a commit 71e7bc1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion application/config/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

$config['versionnumber'] = "2.05+";
$config['dbversionnumber'] = 177;
$config['dbversionnumber'] = 178;
$config['buildnumber'] = '';
$config['updatable'] = true;

Expand Down
19 changes: 18 additions & 1 deletion application/helpers/update/updatedb_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,14 @@ function db_upgrade_all($iOldDBVersion) {
upgradeSurveys177();
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>177),"stg_name='DBVersion'");
}

if ($iOldDBVersion < 178)
{
if ($sDBDriverName=='mysql' || $sDBDriverName='mysqli')
{
modifyPrimaryKey('questions', array('qid','language'));
}
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>178),"stg_name='DBVersion'");
}

$oTransaction->commit();
// Activate schema caching
Expand Down Expand Up @@ -2031,6 +2038,16 @@ function addPrimaryKey($sTablename, $aColumns)
Yii::app()->db->createCommand("ALTER TABLE {{".$sTablename."}} ADD PRIMARY KEY (".implode(',',$aColumns).")")->execute();
}

/**
* Modifies a primary key in one command - this is only tested on MySQL
*
* @param string $sTablename The table name
* @param array $aColumns Column names to be in the new key
*/
function modifyPrimaryKey($sTablename, $aColumns)
{
Yii::app()->db->createCommand("ALTER TABLE {{".$sTablename."}} DROP PRIMARY KEY, ADD PRIMARY KEY (".implode(',',$aColumns).")")->execute();
}

function dropPrimaryKey($sTablename)
{
Expand Down
2 changes: 1 addition & 1 deletion installer/sql/create-mssql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -566,4 +566,4 @@ create index [parent_qid_idx] on [prefix_questions] ([parent_qid]);
--
-- Version Info
--
INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '177');
INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '178');
4 changes: 2 additions & 2 deletions installer/sql/create-mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ CREATE TABLE `prefix_questions` (
`scale_id` int(11) NOT NULL default '0',
`same_default` int(11) NOT NULL default '0' COMMENT 'Saves if user set to use the same default value across languages in default options dialog',
`relevance` text,
PRIMARY KEY (`language`, `qid`)
PRIMARY KEY (`qid`,`language`)
) ENGINE=MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;


Expand Down Expand Up @@ -575,4 +575,4 @@ CREATE INDEX `parent_qid_idx` ON `prefix_questions` (`parent_qid`);
--
-- Version Info
--
INSERT INTO `prefix_settings_global` VALUES ('DBVersion', '177');
INSERT INTO `prefix_settings_global` VALUES ('DBVersion', '178');
2 changes: 1 addition & 1 deletion installer/sql/create-pgsql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -576,4 +576,4 @@ create unique index permissions_idx2 ON prefix_permissions (entity_id, entity, u
--
-- Version Info
--
INSERT INTO prefix_settings_global VALUES ('DBVersion', '177');
INSERT INTO prefix_settings_global VALUES ('DBVersion', '178');

0 comments on commit 71e7bc1

Please sign in to comment.