From 60284888e77199b5dcf20cf22a42a29462e840a3 Mon Sep 17 00:00:00 2001 From: Dominik Vitt Date: Tue, 26 Jun 2018 16:08:31 +0200 Subject: [PATCH] Fixed issue #13548: Import survey process fails sometimes with data conditions --- application/helpers/admin/import_helper.php | 15 +++++++++++++-- application/helpers/common_helper.php | 6 +++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/application/helpers/admin/import_helper.php b/application/helpers/admin/import_helper.php index d12d01dab99..bc547205891 100644 --- a/application/helpers/admin/import_helper.php +++ b/application/helpers/admin/import_helper.php @@ -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) { @@ -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 @@ -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; } } @@ -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) { @@ -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; } } @@ -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'], "".gT('Attention: Several question codes were updated. Please check these carefully as the update may not be perfect with customized expressions.').''); } diff --git a/application/helpers/common_helper.php b/application/helpers/common_helper.php index fae88d48084..5ed14911fbb 100644 --- a/application/helpers/common_helper.php +++ b/application/helpers/common_helper.php @@ -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; @@ -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;