Skip to content

Commit

Permalink
Fixed issue #9934: Survey cannot be repeatedly activated in MSSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Oct 16, 2015
1 parent 57361d9 commit f3f6ed7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions application/helpers/admin/activate_helper.php
Expand Up @@ -83,7 +83,7 @@ function fixNumbering($iQuestionID, $iSurveyID)
*/
function checkGroup($postsid)
{


$baselang = Survey::model()->findByPk($postsid)->language;
$groupquery = "SELECT g.gid,g.group_name,count(q.qid) as count from {{questions}} as q RIGHT JOIN {{groups}} as g ON q.gid=g.gid AND g.language=q.language WHERE g.sid=$postsid AND g.language='$baselang' group by g.gid,g.group_name;";
Expand All @@ -109,7 +109,7 @@ function checkGroup($postsid)
*/
function checkQuestions($postsid, $iSurveyID, $qtypes)
{


//CHECK TO MAKE SURE ALL QUESTION TYPES THAT REQUIRE ANSWERS HAVE ACTUALLY GOT ANSWERS
//THESE QUESTION TYPES ARE:
Expand Down Expand Up @@ -350,7 +350,7 @@ function activateSurvey($iSurveyID, $simulate = false)
}
if (Yii::app()->db->driverName=='sqlsrv' | Yii::app()->db->driverName=='dblib' | Yii::app()->db->driverName=='mssql'){
$sCollation=" COLLATE SQL_Latin1_General_CP1_CS_AS";
}
}
$createsurvey[$arow['fieldname']] = 'string(35)'.$sCollation;
break;
case '*': // Equation
Expand Down Expand Up @@ -385,7 +385,7 @@ function activateSurvey($iSurveyID, $simulate = false)
$tabname = "{{survey_{$iSurveyID}}}";
Yii::app()->loadHelper("database");
try
{
{
$execresult = Yii::app()->db->createCommand()->createTable($tabname, $createsurvey);
Yii::app()->db->schema->getTable($tabname, true); // Refresh schema cache just in case the table existed in the past
}
Expand Down Expand Up @@ -421,7 +421,8 @@ function activateSurvey($iSurveyID, $simulate = false)
$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');

Yii::app()->db->createCommand()->addPrimaryKey('PRIMARY_'.rand(1,50000), '{{survey_'.$iSurveyID.'}}', 'id');
}
elseif (Yii::app()->db->driverName=='pgsql')
{
Expand Down

0 comments on commit f3f6ed7

Please sign in to comment.