View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
09282 | Bug reports | Other | public | 2014-10-07 15:00 | 2014-11-23 23:42 |
Reporter | sveinp | Assigned To | c_schmitz | ||
Priority | normal | Severity | minor | ||
Status | closed | Resolution | fixed | ||
Fixed in Version | 2.05+ | ||||
Summary | 09282: Deactivating survey with tokens fails with postgres | ||||
Description | Deactivating a survey with tokens fails with postgresql in Version 2.05+ Build 140915 (internal server error). The reasons are outlined in additional information. | ||||
Additional Information | Around line 330 in serveyadmin.php:
In an earlier version I have installed, this block did not execute (I think) due to a bug where the condition was the the driver name should be 'postgre'. Anyhow, the variables $toldtable and $tnewtable are defined below this block, so when it is executed - it fails. Further: $toldtable should be used, not $tnewtable, since the table hasn't been renamed yet. Also, at least for me, the $setidx statement will fail because there is no such index - the indexes present are:
| ||||
Tags | No tags attached. | ||||
Attached Files | surveyadmin.diff (3,616 bytes)
--- /var/www/limesurvey/application/controllers/admin/surveyadmin.php 2014-11-14 23:46:15.486568303 +0100 +++ /tmp/limesurvey/application/controllers/admin/surveyadmin.php 2014-11-14 15:53:05.000000000 +0100 @@ -326,17 +326,26 @@ //See if there is a tokens table for this survey if (tableExists("{{tokens_{$iSurveyID}}}")) { + + $toldtable = Yii::app()->db->tablePrefix."tokens_{$iSurveyID}"; + $tnewtable = Yii::app()->db->tablePrefix."old_tokens_{$iSurveyID}_{$date}"; + if (Yii::app()->db->getDriverName() == 'pgsql') { - $deactivateresult = Yii::app()->db->createCommand()->renameTable($toldtable . '_tid_seq', $tnewtable . '_tid_seq'); - $setsequence = "ALTER TABLE ".Yii::app()->db->quoteTableName($tnewtable)." ALTER COLUMN tid SET DEFAULT nextval('{{{$tnewtable}}}_tid_seq'::regclass);"; - $deactivateresult = Yii::app()->db->createCommand($setsequence)->query(); - $setidx = "ALTER INDEX {{{$toldtable}}}_idx RENAME TO {{{$tnewtable}}}_idx;"; - $deactivateresult = Yii::app()->db->createCommand($setidx)->query(); + + $tidDefault = Yii::app()->db->createCommand("SELECT pg_attrdef.adsrc FROM pg_attribute JOIN pg_class ON (pg_attribute.attrelid=pg_class.oid) JOIN pg_attrdef ON(pg_attribute.attrelid=pg_attrdef.adrelid AND pg_attribute.attnum=pg_attrdef.adnum) WHERE pg_class.relname='$toldtable' and pg_attribute.attname='tid'")->queryScalar(); + + if(preg_match("/nextval\('(tokens_\d+_tid_seq\d*)'::regclass\)/", $tidDefault, $matches)){ + + $oldSeq = $matches[1]; + + $deactivateresult = Yii::app()->db->createCommand()->renameTable($oldSeq, $tnewtable . '_tid_seq'); + $setsequence = "ALTER TABLE ".Yii::app()->db->quoteTableName($toldtable)." ALTER COLUMN tid SET DEFAULT nextval('{$tnewtable}_tid_seq'::regclass);"; + $deactivateresult = Yii::app()->db->createCommand($setsequence)->query(); + } + } - $toldtable = "{{tokens_{$iSurveyID}}}"; - $tnewtable = "{{old_tokens_{$iSurveyID}_{$date}}}"; $tdeactivateresult = Yii::app()->db->createCommand()->renameTable($toldtable, $tnewtable); @@ -363,6 +372,23 @@ $survey->autonumber_start = $new_autonumber_start; $survey->save(); + if (Yii::app()->db->getDriverName() == 'pgsql') + { + + $idDefault = Yii::app()->db->createCommand("SELECT pg_attrdef.adsrc FROM pg_attribute JOIN pg_class ON (pg_attribute.attrelid=pg_class.oid) JOIN pg_attrdef ON(pg_attribute.attrelid=pg_attrdef.adrelid AND pg_attribute.attnum=pg_attrdef.adnum) WHERE pg_class.relname='$sOldSurveyTableName' and pg_attribute.attname='id'")->queryScalar(); + + if(preg_match("/nextval\('(survey_\d+_id_seq\d*)'::regclass\)/", $idDefault, $matches)){ + + $oldSeq = $matches[1]; + + $deactivateresult = Yii::app()->db->createCommand()->renameTable($oldSeq, $sNewSurveyTableName . '_id_seq'); + $setsequence = "ALTER TABLE ".Yii::app()->db->quoteTableName($sOldSurveyTableName)." ALTER COLUMN id SET DEFAULT nextval('{{{$sNewSurveyTableName}}}_id_seq'::regclass);"; + $deactivateresult = Yii::app()->db->createCommand($setsequence)->query(); + } + + } + + $deactivateresult = Yii::app()->db->createCommand()->renameTable($sOldSurveyTableName, $sNewSurveyTableName); $insertdata = array('active' => 'N'); | ||||
Bug heat | 22 | ||||
Complete LimeSurvey version number (& build) | 140915 | ||||
I will donate to the project if issue is resolved | No | ||||
Browser | |||||
Database type & version | Postgres 9.3 | ||||
Server OS (if known) | Linux | ||||
Webserver software & version (if known) | Apache | ||||
PHP Version | 5.5.9 | ||||
Probably, the easiest solution is to simply remove the whole block |
|
I had the same problem and fixed it (see surveyadmin.diff) |
|
Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=14627 |
|
Great patch, random1, much appreciated. |
|
Version 2.05 Build 141123 released. |
|
Date Modified | Username | Field | Change |
---|---|---|---|
2014-10-07 15:00 | sveinp | New Issue | |
2014-10-07 17:12 | sveinp | Note Added: 30748 | |
2014-11-16 12:58 | random1 | File Added: surveyadmin.diff | |
2014-11-16 12:59 | random1 | Note Added: 30991 | |
2014-11-16 13:19 | DenisChenu | Relationship added | has duplicate 09360 |
2014-11-16 18:30 | c_schmitz | Relationship added | has duplicate 09306 |
2014-11-16 18:36 | c_schmitz | Assigned To | => c_schmitz |
2014-11-16 18:36 | c_schmitz | Status | new => assigned |
2014-11-16 18:37 | c_schmitz | Changeset attached | => LimeSurvey master 8d481e84 |
2014-11-16 18:37 | c_schmitz | Note Added: 30996 | |
2014-11-16 18:37 | c_schmitz | Resolution | open => fixed |
2014-11-16 18:37 | c_schmitz | Note Added: 30997 | |
2014-11-16 18:37 | c_schmitz | Status | assigned => resolved |
2014-11-16 18:37 | c_schmitz | Fixed in Version | => 2.05+ |
2014-11-23 23:42 | c_schmitz | Note Added: 31072 | |
2014-11-23 23:42 | c_schmitz | Status | resolved => closed |
2021-08-02 22:25 | guest | Bug heat | 20 => 22 |