Skip to content

Commit 238c3ca

Browse files
committed
skip the validation of parentId on deletion
1 parent 2083417 commit 238c3ca

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

controllers/DefaultController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public function actionCreate($entity)
131131
public function actionDelete($id)
132132
{
133133
$commentModel = $this->findModel($id);
134+
$commentModel->setScenario(CommentModel::SCENARIO_MODERATION);
134135
$event = Yii::createObject(['class' => CommentEvent::class, 'commentModel' => $commentModel]);
135136
$this->trigger(self::EVENT_BEFORE_DELETE, $event);
136137

@@ -157,7 +158,7 @@ public function actionDelete($id)
157158
protected function findModel($id)
158159
{
159160
$commentModel = $this->getModule()->commentModelClass;
160-
if (($model = $commentModel::findOne($id)) !== null) {
161+
if (null !== ($model = $commentModel::findOne($id))) {
161162
return $model;
162163
} else {
163164
throw new NotFoundHttpException(Yii::t('yii2mod.comments', 'The requested page does not exist.'));
@@ -176,7 +177,7 @@ protected function findModel($id)
176177
protected function getCommentAttributesFromEntity($entity)
177178
{
178179
$decryptEntity = Yii::$app->getSecurity()->decryptByKey(utf8_decode($entity), $this->getModule()->id);
179-
if ($decryptEntity !== false) {
180+
if (false !== $decryptEntity) {
180181
return Json::decode($decryptEntity);
181182
}
182183

controllers/ManageController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected function findModel($id)
142142
{
143143
$commentModel = $this->getModule()->commentModelClass;
144144

145-
if (($model = $commentModel::findOne($id)) !== null) {
145+
if (null !== ($model = $commentModel::findOne($id))) {
146146
return $model;
147147
} else {
148148
throw new NotFoundHttpException(Yii::t('yii2mod.comments', 'The requested page does not exist.'));

models/CommentModel.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class CommentModel extends ActiveRecord
4242
{
4343
use ModuleTrait;
4444

45+
const SCENARIO_MODERATION = 'moderation';
46+
4547
/**
4648
* @var null|array|ActiveRecord[] comment children
4749
*/
@@ -67,7 +69,7 @@ public function rules()
6769
['status', 'default', 'value' => Status::APPROVED],
6870
['status', 'in', 'range' => Status::getConstantsByName()],
6971
['level', 'default', 'value' => 1],
70-
['parentId', 'validateParentID'],
72+
['parentId', 'validateParentID', 'except' => static::SCENARIO_MODERATION],
7173
[['entityId', 'parentId', 'status', 'level'], 'integer'],
7274
];
7375
}
@@ -77,7 +79,7 @@ public function rules()
7779
*/
7880
public function validateParentID($attribute)
7981
{
80-
if ($this->{$attribute} !== null) {
82+
if (null !== $this->{$attribute}) {
8183
$parentCommentExist = static::find()
8284
->approved()
8385
->andWhere([

0 commit comments

Comments
 (0)