Skip to content

Commit

Permalink
Fixed issue: Cannot add survey menu when using PHP8 (#3115)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trischi80 committed May 8, 2023
1 parent 47db94f commit ca2209c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
22 changes: 15 additions & 7 deletions application/controllers/admin/SurveymenuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public function update($id = 0)
Yii::app()->user->setFlash('error', gT("Access denied"));
$this->getController()->redirect(Yii::app()->createUrl('/admin'));
}

$id = (int) $id;
if ($id != 0) {
$model = $this->loadModel($id);
$model = Surveymenu::model()->findByPk($id);
} else {
$model = new Surveymenu();
$model = new Surveymenu();
}
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
Expand Down Expand Up @@ -186,8 +186,12 @@ public function massDelete()
$aSurveyMenuIds = json_decode(Yii::app()->request->getPost('sItems', '')) ?? [];
$success = [];
foreach ($aSurveyMenuIds as $menuid) {
$model = $this->loadModel($menuid);
$success[$menuid] = $model->delete();
$model = Surveymenu::model()->findByPk((int)$menuid);
$success[$menuid] = false;
if ($model !== null) {
$model->delete();
$success[$menuid] = true;
}
}

$debug = $userConfig['config']['debug'] ?? 0;
Expand Down Expand Up @@ -229,9 +233,12 @@ public function delete()

if (Yii::app()->request->isPostRequest) {
$menuid = Yii::app()->request->getPost('menuid', 0);
$model = Surveymenu::model()->findByPk((int)$menuid);
$success = false;
$model = $this->loadModel($menuid);
$success = $model->delete();
if ($model !== null) {
$model->delete();
$success = true;
}
$debug = $userConfig['config']['debug'] ?? 0;
$returnData = array(
'data' => [
Expand Down Expand Up @@ -332,6 +339,7 @@ public function restore()
* @param integer $id the ID of the model to be loaded
* @return Surveymenu the loaded model
* @throws CHttpException
* @deprecated do not use this function anymore
*/
public function loadModel($id)
{
Expand Down
18 changes: 13 additions & 5 deletions application/controllers/admin/SurveymenuEntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ public function update($id)
$this->getController()->redirect(Yii::app()->createUrl('/admin'));
}
//Update or create
$id = (int) $id;
if ($id != 0) {
$model = $this->loadModel($id);
$model = SurveymenuEntries::model()->findByPk($id);
} else {
$model = new SurveymenuEntries();
}
Expand Down Expand Up @@ -280,8 +281,12 @@ public function massDelete()
$aSurveyMenuEntryIds = json_decode(Yii::app()->request->getPost('sItems', '')) ?? [];
$success = [];
foreach ($aSurveyMenuEntryIds as $menuEntryid) {
$model = $this->loadModel($menuEntryid);
$success[$menuEntryid] = $model->delete();
$model = SurveymenuEntries::model()->findByPk((int)$menuEntryid);
$success[$menuEntryid] = false;
if ($model !== null) {
$model->delete();
$success[$menuEntryid] = true;
}
}

$debug = $userConfig['config']['debug'] ?? 0;
Expand Down Expand Up @@ -323,13 +328,15 @@ public function delete()
if (Yii::app()->request->isPostRequest) {
$menuEntryid = Yii::app()->request->getPost('menuEntryid', 0);
$success = false;
$model = $this->loadModel($menuEntryid);
$model = SurveymenuEntries::model()->findByPk((int)$menuEntryid);
//Don't delete main menu entries when not superadmin
if (($model->menu_id == 1 || $model->menu_id == 2) && !Permission::model()->hasGlobalPermission('superadmin', 'read')) {
Yii::app()->user->setFlash('error', gT("Access denied"));
$this->getController()->redirect(Yii::app()->createUrl('/admin'));
}
$success = $model->delete();
if ($model !== null) {
$success = $model->delete();
}
$debug = $userConfig['config']['debug'] ?? 0;

$returnData = array(
Expand Down Expand Up @@ -404,6 +411,7 @@ public function reorder()
* @param integer $id the ID of the model to be loaded
* @return SurveymenuEntries the loaded model
* @throws CHttpException
* * @deprecated do not use this function in future
*/
public function loadModel($id)
{
Expand Down

0 comments on commit ca2209c

Please sign in to comment.