Skip to content

Commit

Permalink
Fixed issue #7191: Survey links not deleted when deactivating a survey
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Mar 2, 2013
1 parent 7eeb442 commit 4db3f66
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
28 changes: 15 additions & 13 deletions application/controllers/admin/surveyadmin.php
Expand Up @@ -335,10 +335,8 @@ public function view($iSurveyID, $gid = null, $qid = null)
*/
public function deactivate($iSurveyID = null)
{
$iSurveyID = Yii::app()->request->getPost('sid', $iSurveyID);
$iSurveyID = sanitize_int($iSurveyID);

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

Expand All @@ -352,7 +350,7 @@ public function deactivate($iSurveyID = null)
else
{
//See if there is a tokens table for this survey
if (tableExists("{{tokens_{$postsid}}}"))
if (tableExists("{{tokens_{$iSurveyID}}}"))
{
if (Yii::app()->db->getDriverName() == 'postgre')
{
Expand All @@ -363,19 +361,23 @@ public function deactivate($iSurveyID = null)
$deactivateresult = Yii::app()->db->createCommand($setidx)->query();
}

$toldtable = "{{tokens_{$postsid}}}";
$tnewtable = "{{old_tokens_{$postsid}_{$date}}}";
$toldtable = "{{tokens_{$iSurveyID}}}";
$tnewtable = "{{old_tokens_{$iSurveyID}_{$date}}}";

$tdeactivateresult = Yii::app()->db->createCommand()->renameTable($toldtable, $tnewtable);

$aData['tnewtable'] = $tnewtable;
$aData['toldtable'] = $toldtable;
}

//Remove any survey_links to the CPDB
Survey_links::model()->deleteLinksBySurvey($iSurveyID);


// 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();
$sOldSurveyTableName = Yii::app()->db->tablePrefix."survey_{$postsid}";
$sNewSurveyTableName = Yii::app()->db->tablePrefix."old_survey_{$postsid}_{$date}";
$result = Saved_control::model()->deleteSomeRecords(array('sid' => $iSurveyID)); //Yii::app()->db->createCommand($query)->query();
$sOldSurveyTableName = Yii::app()->db->tablePrefix."survey_{$iSurveyID}";
$sNewSurveyTableName = Yii::app()->db->tablePrefix."old_survey_{$iSurveyID}_{$date}";
$aData['sNewSurveyTableName']=$sNewSurveyTableName;
//Update the auto_increment value from the table before renaming
$new_autonumber_start = 0;
Expand Down Expand Up @@ -415,11 +417,11 @@ public function deactivate($iSurveyID = null)
$survey->active = 'N';
$survey->save();

$prow = Survey::model()->find('sid = :sid', array(':sid' => $postsid));
$prow = Survey::model()->find('sid = :sid', array(':sid' => $iSurveyID));
if ($prow->savetimings == "Y")
{
$sOldTimingsTableName = Yii::app()->db->tablePrefix."survey_{$postsid}_timings";
$sNewTimingsTableName = Yii::app()->db->tablePrefix."old_survey_{$postsid}_timings_{$date}";
$sOldTimingsTableName = Yii::app()->db->tablePrefix."survey_{$iSurveyID}_timings";
$sNewTimingsTableName = Yii::app()->db->tablePrefix."old_survey_{$iSurveyID}_timings_{$date}";

$deactivateresult2 = Yii::app()->db->createCommand()->renameTable($sOldTimingsTableName, $sNewTimingsTableName);
$deactivateresult = ($deactivateresult && $deactivateresult2);
Expand Down Expand Up @@ -1515,7 +1517,7 @@ private function _registerScriptFiles($files = array())
if (empty($files))
{
$generalscripts_path = Yii::app()->getConfig('generalscripts');
$adminscripts_path = Yii::app()->getConfig('adminscripts');
$adminscripts_path = Yii::app()->getConfig('adminscripts');
$styleurl = Yii::app()->getConfig('styleurl');

$js_files = array(
Expand Down
2 changes: 2 additions & 0 deletions application/models/Survey.php
Expand Up @@ -339,6 +339,8 @@ public function deleteSurvey($iSurveyID, $recursive=true)
Survey_permissions::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
Saved_control::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
Survey_url_parameters::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
//Remove any survey_links to the CPDB
Survey_links::model()->deleteLinksBySurvey($iSurveyID);
Quota::model()->deleteQuota(array('sid' => $iSurveyID), true);
}
}
Expand Down

0 comments on commit 4db3f66

Please sign in to comment.