Skip to content

Commit

Permalink
Fixed issue #17029: import wrong question attribute values ('Y' or 'N')
Browse files Browse the repository at this point in the history
  • Loading branch information
Trischi80 committed Mar 10, 2021
1 parent 1046aee commit 610446d
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion application/helpers/admin/import_helper.php
Expand Up @@ -985,6 +985,7 @@ function XMLImportQuestion($sFullFilePath, $iNewSID, $iNewGID, $options = array(

$attributes->save();
}
checkWrongQuestionAttributes($insertdata['qid']);
$results['question_attributes']++;
}
}
Expand Down Expand Up @@ -1926,7 +1927,7 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
safeDie(gT("Error") . ": Failed to insert data[8]<br />");
}
}

checkWrongQuestionAttributes($insertdata['qid']);
$results['question_attributes']++;
}
}
Expand Down Expand Up @@ -2325,6 +2326,34 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
return $results;
}

/**
* This function checks if there are set wrong values ('Y' or 'N') into table
* question_attributes. These are set to 1 and 0 if needed.
*
* @param $questionId
*/
function checkWrongQuestionAttributes($questionId){
//these attributes could be wrongly set to 'Y' or 'N' instead of 1 and 0
$attributesTobeChecked = ['statistics_showgraph', 'public_statistics' , 'page_break' , 'other_numbers_only',
'other_comment_mandatory', 'hide_tip' , 'hidden', 'exclude_all_others_auto',
'commented_checkbox_auto', 'num_value_int_only', 'alphasort', 'use_dropdown',
'slider_default_set', 'slider_layout', 'slider_middlestart', 'slider_reset',
'slider_reversed', 'slider_showminmax', 'value_range_allows_missing'];
$questionAttributes = QuestionAttribute::model()->findAllByAttributes(['qid' => $questionId]);
foreach($questionAttributes as $questionAttribute){
if(in_array($questionAttribute->attribute, $attributesTobeChecked)){
//now check if value is 0 or 1 (if not then reset the wrong values ('Y' or 'N')
if($questionAttribute->value === 'Y'){
$questionAttribute->value = 1;
$questionAttribute->save();
}elseif($questionAttribute->value === 'N'){
$questionAttribute->value = 0;
$questionAttribute->save();
}
}
}
}

/**
* @param string $sFullFilePath
* @return mixed
Expand Down

0 comments on commit 610446d

Please sign in to comment.