Skip to content

Commit

Permalink
Fixed issue #4036: exclude_all_others question attribute design changed
Browse files Browse the repository at this point in the history
Dev Added proper conversion of the attribute on upgrade

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey@8246 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Jan 13, 2010
1 parent e38d2c2 commit de97593
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 12 deletions.
19 changes: 17 additions & 2 deletions admin/update/upgrade-mssql.php
Expand Up @@ -351,6 +351,7 @@ function db_upgrade($oldversion) {

if ($oldversion < 142) //Modify surveys table
{
upgrade_question_attributes142();
modify_database("", "ALTER TABLE [prefix_surveys] ALTER COLUMN [startdate] datetime NULL"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE [prefix_surveys] ALTER COLUMN [expires] datetime NULL"); echo $modifyoutput; flush();
modify_database("", "UPDATE [prefix_question_attributes] SET [value]='0' WHERE [value]='false'"); echo $modifyoutput; flush();
Expand Down Expand Up @@ -483,5 +484,19 @@ function upgrade_survey_tables139()
}
}


?>
function upgrade_question_attributes142()
{
global $modifyoutput,$dbprefix, $connect;
$attributequery="Select qid from {$dbprefix}question_attributes where attribute='exclude_all_other' group by qid having count(qid)>1 ";
$questionids = db_select_column($attributequery);
foreach ($questionids as $questionid)
{
//Select all affected question attributes
$attributevalues=db_select_column("SELECT value from {$dbprefix}question_attributes where attribute='exclude_all_other' and qid=".$questionid);
modify_database("","delete from {$dbprefix}question_attributes where attribute='exclude_all_other' and qid=".$questionid); echo $modifyoutput; flush();
$record['value']=implode(';',$attributevalues);
$record['attribute']='exclude_all_other';
$record['qid']=$questionid;
$connect->AutoExecute("{$dbprefix}question_attributes", $record, 'INSERT');
}
}
18 changes: 18 additions & 0 deletions admin/update/upgrade-mysql.php
Expand Up @@ -338,6 +338,7 @@ function db_upgrade($oldversion) {

if ($oldversion < 142) //Modify surveys table
{
upgrade_question_attributes142();
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `expires` `expires` datetime"); echo $modifyoutput; flush();
modify_database("","ALTER TABLE `prefix_surveys` CHANGE `startdate` `startdate` datetime"); echo $modifyoutput; flush();
modify_database("", "UPDATE `prefix_question_attributes` SET `value`='0' WHERE `value`='false'"); echo $modifyoutput; flush();
Expand Down Expand Up @@ -510,4 +511,21 @@ function upgrade_survey_tables139()
}
}
}
}

function upgrade_question_attributes142()
{
global $modifyoutput,$dbprefix, $connect;
$attributequery="Select qid from {$dbprefix}question_attributes where attribute='exclude_all_other' group by qid having count(qid)>1 ";
$questionids = db_select_column($attributequery);
foreach ($questionids as $questionid)
{
//Select all affected question attributes
$attributevalues=db_select_column("SELECT value from {$dbprefix}question_attributes where attribute='exclude_all_other' and qid=".$questionid);
modify_database("","delete from {$dbprefix}question_attributes where attribute='exclude_all_other' and qid=".$questionid); echo $modifyoutput; flush();
$record['value']=implode(';',$attributevalues);
$record['attribute']='exclude_all_other';
$record['qid']=$questionid;
$connect->AutoExecute("{$dbprefix}question_attributes", $record, 'INSERT');
}
}
18 changes: 17 additions & 1 deletion admin/update/upgrade-postgres.php
Expand Up @@ -179,6 +179,7 @@ function db_upgrade($oldversion) {

if ($oldversion < 142) //Modify surveys table
{
upgrade_question_attributes142();
modify_database("", "ALTER TABLE prefix_surveys ALTER COLUMN \"startdate\" timestamp"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE prefix_surveys ALTER COLUMN \"expires\" timestamp"); echo $modifyoutput; flush();
modify_database("", "UPDATE prefix_question_attributes SET value='0' WHERE value='false'"); echo $modifyoutput; flush();
Expand Down Expand Up @@ -249,4 +250,19 @@ function upgrade_survey_tables139()
}
}

?>
function upgrade_question_attributes142()
{
global $modifyoutput,$dbprefix, $connect;
$attributequery="Select qid from {$dbprefix}question_attributes where attribute='exclude_all_other' group by qid having count(qid)>1 ";
$questionids = db_select_column($attributequery);
foreach ($questionids as $questionid)
{
//Select all affected question attributes
$attributevalues=db_select_column("SELECT value from {$dbprefix}question_attributes where attribute='exclude_all_other' and qid=".$questionid);
modify_database("","delete from {$dbprefix}question_attributes where attribute='exclude_all_other' and qid=".$questionid); echo $modifyoutput; flush();
$record['value']=implode(';',$attributevalues);
$record['attribute']='exclude_all_other';
$record['qid']=$questionid;
$connect->AutoExecute("{$dbprefix}question_attributes", $record, 'INSERT');
}
}
34 changes: 25 additions & 9 deletions common.php
Expand Up @@ -453,19 +453,16 @@ function showadminmenu()
function &db_execute_num($sql,$inputarr=false)
{
global $connect;

// Todo: Set fetchmode to previous state after changing
//$oldfetchmode=

$connect->SetFetchMode(ADODB_FETCH_NUM);
$dataset=$connect->Execute($sql,$inputarr); //Checked
//$connect->SetFetchMode($oldfetchmode);
return $dataset;
}

function &db_select_limit_num($sql,$numrows=-1,$offset=-1,$inputarr=false)
{
global $connect;

$connect->SetFetchMode(ADODB_FETCH_NUM);
$dataset=$connect->SelectLimit($sql,$numrows,$offset,$inputarr=false) or safe_die($sql);
return $dataset;
Expand All @@ -474,25 +471,44 @@ function &db_select_limit_num($sql,$numrows=-1,$offset=-1,$inputarr=false)
function &db_execute_assoc($sql,$inputarr=false,$silent=false)
{
global $connect;
// Todo: Set fetchmode to previous state after changing
// $oldfetchmode=

$connect->SetFetchMode(ADODB_FETCH_ASSOC);
$dataset=$connect->Execute($sql,$inputarr); //Checked
if (!$silent && !$dataset) {safe_die($connect->ErrorMsg().':'.$sql);}
// $connect->SetFetchMode($oldfetchmode);
return $dataset;
}

function &db_select_limit_assoc($sql,$numrows=-1,$offset=-1,$inputarr=false,$dieonerror=true)
{
global $connect;

$connect->SetFetchMode(ADODB_FETCH_ASSOC);
$dataset=$connect->SelectLimit($sql,$numrows,$offset,$inputarr=false);
if (!$dataset && $dieonerror) {safe_die($connect->ErrorMsg().':'.$sql);}
return $dataset;
}


/**
* Returns the first row of values of the $sql query result
* as a 1-dimensional array
*
* @param mixed $sql
*/
function &db_select_column($sql)
{
global $connect;

$connect->SetFetchMode(ADODB_FETCH_NUM);
$dataset=$connect->Execute($sql);
$resultarray=array();
while ($row = $dataset->fetchRow()) {
$resultarray[]=$row[0];
}
return $resultarray;
}


/**
* This functions quotes fieldnames accordingly
*
Expand Down

0 comments on commit de97593

Please sign in to comment.