Skip to content

Commit

Permalink
QE-903: Fixed a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Lajos Arpad committed May 15, 2024
1 parent e11d3cc commit 4d913ec
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
60 changes: 42 additions & 18 deletions application/controllers/SurveyAdministrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1592,29 +1592,53 @@ public function actionDeactivate()
LimeSurvey\Models\Services\SurveyDeactivate::class
);

try {
$result = $surveyDeactivate->deactivate($iSurveyID, Yii::app()->request->getPost('ok'));
} catch (Exception $e) {
App()->user->setFlash('error', $e->getMessage());
}
$aData = array();

if (!empty($result["beforeDeactivate"]["message"])) {
Yii::app()->user->setFlash('error', $result["beforeDeactivate"]["message"]);
}
if ($result["beforeDeactivate"]["message"] === false) {
// @todo: What if two plugins change this?
$aData = [];
$aData['nostep'] = true;
$this->aData = $aData;
$datestamp = time();
$date = date('YmdHis', $datestamp); //'His' adds 24hours+minutes to name to allow multiple deactiviations in a day
$survey = Survey::model()->findByPk($iSurveyID);
$aData['aSurveysettings'] = getSurveyInfo($iSurveyID);
$aData['surveyid'] = $iSurveyID;
$aData['sid'] = $iSurveyID;
$aData['title_bar']['title'] = $survey->currentLanguageSettings->surveyls_title . " (" . gT("ID") . ":" . $iSurveyID . ")";
$aData['topBar']['hide'] = true;
$ok = Yii::app()->request->getPost('ok');

if ($ok == '') {
if (!empty(Yii::app()->session->get('sNewSurveyTableName'))) {
Yii::app()->session->remove('sNewSurveyTableName');
}

Yii::app()->session->add('sNewSurveyTableName', Yii::app()->db->tablePrefix . "old_survey_{$iSurveyID}_{$date}");
$aData['date'] = $date;
$aData['dbprefix'] = Yii::app()->db->tablePrefix;
$aData['sNewSurveyTableName'] = Yii::app()->session->get('sNewSurveyTableName');
$aData['step1'] = true;
} else {
if (!$result["surveyTableExists"]) {
$_SESSION['flashmessage'] = gT("Error: Response table does not exist. Survey cannot be deactivated.");
$this->redirect($this->createUrl("surveyAdministration/view/surveyid/{$iSurveyID}"));
try {
$result = $surveyDeactivate->deactivate($iSurveyID, ['ok' => $ok]);
} catch (Exception $e) {
App()->user->setFlash('error', $e->getMessage());
}

$aData = $result['aData'];
if (!empty($result["beforeDeactivate"]["message"])) {
Yii::app()->user->setFlash('error', $result["beforeDeactivate"]["message"]);
}
if ($result["beforeDeactivate"]["message"] === false) {
// @todo: What if two plugins change this?
$aData = [];
$aData['nostep'] = true;
$this->aData = $aData;
} else {
if (!$result["surveyTableExists"]) {
$_SESSION['flashmessage'] = gT("Error: Response table does not exist. Survey cannot be deactivated.");
$this->redirect($this->createUrl("surveyAdministration/view/surveyid/{$iSurveyID}"));
}

$aData['sidemenu']['state'] = false;
$aData = $result['aData'];

$aData['sidemenu']['state'] = false;
}
}

$this->aData = $aData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function handle(OpInterface $op)
$surveyDeactivateService = $diContainer->get(
SurveyAggregateService::class
);
$surveyDeactivateService->deactivate($op->getEntityId());
$surveyDeactivateService->deactivate($op->getEntityId(), $op->getProps());
}

/**
Expand Down
5 changes: 3 additions & 2 deletions application/models/services/SurveyAggregateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ public function activate($surveyId, $input)
* Deactivate
*
* @param int $surveyId
* @param array $input
* @return array
*/
public function deactivate($surveyId)
public function deactivate($surveyId, $input)
{
return $this->surveyDeactivate->deactivate($surveyId);
return $this->surveyDeactivate->deactivate($surveyId, $input);
}
}
4 changes: 2 additions & 2 deletions application/models/services/SurveyDeactivate.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(
* @return array
* @throws PermissionDeniedException
*/
public function deactivate(int $iSurveyID, $isOk = [])
public function deactivate(int $iSurveyID, $params = [])
{
if (!$this->permission->hasSurveyPermission($iSurveyID, 'surveyactivation', 'update')) {
throw new PermissionDeniedException(
Expand Down Expand Up @@ -78,7 +78,7 @@ public function deactivate(int $iSurveyID, $isOk = [])
if (!$result["surveyTableExists"]) {
return $result;
}
if ($isOk) {
if (!is_array($params) || (($params['ok'] ?? '') == '')) {
if (!empty($this->app->session->get('sNewSurveyTableName'))) {
$this->app->session->remove('sNewSurveyTableName');
}
Expand Down

0 comments on commit 4d913ec

Please sign in to comment.