Skip to content

Commit

Permalink
Fixed issue #16694: Export multiple surveys (lss, lsa) to ZIP crashes…
Browse files Browse the repository at this point in the history
… or does not export reports/tokens for correct survey

In 'buildXMLFromQuery', the survey ID is needed for response and token decryption.
It was being derived from session. which worked when exporting a single survey info, or from within a survey. Now an optional parameter was added so the ID can be specified by the caller.
  • Loading branch information
gabrieljenik authored and eddylackmann committed Oct 8, 2020
1 parent e71c7d2 commit 88a9a28
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions application/helpers/export_helper.php
Expand Up @@ -708,7 +708,7 @@ function SPSSGetQuery($iSurveyID, $limit = null, $offset = null)
* @param string $tagname If the XML tag of the resulting question should be named differently than the table name set it here
* @param string[] $excludes array of columnames not to include in export
*/
function buildXMLFromQuery($xmlwriter, $Query, $tagname = '', $excludes = array())
function buildXMLFromQuery($xmlwriter, $Query, $tagname = '', $excludes = array(), $iSurveyID = 0)
{
$iChunkSize = 3000; // This works even for very large result sets and leaves a minimal memory footprint

Expand All @@ -731,9 +731,9 @@ function buildXMLFromQuery($xmlwriter, $Query, $tagname = '', $excludes = array(
$criteria->limit = $iChunkSize;
$criteria->offset = $iStart;
if ($TableName == 'responses'){
$results = Response::model(Yii::app()->session['LEMsid'])->findAll($criteria);
$results = Response::model($iSurveyID)->findAll($criteria);
} elseif ($TableName == 'tokens'){
$results = Token::model(Yii::app()->session['LEMsid'])->findAll($criteria);
$results = Token::model($iSurveyID)->findAll($criteria);
}

foreach($results as $row){
Expand Down Expand Up @@ -1009,7 +1009,7 @@ function getXMLDataSingleTable($iSurveyID, $sTableName, $sDocType, $sXMLTableTag
$xml->endElement();
$aquery = "SELECT * FROM {{{$sTableName}}}";

buildXMLFromQuery($xml, $aquery, $sXMLTableTagName);
buildXMLFromQuery($xml, $aquery, $sXMLTableTagName, array(), $iSurveyID);
$xml->endElement(); // close columns
$xml->endDocument();
if ($sFileName = '') {
Expand Down

0 comments on commit 88a9a28

Please sign in to comment.