Skip to content

Commit

Permalink
Fixed issue #13548: Import survey process fails sometimes with data c…
Browse files Browse the repository at this point in the history
…onditions
  • Loading branch information
dominikvitt committed Jun 26, 2018
1 parent 92fef12 commit 6028488
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 13 additions & 2 deletions application/helpers/admin/import_helper.php
Expand Up @@ -1009,6 +1009,7 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
// We have to run the question table data two times - first to find all main questions
// then for subquestions (because we need to determine the new qids for the main questions first)
// there could be surveys without a any questions
$aQuestionsMapping = array(); // collect all old and new question codes for replacement
if (isset($xml->questions)) {

foreach ($xml->questions->rows->row as $row) {
Expand All @@ -1022,7 +1023,8 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
continue;
}

$iOldSID = $insertdata['sid'];
$iOldSID = $insertdata['sid'];
$iOldGID = $insertdata['gid'];
$insertdata['sid'] = $iNewSID;
$insertdata['gid'] = $aGIDReplacements[$insertdata['gid']];
$oldqid = $insertdata['qid']; unset($insertdata['qid']); // save the old qid
Expand Down Expand Up @@ -1104,6 +1106,9 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
} else {
switchMSSQLIdentityInsert('questions', false);
}

// question codes in format "38612X105X3011" are collected for replacing
$aQuestionsMapping[$iOldSID.'X'.$iOldGID.'X'.$oldqid] = $iNewSID.'X'.$oQuestion->gid.'X'.$oQuestion->qid;
}
}

Expand All @@ -1123,10 +1128,12 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
$insertdata['mandatory'] = 'N';
}

$insertdata['sid'] = $iNewSID;
$insertdata['sid'] = $iNewSID;
$iOldGID = $insertdata['gid'];
$insertdata['gid'] = $aGIDReplacements[(int) $insertdata['gid']]; ;
$oldsqid = (int) $insertdata['qid']; unset($insertdata['qid']); // save the old qid
$insertdata['parent_qid'] = $aQIDReplacements[(int) $insertdata['parent_qid']]; // remap the parent_qid
$sOldTitle = '';

// now translate any links
if ($bTranslateInsertansTags) {
Expand Down Expand Up @@ -1212,6 +1219,9 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
} else {
switchMSSQLIdentityInsert('questions', false);
}

// question codes in format "38612X105X3011" are collected for replacing
$aQuestionsMapping[$iOldSID.'X'.$iOldGID.'X'.$oldqid.$question->title] = $iNewSID.'X'.$oQuestion->gid.'X'.$oQuestion->qid.$question->title;
}
}

Expand Down Expand Up @@ -1525,6 +1535,7 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
LimeExpressionManager::SetSurveyId($iNewSID);
translateInsertansTags($iNewSID, $iOldSID, $aOldNewFieldmap);
replaceExpressionCodes($iNewSID, $aQuestionCodeReplacements);
replaceExpressionCodes($iNewSID, $aQuestionsMapping); // replace question codes in format "38612X105X3011"
if (count($aQuestionCodeReplacements)) {
array_unshift($results['importwarnings'], "<span class='warningtitle'>".gT('Attention: Several question codes were updated. Please check these carefully as the update may not be perfect with customized expressions.').'</span>');
}
Expand Down
6 changes: 3 additions & 3 deletions application/helpers/common_helper.php
Expand Up @@ -3625,9 +3625,9 @@ function replaceExpressionCodes($iSurveyID, $aCodeMap)
$bModified = false;
foreach ($aCodeMap as $sOldCode=>$sNewCode) {
// Don't search/replace old codes that are too short or were numeric (because they would not have been usable in EM expressions anyway)
if (strlen($sOldCode) > 1 && !is_numeric($sOldCode[0])) {
if (strlen($sOldCode) > 1 && !is_numeric($sOldCode)) {
$sOldCode = preg_quote($sOldCode, '~');
$arQuestion->relevance = preg_replace("~{[^}]*\K{$sOldCode}(?=[^}]*?})~", $sNewCode, $arQuestion->relevance, -1, $iCount);
$arQuestion->relevance=preg_replace("/\b{$sOldCode}/",$sNewCode,$arQuestion->relevance,-1,$iCount);
$bModified = $bModified || $iCount;
$arQuestion->question = preg_replace("~{[^}]*\K{$sOldCode}(?=[^}]*?})~", $sNewCode, $arQuestion->question, -1, $iCount);
$bModified = $bModified || $iCount;
Expand All @@ -3642,7 +3642,7 @@ function replaceExpressionCodes($iSurveyID, $aCodeMap)
$bModified = false;
foreach ($aCodeMap as $sOldCode=>$sNewCode) {
$sOldCode = preg_quote($sOldCode, '~');
$arGroup->grelevance = preg_replace("~{[^}]*\K{$sOldCode}(?=[^}]*?})~", $sNewCode, $arGroup->grelevance, -1, $iCount);
$arGroup->grelevance=preg_replace("~{[^}]*\K{$sOldCode}(?=[^}]*?})~",$sNewCode,$arGroup->grelevance,-1,$iCount);
$bModified = $bModified || $iCount;
$arGroup->description = preg_replace("~{[^}]*\K{$sOldCode}(?=[^}]*?})~", $sNewCode, $arGroup->description, -1, $iCount);
$bModified = $bModified || $iCount;
Expand Down

0 comments on commit 6028488

Please sign in to comment.