Skip to content

Commit

Permalink
Fixed issue: SQL error on import if quota member code is too long
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Jun 19, 2023
1 parent 7f2e691 commit 5db6743
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
29 changes: 20 additions & 9 deletions application/helpers/admin/import_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2022,8 +2022,8 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
if (
$insertdata['attribute'] == 'alphasort'
|| (
$insertdata['attribute'] == 'random_order'
&& in_array($importedQuestions[$insertdata['qid']]->type, ['!', 'L', 'O', 'R'])
$insertdata['attribute'] == 'random_order'
&& in_array($importedQuestions[$insertdata['qid']]->type, ['!', 'L', 'O', 'R'])
)
) {
$answerOrderAttributes[$insertdata['qid']][$insertdata['attribute']] = $insertdata['value'];
Expand Down Expand Up @@ -2055,19 +2055,19 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
foreach ($answerOrderAttributes as $importedQid => $questionAttributes) {
if (!empty($questionAttributes['random_order'])) {
$insertdata = [
'qid' => $importedQid,
'attribute' => 'answer_order',
'value' => 'random',
'qid' => $importedQid,
'attribute' => 'answer_order',
'value' => 'random',
];
App()->db->createCommand()->insert('{{question_attributes}}', $insertdata);
$results['question_attributes']++;
continue;
}
if (!empty($questionAttributes['alphasort'])) {
$insertdata = [
'qid' => $importedQid,
'attribute' => 'answer_order',
'value' => 'alphabetical',
'qid' => $importedQid,
'attribute' => 'answer_order',
'value' => 'alphabetical',
];
App()->db->createCommand()->insert('{{question_attributes}}', $insertdata);
$results['question_attributes']++;
Expand Down Expand Up @@ -2228,8 +2228,19 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
unset($insertdata['id']);
// now translate any links
$quotaMember->setAttributes($insertdata, false);

if (!$quotaMember->validate()) {
// Display validation errors
foreach ($quotaMember->errors as $attribute => $errors) {
$errorText = '';
foreach ($errors as $error) {
$errorText .= 'Field "' . $attribute . '": ' . $error . " Value: '{$quotaMember->$attribute}'\n";
}
throw new Exception(gT("Error:") . " Failed to insert quota member" . "\n" . $errorText);
}
}
if (!$quotaMember->save()) {
throw new Exception(gT("Error") . ": Failed to insert data[13]<br />");
throw new Exception(gT("Error:") . " Failed to insert quota member database entry\n");
}
$results['quotamembers']++;
}
Expand Down
4 changes: 3 additions & 1 deletion application/models/QuotaMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public static function model($className = __CLASS__)
public function rules()
{
return array(
array('code', 'required', 'on' => array('create'))
array('code', 'required', 'on' => array('create')),
array('code', 'length', 'max' => 11)

);
}
/**
Expand Down

0 comments on commit 5db6743

Please sign in to comment.