Skip to content

Commit

Permalink
Fixed issue #6595: Data restore from old_survey_... table fails when …
Browse files Browse the repository at this point in the history
…using Postgres
  • Loading branch information
c-schmitz committed Oct 9, 2012
1 parent 3996fea commit f535bbb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions application/controllers/admin/dataentry.php
Expand Up @@ -441,11 +441,13 @@ function import($surveyid)
{
$iOldID=$row['id'];
unset($row['id']);

// Remove NULL values
$row=array_filter($row, 'strlen');
//$sInsertSQL=Yii::app()->db->GetInsertSQL($activetable, $row);
$sInsertSQL="INSERT into {$activetable} (".implode(",", array_map("dbQuoteID", array_keys($row))).") VALUES (".implode(",", array_map("dbQuoteAll",array_values($row))).")";
$result = dbExecuteAssoc($sInsertSQL) or show_error("Error:<br />$sInsertSQL<br />");
$aSRIDConversions[$iOldID]=Yii::app()->db->getLastInsertID();

$aSRIDConversions[$iOldID] = Yii::app()->db->getCommandBuilder()->getLastInsertID($activetable);
$iRecordCount++;
}

Expand Down
14 changes: 9 additions & 5 deletions application/helpers/admin/import_helper.php
Expand Up @@ -3477,7 +3477,7 @@ function XMLImportSurvey($sFullFilepath,$sXMLdata=NULL,$sNewSurveyName=NULL,$iDe
$insertdata['showxquestions']=$insertdata['showXquestions'];
unset($insertdata['showXquestions']);
}
$iNewSID = $results['newsid'] = Survey::model()->insertNewSurvey($insertdata) or safeDie($clang->gT("Error").": Failed to insert data<br />");
$iNewSID = $results['newsid'] = Survey::model()->insertNewSurvey($insertdata) or safeDie($clang->gT("Error").": Failed to insert data [1]<br />");

$results['surveys']++;
}
Expand Down Expand Up @@ -3516,7 +3516,7 @@ function XMLImportSurvey($sFullFilepath,$sXMLdata=NULL,$sNewSurveyName=NULL,$iDe
}


$result = Surveys_languagesettings::model()->insertNewSurvey($insertdata) or safeDie($clang->gT("Error").": Failed to insert data<br />");
$result = Surveys_languagesettings::model()->insertNewSurvey($insertdata) or safeDie($clang->gT("Error").": Failed to insert data [2]<br />");
}


Expand Down Expand Up @@ -3549,7 +3549,7 @@ function XMLImportSurvey($sFullFilepath,$sXMLdata=NULL,$sNewSurveyName=NULL,$iDe
switchMSSQLIdentityInsert('groups',true);
$insertdata['gid']=$aGIDReplacements[$oldgid];
}
$newgid = Groups::model()->insertRecords($insertdata) or safeDie($clang->gT("Error").": Failed to insert data<br />");
$newgid = Groups::model()->insertRecords($insertdata) or safeDie($clang->gT("Error").": Failed to insert data [3]<br />");
$results['groups']++;

if (!isset($aGIDReplacements[$oldgid]))
Expand Down Expand Up @@ -3598,7 +3598,7 @@ function XMLImportSurvey($sFullFilepath,$sXMLdata=NULL,$sNewSurveyName=NULL,$iDe
}
if ($insertdata)
XSSFilterArray($insertdata);
$newqid = Questions::model()->insertRecords($insertdata) or safeDie($clang->gT("Error").": Failed to insert data<br />");
$newqid = Questions::model()->insertRecords($insertdata) or safeDie($clang->gT("Error").": Failed to insert data [4]<br />");
if (!isset($aQIDReplacements[$oldqid]))
{
$aQIDReplacements[$oldqid]=$newqid;
Expand All @@ -3623,6 +3623,10 @@ function XMLImportSurvey($sFullFilepath,$sXMLdata=NULL,$sNewSurveyName=NULL,$iDe
$insertdata[(string)$key]=(string)$value;
}
if (!in_array($insertdata['language'],$aLanguagesSupported)) continue;
if (trim($insertdata['mandatory'])=='')
{
$insertdata['mandatory']='N';
}
$insertdata['sid']=$iNewSID;
$insertdata['gid']=$aGIDReplacements[(int)$insertdata['gid']];;
$oldsqid=(int)$insertdata['qid']; unset($insertdata['qid']); // save the old qid
Expand All @@ -3640,7 +3644,7 @@ function XMLImportSurvey($sFullFilepath,$sXMLdata=NULL,$sNewSurveyName=NULL,$iDe
}
if ($insertdata)
XSSFilterArray($insertdata);
$newsqid =Questions::model()->insertRecords($insertdata) or safeDie($clang->gT("Error").": Failed to insert data<br />");
$newsqid =Questions::model()->insertRecords($insertdata) or safeDie($clang->gT("Error").": Failed to insert data [5]<br />");
if (!isset($insertdata['qid']))
{
$aQIDReplacements[$oldsqid]=$newsqid; // add old and new qid to the mapping array
Expand Down
1 change: 0 additions & 1 deletion application/helpers/database_helper.php
Expand Up @@ -164,7 +164,6 @@ function dbSelectTablesLike($table)
case 'sqlsrv' :
return "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES where TABLE_TYPE='BASE TABLE' and TABLE_NAME LIKE '$table' ESCAPE '\'";
case 'pgsql' :
$table=str_replace('\\','\\\\',$table);
return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' and table_name like '$table'";
default: safeDie ("Couldn't create 'select tables like' query for connection type '".Yii::app()->db->getDriverName()."'");
}
Expand Down
3 changes: 1 addition & 2 deletions application/helpers/frontend_helper.php
Expand Up @@ -1748,8 +1748,7 @@ function buildsurveysession($surveyid,$previewGroup=false)
." WHERE {{questions}}.sid=".$surveyid."\n"
." AND {{groups}}.language='".$_SESSION['survey_'.$surveyid]['s_lang']."'\n"
." AND {{questions}}.language='".$_SESSION['survey_'.$surveyid]['s_lang']."'\n"
." AND {{questions}}.parent_qid=0\n"
." ORDER BY {{groups}}.group_order,{{questions}}.question_order";
." AND {{questions}}.parent_qid=0\n";

$totalquestions = Yii::app()->db->createCommand($sQuery)->queryScalar();

Expand Down

0 comments on commit f535bbb

Please sign in to comment.