Skip to content

Commit

Permalink
Fixed issue #10337 : Delete survey don't delete all user's settings
Browse files Browse the repository at this point in the history
Dev: Delete in model : deleted for RC and plugin (if using model)
Dev: Delete other user settings if linked with survey
Dev: use compare and addInCondition : better quote value for PG and ms
  • Loading branch information
Shnoulle committed Feb 10, 2016
1 parent 0eb8b5b commit f2acf6a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
10 changes: 0 additions & 10 deletions application/controllers/admin/surveyadmin.php
Expand Up @@ -918,16 +918,6 @@ public function delete($iSurveyID)
$aData['issuperadmin'] = Permission::model()->hasGlobalPermission('superadmin','read');
$this->_deleteSurvey($iSurveyID);
Yii::app()->session['flashmessage'] = gT("Survey deleted.");

// We clean all the last visited
$lastLikeSurvey = 'last%'.$iSurveyID.'%';
$lastQuestionGidUser = 'last_question_gid_'.Yii::app()->user->getId();
$lastQuestionUser = 'last_question_'.Yii::app()->user->getId();
SettingGlobal::model()->deleteAll(
"stg_name LIKE ':stg_name' OR stg_name = ':last_question_gid_user' OR stg_name = ':last_question_user' OR stg_value = ':stg_value'",
array(':stg_name' => $lastLikeSurvey, ':last_question_gid_user' => $lastQuestionGidUser, ':last_question_user' => $lastQuestionUser , ':stg_value' => $iSurveyID )
);

$this->getController()->redirect(array("admin/index"));
}
else
Expand Down
23 changes: 23 additions & 0 deletions application/models/Survey.php
Expand Up @@ -481,6 +481,29 @@ public function deleteSurvey($iSurveyID, $recursive=true)
Yii::app()->db->createCommand()->dropTable("{{tokens_".intval($iSurveyID)."}}");
}

/* Remove User/global settings part : need Question and QuestionGroup*/
// Settings specific for this survey
$oCriteria = new CDbCriteria();
$oCriteria->compare('stg_name','last_%',true,'AND',false);
$oCriteria->compare('stg_value',$iSurveyID,false,'AND');
SettingGlobal::model()->deleteAll($oCriteria);
// Settings specific for this survey, 2nd part
$oCriteria = new CDbCriteria();
$oCriteria->compare('stg_name','last_%'.$iSurveyID.'%',true,'AND',false);
SettingGlobal::model()->deleteAll($oCriteria);
// All Group id from this survey for ALL users
$aGroupId=CHtml::listData(QuestionGroup::model()->findAll(array('select'=>'gid','condition'=>'sid=:sid','params'=>array(':sid'=>$iSurveyID))),'gid','gid');
$oCriteria = new CDbCriteria();
$oCriteria->compare('stg_name','last_question_gid_%',true,'AND',false);
$oCriteria->addInCondition('stg_value',$aGroupId);
SettingGlobal::model()->deleteAll($oCriteria);
// All Question id from this survey for ALL users
$aQuestionId=CHtml::listData(Question::model()->findAll(array('select'=>'qid','condition'=>'sid=:sid','params'=>array(':sid'=>$iSurveyID))),'qid','qid');
$oCriteria = new CDbCriteria();
$oCriteria->compare('stg_name','last_question_%',true,'OR',false);
$oCriteria->addInCondition('stg_value',$aQuestionId);
SettingGlobal::model()->deleteAll($oCriteria);

$oResult = Question::model()->findAllByAttributes(array('sid' => $iSurveyID));
foreach ($oResult as $aRow)
{
Expand Down

1 comment on commit f2acf6a

@Shnoulle
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are an issue : need to CAST value, i do it in some minutes

Please sign in to comment.