Skip to content

Commit

Permalink
Fixed issue #9811: Unable to delete responses
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Aug 4, 2015
1 parent f2b84ca commit 62df1a7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion application/config/version.php
Expand Up @@ -13,7 +13,7 @@
*/

$config['versionnumber'] = "2.06+";
$config['dbversionnumber'] = 182;
$config['dbversionnumber'] = 183;
$config['buildnumber'] = '';
$config['updatable'] = true;

Expand Down
6 changes: 4 additions & 2 deletions application/helpers/admin/activate_helper.php
Expand Up @@ -409,10 +409,12 @@ function activateSurvey($iSurveyID, $simulate = false)
if (Yii::app()->db->driverName=='mssql' || Yii::app()->db->driverName=='sqlsrv' || Yii::app()->db->driverName=='dblib') {
mssql_drop_primary_index('survey_'.$iSurveyID);
mssql_drop_constraint('id','survey_'.$iSurveyID);
$sQuery = "alter table {{survey_{$iSurveyID}}} drop column id ";
$sQuery = "ALTER TABLE {{survey_{$iSurveyID}}} drop column id ";
Yii::app()->db->createCommand($sQuery)->execute();
$sQuery = "alter table {{survey_{$iSurveyID}}} add [id] int identity({$iAutoNumberStart},1)";
$sQuery = "ALTER TABLE {{survey_{$iSurveyID}}} ADD [id] int identity({$iAutoNumberStart},1)";
Yii::app()->db->createCommand($sQuery)->execute();
// Add back the primaryKey
Yii::app()->db->createCommand()->addPrimaryKey('PRIMARY', '{{survey_'.$iSurveyID.'}}', 'id');
}
elseif (Yii::app()->db->driverName=='pgsql')
{
Expand Down
30 changes: 29 additions & 1 deletion application/helpers/update/updatedb_helper.php
Expand Up @@ -1309,6 +1309,11 @@ function db_upgrade_all($iOldDBVersion) {
fixKCFinder182();
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>182),"stg_name='DBVersion'");
}
if ($iOldDBVersion < 183)
{
upgradeSurveyTables183();
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>183),"stg_name='DBVersion'");
}
$oTransaction->commit();
// Activate schema caching
$oDB->schemaCachingDuration=3600;
Expand All @@ -1334,6 +1339,29 @@ function db_upgrade_all($iOldDBVersion) {
return true;
}


function upgradeSurveyTables183()
{
$oDB = Yii::app()->db;
$oSchema = Yii::app()->db->schema;
if(Yii::app()->db->driverName!='pgsql')
{
$aTables = dbGetTablesLike("survey\_%");
if ($aTables)
{
foreach ( $aTables as $sTableName )
{
$oTableSchema=$oSchema->getTable($sTableName);
if (empty($oTableSchema->primaryKey))
{
addPrimaryKey(substr($sTableName,strlen(Yii::app()->getDb()->tablePrefix)), 'id');
}
}
}
}
}


function fixKCFinder182()
{
$sThirdPartyDir=Yii::app()->getConfig('standardtemplaterootdir').DIRECTORY_SEPARATOR.'third_party'.DIRECTORY_SEPARATOR;
Expand Down Expand Up @@ -2184,7 +2212,7 @@ function alterLanguageCode($sOldLanguageCode,$sNewLanguageCode)

function addPrimaryKey($sTablename, $aColumns)
{
return Yii::app()->db->createCommand()->addPrimaryKey('PRIMARY', '{{'.$sTablename.'}}', $aColumns);
return Yii::app()->db->createCommand()->addPrimaryKey('PK_'.$sTablename.'_'.randomChars(12,'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'), '{{'.$sTablename.'}}', $aColumns);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion installer/sql/create-mssql.sql
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', '182');
INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '183');
2 changes: 1 addition & 1 deletion installer/sql/create-mysql.sql
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', '182');
INSERT INTO `prefix_settings_global` VALUES ('DBVersion', '183');
2 changes: 1 addition & 1 deletion installer/sql/create-pgsql.sql
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', '182');
INSERT INTO prefix_settings_global VALUES ('DBVersion', '183');

0 comments on commit 62df1a7

Please sign in to comment.