Skip to content

Commit

Permalink
Importing huge response sets is now possible
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@11134 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Oct 10, 2011
1 parent f3fd19e commit 3ce4e14
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 70 deletions.
2 changes: 1 addition & 1 deletion application/controllers/admin/export.php
Expand Up @@ -105,7 +105,7 @@ function _surveyexport($action, $surveyid)
{
getXMLDataSingleTable($surveyid,'survey_'.$surveyid,'Responses','responses',$sLSRFileName, false);
$zip->add(array(array(PCLZIP_ATT_FILE_NAME=>$sLSRFileName,
PCLZIP_ATT_FILE_NEW_FULL_NAME =>'survey_'.$surveyid.'_responses.lss')));
PCLZIP_ATT_FILE_NEW_FULL_NAME =>'survey_'.$surveyid.'_responses.lsr')));
unlink($sLSRFileName);
}
if ($this->db->table_exists('tokens_'.$surveyid))
Expand Down
6 changes: 3 additions & 3 deletions application/controllers/admin/survey.php
Expand Up @@ -369,7 +369,7 @@ function view($surveyid,$gid=null,$qid=null)
$surveyid = sanitize_int($surveyid);
if(isset($gid)) $gid = sanitize_int($gid);
if(isset($qid)) $qid = sanitize_int($qid);

// show till question menubar.
if (!is_null($qid))
{
Expand Down Expand Up @@ -1041,8 +1041,8 @@ function copy()
// Start the HTML
if ($action == 'importsurvey')
{
$aData['sHeader']=$clang->gT("Import survey");
$aData['sSummaryHeader']=$clang->gT("Survey import summary");
$aData['sHeader']=$clang->gT("Import survey data");
$aData['sSummaryHeader']=$clang->gT("Survey structure import summary");
$importingfrom = "http";
}
elseif($action == 'copysurvey')
Expand Down
73 changes: 42 additions & 31 deletions application/helpers/admin/import_helper.php
Expand Up @@ -4057,45 +4057,56 @@ function XMLImportResponses($sFullFilepath,$iSurveyID,$aFieldReMap=array())

$CI->load->helper('database');
$clang = $CI->limesurvey_lang;
$xml = simplexml_load_file($sFullFilepath);

if ($xml->LimeSurveyDocType!='Responses')
{
$results['error'] = $clang->gT("This is not a valid response data XML file.");
return $results;
}

$results['responses']=0;

$aLanguagesSupported=array();
foreach ($xml->languages->language as $language)
{
$aLanguagesSupported[]=(string)$language;
}
$results['languages']=count($aLanguagesSupported);


$CI->load->model('surveys_dynamic_model');

db_switchIDInsert('survey_'.$iSurveyID,true);
foreach ($xml->responses->rows->row as $row)
{
$insertdata=array();

foreach ($row as $key=>$value)
db_switchIDInsert('survey_'.$iSurveyID,false);
$results['responses']=0;
$oXMLReader = new XMLReader();
$oXMLReader->open($sFullFilepath);
$DestinationFields = $CI->db->list_fields('survey_'.$iSurveyID);
while ($oXMLReader->read()) {
if ($oXMLReader->name === 'LimeSurveyDocType' && $oXMLReader->nodeType == XMLReader::ELEMENT)
{
if ($key[0]=='_') $key=substr($key,1);
if (isset($aFieldReMap[$key]))
$oXMLReader->read();
if ($oXMLReader->value!='Responses')
{
$key=$aFieldReMap[$key];
$results['error'] = $clang->gT("This is not a valid response data XML file.");
return $results;
}
$insertdata[$key]=(string)$value;
}
if ($oXMLReader->name === 'rows' && $oXMLReader->nodeType == XMLReader::ELEMENT)
{
while ($oXMLReader->read()) {
if ($oXMLReader->name === 'row' && $oXMLReader->nodeType == XMLReader::ELEMENT)
{
$aInsertData=array();
while ($oXMLReader->read() && $oXMLReader->name != 'row') {
$sFieldname=$oXMLReader->name;
if ($sFieldname[0]=='_') $sFieldname=substr($sFieldname,1);
if (isset($aFieldReMap[$sFieldname]))
{
$sFieldname=$aFieldReMap[$sFieldname];
}
if (!$oXMLReader->isEmptyElement)
{
$oXMLReader->read();
if(in_array($sFieldname,$DestinationFields)) // some old response tables contain invalid column names due to old bugs
$aInsertData[$sFieldname]=$oXMLReader->value;
$oXMLReader->read();
}else
{
if(in_array($sFieldname,$DestinationFields))
$aInsertData[$sFieldname]='';
}
}
$result = $CI->surveys_dynamic_model->insertRecords($iSurveyID,$aInsertData) or show_error($clang->gT("Error").": Failed to insert data<br />". $CI->db->last_query());
$results['responses']++;
}
}

$result = $CI->surveys_dynamic_model->insertRecords($iSurveyID,$insertdata) or show_error($clang->gT("Error").": Failed to insert data<br />");

$results['responses']++;
}
}

db_switchIDInsert('survey_'.$iSurveyID,false);

return $results;
Expand Down
78 changes: 43 additions & 35 deletions application/views/admin/survey/importSurvey_view.php
Expand Up @@ -5,23 +5,22 @@
<div class='errorheader'><?php $clang->eT("Error");?></div>
<?php echo $sErrorMessage; ?><br /><br />
<input type='submit' value='<?php $clang->eT("Main Admin Screen");?>' onclick="window.open('<?php echo site_url('admin');?>', '_top')"><br /><br /></div>
<?php } else
{?>
<div class='successheader'><?php $clang->eT("Success");?></div>&nbsp;<br />
<?php $clang->eT("File upload succeeded.");?> <?php $clang->eT("Reading file..");?><br />
<?php if (isset($aImportResults['error']) && $aImportResults['error']!=false)
{?>
<div class='warningheader'><?php $clang->eT("Error");?></div><br />
<?php echo $aImportResults['error']; ?><br /><br />
<input type='submit' value='<?php $clang->eT("Main Admin Screen");?>' onclick="window.open('<?php echo site_url('admin');?>', '_top')" />
<?php } else
{?>
<div class='successheader'><?php $clang->eT("Success");?></div>&nbsp;<br />
<?php $clang->eT("File upload succeeded.");?><br /><br />
<?php $clang->eT("Reading file..");?><br />
<?php if (isset($aImportResults['error']) && $aImportResults['error']!=false)
{?>
<div class='warningheader'><?php $clang->eT("Error");?></div><br />
<?php echo $aImportResults['error']; ?><br /><br />
<input type='submit' value='<?php $clang->eT("Main Admin Screen");?>' onclick="window.open('<?php echo site_url('admin');?>', '_top')" />
<?php } else
{?>

<br /><div class='successheader'><?php $clang->eT("Success");?></div><br /><br />
<strong><?php echo $sSummaryHeader; ?></strong><br />
<br /><div class='successheader'><?php $clang->eT("Success");?></div>
<strong><?php echo $sSummaryHeader; ?></strong><br />

<ul style=\"text-align:left;\">
<ul style="text-align:left;">
<li><?php $clang->eT("Surveys");?>: <?php echo $aImportResults['surveys'];?></li>
<li><?php $clang->eT("Languages");?>: <?php echo $aImportResults['languages'];?></li>
<li><?php $clang->eT("Question groups");?>: <?php echo $aImportResults['groups'];?></li>
Expand Down Expand Up @@ -51,29 +50,38 @@
<li><?php $clang->eT("Assessments");?>: <?php echo $aImportResults['assessments'];?></li>
<li><?php $clang->eT("Quotas");?>: <?php echo $aImportResults['quota'];?> (<?php echo $aImportResults['quotamembers']?> <?php $clang->eT("quota members");?> <?php $clang->eT("and");?> <?php echo $aImportResults['quotals']?> <?php $clang->eT("quota language settings"); ?></li>

</ul><br />
<?php
if (count($aImportResults['importwarnings'])>0)
{ ?>
<div class='warningheader'><?php $clang->eT("Warnings");?>:</div>
<ul style="text-align:left;">
</ul>
<?php
if (isset($aImportResults['responses']))
{?>
<strong><?php $clang->eT("Response import summary"); ?></strong><br />
<ul>
<li><?php $clang->eT("Responses");?>: <?php echo $aImportResults['responses'];?></li>
<?php }?>
</ul>
<br />
<?php
if (count($aImportResults['importwarnings'])>0)
{ ?>
<div class='warningheader'><?php $clang->eT("Warnings");?>:</div>
<ul style="text-align:left;">
<?php
foreach ($aImportResults['importwarnings'] as $warning)
{ ?>
<li><?php echo $warning; ?></li>
<?php
foreach ($aImportResults['importwarnings'] as $warning)
{ ?>
<li><?php echo $warning; ?></li>
<?php
} ?>
</ul><br />
<?php }
if ($action == 'importsurvey')
{?>
<strong><?php $clang->eT("Import of survey is completed.");?></strong><br />
<?php }
elseif($action == 'copysurvey')
{?>
<strong><?php $clang->eT("Copy of survey is completed.");?></strong><br />
<?php } ?>
<a href='<?php echo $sLink; ?>'><?php $clang->eT("Go to survey");?></a><br />
} ?>
</ul><br />
<?php }
if ($action == 'importsurvey')
{?>
<strong><?php $clang->eT("Import of survey is completed.");?></strong><br />
<?php }
elseif($action == 'copysurvey')
{?>
<strong><?php $clang->eT("Copy of survey is completed.");?></strong><br />
<?php } ?>
<a href='<?php echo $sLink; ?>'><?php $clang->eT("Go to survey");?></a><br />
<?php } ?>
</div><br />
<?php }?>

0 comments on commit 3ce4e14

Please sign in to comment.