Skip to content

Commit

Permalink
Fixed issue #16069: Deactivate survey using tokens in Postgres 12 sho…
Browse files Browse the repository at this point in the history
…ws error
  • Loading branch information
c-schmitz committed Apr 1, 2020
1 parent a63c6f5 commit d9a465c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion application/controllers/admin/surveyadmin.php
Expand Up @@ -786,7 +786,8 @@ public function deactivate($iSurveyID = null)
$toldtable = Yii::app()->db->tablePrefix."tokens_{$iSurveyID}";
$tnewtable = Yii::app()->db->tablePrefix."old_tokens_{$iSurveyID}_{$date}";
if (Yii::app()->db->getDriverName() == 'pgsql') {
$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();
// Find out the trigger name for tid column
$tidDefault = Yii::app()->db->createCommand("SELECT pg_get_expr(adbin, adrelid) as 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];
Yii::app()->db->createCommand()->renameTable($oldSeq, $tnewtable.'_tid_seq');
Expand Down

0 comments on commit d9a465c

Please sign in to comment.