Skip to content

Commit

Permalink
Dev: Remove collation from object state (can be passed around - or be…
Browse files Browse the repository at this point in the history
…tter, be input to new class TableDefinitionPreparer)
  • Loading branch information
olleharstedt committed Mar 11, 2020
1 parent 9cedd88 commit b2b91fa
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions application/models/SurveyActivator.php
Expand Up @@ -18,9 +18,6 @@ class SurveyActivator
/** @var array */
protected $fieldMap;

/** @var string */
protected $collation;

/** @var string */
protected $error;

Expand Down Expand Up @@ -107,9 +104,11 @@ public function activate()

/**
* For each question, create the appropriate field(s)
*
* @param string $collation
* @return void
*/
protected function prepareTableDefinition()
protected function prepareTableDefinition(string $collation)
{
$sFieldMap = $this->fieldMap;

Expand Down Expand Up @@ -190,7 +189,7 @@ protected function prepareTableDefinition()
}
break;
case "token":
$aTableDefinition[$aRow['fieldname']] = 'string(' . Token::MAX_LENGTH . ')'.$this->collation;
$aTableDefinition[$aRow['fieldname']] = 'string(' . Token::MAX_LENGTH . ')'.$collation;
break;
case Question::QT_ASTERISK_EQUATION:
$aTableDefinition[$aRow['fieldname']] = isset($aRow['answertabledefinition']) && !empty($aRow['answertabledefinition']) ? $aRow['answertabledefinition'] : "text";
Expand Down Expand Up @@ -224,7 +223,7 @@ protected function prepareTableDefinition()
$aTableDefinition[$aRow['fieldname']] = (array_key_exists('encrypted', $aRow) && $aRow['encrypted'] == 'Y') ? "text" : (isset($aRow['answertabledefinition']) && !empty($aRow['answertabledefinition']) ? $aRow['answertabledefinition'] : "string(5)");
}
if (!$this->survey->isAnonymized && !array_key_exists('token', $aTableDefinition)) {
$aTableDefinition['token'] = 'string('.Token::MAX_LENGTH.')'.$this->collation;
$aTableDefinition['token'] = 'string('.Token::MAX_LENGTH.')'.$collation;
}
}
$this->tableDefinition = $aTableDefinition;
Expand All @@ -251,20 +250,21 @@ protected function prepareTimingsTable()
}

/**
* @return void
* @return string
*/
protected function prepareCollation()
protected function getCollation()
{
// Specify case sensitive collations for the token
$this->collation = '';
$collation = '';
if (Yii::app()->db->driverName == 'mysqli' || Yii::app()->db->driverName == 'mysql') {
$this->collation = " COLLATE 'utf8mb4_bin'";
$collation = " COLLATE 'utf8mb4_bin'";
}
if (Yii::app()->db->driverName == 'sqlsrv'
|| Yii::app()->db->driverName == 'dblib'
|| Yii::app()->db->driverName == 'mssql') {
$this->collation = " COLLATE SQL_Latin1_General_CP1_CS_AS";
$collation = " COLLATE SQL_Latin1_General_CP1_CS_AS";
}
return $collation;
}

/**
Expand All @@ -290,12 +290,13 @@ protected function prepareSimulateQuery()
*/
protected function prepareResponsesTable()
{
$this->prepareCollation();
/** @var string */
$collation = $this->getCollation();
//Check for any additional fields for this survey and create necessary fields (token and datestamp)
$this->survey->fixInvalidQuestions();
//Get list of questions for the base language
$this->fieldMap = createFieldMap($this->survey, 'full', true, false, $this->survey->language);
$this->prepareTableDefinition();
$this->prepareTableDefinition($collation);
$this->prepareSimulateQuery();
}

Expand Down

0 comments on commit b2b91fa

Please sign in to comment.