Skip to content

Commit

Permalink
Fixed issue #6466: Wrong table name is displayed on deactivation
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Aug 12, 2012
1 parent 6f789e6 commit ff64aa0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
23 changes: 12 additions & 11 deletions application/controllers/admin/surveyadmin.php
Expand Up @@ -292,6 +292,7 @@ public function deactivate($iSurveyID = null)
$iSurveyID = sanitize_int($iSurveyID);

$postsid = Yii::app()->request->getPost('sid', $iSurveyID);
$postsid = sanitize_int($postsid);
$clang = $this->getController()->lang;
$date = date('YmdHis'); //'Hi' adds 24hours+minutes to name to allow multiple deactiviations in a day

Expand Down Expand Up @@ -327,12 +328,12 @@ public function deactivate($iSurveyID = null)

// IF there are any records in the saved_control table related to this survey, they have to be deleted
$result = Saved_control::model()->deleteSomeRecords(array('sid' => $postsid)); //Yii::app()->db->createCommand($query)->query();
$oldtable = "{{survey_{$postsid}}}";
$newtable = "{{old_survey_{$postsid}_{$date}}}";

$sOldSurveyTableName = Yii::app()->db->tablePrefix."survey_{$postsid}";
$sNewSurveyTableName = Yii::app()->db->tablePrefix."old_survey_{$postsid}_{$date}";
$aData['sNewSurveyTableName']=$sNewSurveyTableName;
//Update the auto_increment value from the table before renaming
$new_autonumber_start = 0;
$query = "SELECT id FROM ".Yii::app()->db->quoteTableName($oldtable)." ORDER BY id desc";
$query = "SELECT id FROM ".Yii::app()->db->quoteTableName($sOldSurveyTableName)." ORDER BY id desc";
$result = Yii::app()->db->createCommand($query)->limit(1)->query();
if ($result->getRowCount() > 0)
{
Expand Down Expand Up @@ -360,12 +361,12 @@ public function deactivate($iSurveyID = null)
$survey->save();
if (Yii::app()->db->getDrivername() == 'postgre')
{
$deactivateresult = Yii::app()->db->createCommand()->renameTable($oldtable . '_id_seq', $newtable . '_id_seq');
$setsequence = "ALTER TABLE $newtable ALTER COLUMN id SET DEFAULT nextval('{$newtable}_id_seq'::regclass);";
$deactivateresult = Yii::app()->db->createCommand()->renameTable($sOldSurveyTableName . '_id_seq', $sNewSurveyTableName . '_id_seq');
$setsequence = "ALTER TABLE $newtable ALTER COLUMN id SET DEFAULT nextval('{$sNewSurveyTableName}_id_seq'::regclass);";
$deactivateresult = Yii::app()->db->createCommand($setsequence)->execute();
}

$deactivateresult = Yii::app()->db->createCommand()->renameTable($oldtable, $newtable);
$deactivateresult = Yii::app()->db->createCommand()->renameTable($sOldSurveyTableName, $sNewSurveyTableName);

$insertdata = array('active' => 'N');
$survey->active = 'N';
Expand All @@ -374,15 +375,15 @@ public function deactivate($iSurveyID = null)
$prow = Survey::model()->find('sid = :sid', array(':sid' => $postsid));
if ($prow->savetimings == "Y")
{
$oldtable = "{{survey_{$postsid}_timings}}";
$newtable = "{{old_survey_{$postsid}_timings_{$date}}}";
$sOldTimingsTableName = Yii::app()->db->tablePrefix."survey_{$postsid}_timings";
$sNewTimingsTableName = Yii::app()->db->tablePrefix."old_survey_{$postsid}_timings_{$date}";

$deactivateresult2 = Yii::app()->db->createCommand()->renameTable($oldtable, $newtable);
$deactivateresult2 = Yii::app()->db->createCommand()->renameTable($sOldTimingsTableName, $sNewTimingsTableName);
$deactivateresult = ($deactivateresult && $deactivateresult2);
$aData['sNewTimingsTableName'] = $sNewTimingsTableName;
}

$aData['surveyid'] = $iSurveyID;
$aData['newtable'] = $newtable;
}

$this->_renderWrappedTemplate('survey', 'deactivateSurvey_view', $aData);
Expand Down
12 changes: 8 additions & 4 deletions application/views/admin/survey/deactivateSurvey_view.php
Expand Up @@ -49,13 +49,17 @@
<div class='successheader'><?php $clang->eT("Survey Has Been Deactivated"); ?>
</div>
<p>
<?php echo $clang->gT("The responses table has been renamed to: ")." ".$newtable; ?>
<?php $clang->eT("The responses to this survey are no longer available using LimeSurvey."); ?>
<p><?php $clang->eT("You should note the name of this table in case you need to access this information later."); ?></p>
<?php $clang->eT("The responses to this survey are no longer available using LimeSurvey."); ?></p>
<p>
<?php echo $clang->gT("The responses table has been renamed to: ")." ".$sNewSurveyTableName; ?><br>
<?php if (isset($toldtable) && $toldtable)
{
echo $clang->gT("The tokens table associated with this survey has been renamed to: ")." $tnewtable";
echo $clang->gT("The tokens table associated with this survey has been renamed to: ")." $tnewtable<br>";
} ?>

<?php if (isset($sNewTimingsTableName)) echo $clang->gT("The response timings table has been renamed to: ")." ".$sNewTimingsTableName; ?><br>
</p>
<?php $clang->eT("You should note the name(s) of the table(s) in case you need to access this information later."); ?><br>
<p><?php $clang->eT("Note: If you deactivated this survey in error, it is possible to restore this data easily if you do not make any changes to the survey structure. See the LimeSurvey documentation for further details"); ?></p>
</div><br/>&nbsp;
<?php } ?>

0 comments on commit ff64aa0

Please sign in to comment.