Skip to content

Commit

Permalink
Fixed issue: Survey archive format not properly importing
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed May 17, 2012
1 parent f43d536 commit 6ac8d0a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 62 deletions.
23 changes: 1 addition & 22 deletions application/controllers/admin/tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -2053,28 +2053,7 @@ function _newtokentable($iSurveyId)
$clang = $this->getController()->lang;
if (Yii::app()->request->getPost('createtable') == "Y" && hasSurveyPermission($iSurveyId, 'surveyactivation', 'update'))
{
$fields = array(
'tid' => 'int(11) not null auto_increment primary key',
'participant_id' => 'VARCHAR(50)',
'firstname' => 'VARCHAR(40)',
'lastname' => 'VARCHAR(40)',
'email' => 'text',
'emailstatus' => 'text',
'token' => 'VARCHAR(35)',
'language' => 'VARCHAR(25)',
'blacklisted' => 'CHAR(17)',
'sent' => 'VARCHAR(17) DEFAULT "N"',
'remindersent' => 'VARCHAR(17) DEFAULT "N"',
'remindercount' => 'INT(11) DEFAULT 0',
'completed' => 'VARCHAR(17) DEFAULT "N"',
'usesleft' => 'INT(11) DEFAULT 1',
'validfrom' => 'DATETIME',
'validuntil' => 'DATETIME',
'mpid' => 'INT(11)'
);
$comm = Yii::app()->db->createCommand();
$comm->createTable("{{tokens_".intval($iSurveyId)."}}", $fields);

createTokenTable($iSurveyId);
$this->_renderWrappedTemplate('token', array('message' =>array(
'title' => $clang->gT("Token control"),
'message' => $clang->gT("A token table has been created for this survey.") . " (\"" . Yii::app()->db->tablePrefix . "tokens_$iSurveyId\")<br /><br />\n"
Expand Down
5 changes: 3 additions & 2 deletions application/helpers/admin/import_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3973,7 +3973,8 @@ function XMLImportTokens($sFullFilepath,$iSurveyID,$sCreateMissingAttributeField
$aXLMFieldNames[]=(string)$sFieldName;
}
// Get a list of all fieldnames in the token table
$aTokenFieldNames=$CI->db->list_fields('tokens_'.$iSurveyID);
$aTokenFieldNames=Yii::app()->db->getSchema()->getTable("{{tokens_$iSurveyID}}",true);
$aTokenFieldNames=array_keys($aTokenFieldNames->columns);
$aFieldsToCreate=array_diff($aXLMFieldNames, $aTokenFieldNames);
foreach ($aFieldsToCreate as $sField)
{
Expand All @@ -3998,7 +3999,7 @@ function XMLImportTokens($sFullFilepath,$iSurveyID,$sCreateMissingAttributeField
$insertdata[(string)$key]=(string)$value;
}

$result = Tokens_dynamic::model($iSurveyID)->insertToken($insertdata) or safeDie($clang->gT("Error").": Failed to insert data<br />");
$result = Tokens_dynamic::model($iSurveyID)->insertToken($iSurveyID,$insertdata) or safeDie($clang->gT("Error").": Failed to insert data<br />");

$results['tokens']++;
}
Expand Down
78 changes: 40 additions & 38 deletions application/helpers/admin/token_helper.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php
/*
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id$
*/
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id$
*/


/**
Expand All @@ -23,32 +23,34 @@
*/
function createTokenTable($iSurveyID, $aAttributeFields=array())
{
$CI =& get_instance();
$CI->load->helper('database');
$clang=$CI->limesurvey_lang;
$CI->load->dbforge();
$CI->dbforge->add_field("tid int(11) NOT NULL AUTO_INCREMENT");
$aFields = array(
'participant_id' => array('type' => 'VARCHAR', 'constraint' => 50),
'firstname' => array('type' => 'VARCHAR', 'constraint' => 40),
'lastname' => array('type' => 'VARCHAR', 'constraint' => 40),
'email' => array('type' => 'TEXT'),
'emailstatus' => array('type' => 'TEXT'),
'token' => array('type' => 'VARCHAR', 'constraint' => 36),
'language' => array('type' => 'VARCHAR', 'constraint' => 25),
'blacklisted' => array('type' => 'CHAR', 'constraint' => 1),
'sent' => array('type' => 'VARCHAR', 'constraint' => 17, 'default' => 'N'),
'remindersent' => array('type' => 'VARCHAR', 'constraint' => 17, 'default' => 'N'),
'remindercount' => array('type' => 'INT', 'constraint' => 11, 'default' => 0),
'completed' => array('type' => 'VARCHAR', 'constraint' => 17, 'default' => 'N'),
'usesleft' => array('type' => 'INT', 'constraint' => 11, 'default' => 1),
'validfrom' => array('type' => 'DATETIME'),
'validuntil' => array('type' => 'DATETIME'),
'mpid' => array('type' => 'INT', 'constraint' => 11)
$fields = array(
'tid' => 'pk',
'participant_id' => 'VARCHAR(50)',
'firstname' => 'VARCHAR(40)',
'lastname' => 'VARCHAR(40)',
'email' => 'text',
'emailstatus' => 'text',
'token' => 'VARCHAR(35)',
'language' => 'VARCHAR(25)',
'blacklisted' => 'CHAR(17)',
'sent' => "VARCHAR(17) DEFAULT 'N'",
'remindersent' => "VARCHAR(17) DEFAULT 'N'",
'remindercount' => 'integer DEFAULT 0',
'completed' => "VARCHAR(17) DEFAULT 'N'",
'usesleft' => 'integer DEFAULT 1',
'validfrom' => 'datetime',
'validuntil' => 'datetime',
'mpid' => 'integer'
);
$CI->dbforge->add_field($aFields);
$CI->dbforge->add_key('tid', TRUE);
$CI->dbforge->add_key("token");
return $CI->dbforge->create_table("tokens_{$iSurveyID}");
foreach ($aAttributeFields as $sAttributeField)
{
$fields[$sAttributeField]='string';
}
try{
Yii::app()->db->createCommand()->createTable("{{tokens_".intval($iSurveyID)."}}", $fields);
return true;
} catch(Exception $e) {
return false;
}

}

0 comments on commit 6ac8d0a

Please sign in to comment.