From fc96cb859cc15dd7e1dea5a60a8f85296d81736b Mon Sep 17 00:00:00 2001 From: Master_Hans Date: Tue, 13 Oct 2020 12:43:57 +0300 Subject: [PATCH] #4396 Change validation block. First check for empty message before checking the file existence. --- .../modules/comment/models/forms/CommentForm.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/protected/humhub/modules/comment/models/forms/CommentForm.php b/protected/humhub/modules/comment/models/forms/CommentForm.php index 66129c9ba8..81f4a272d8 100644 --- a/protected/humhub/modules/comment/models/forms/CommentForm.php +++ b/protected/humhub/modules/comment/models/forms/CommentForm.php @@ -51,12 +51,16 @@ class CommentForm extends yii\base\Model { return [ [['message'], 'required', 'isEmpty' => function ($message) { - $hasFile = !empty($this->fileList) || (!$this->comment->isNewRecord && $this->comment->fileManager->find()->count()); - - //check if message empty and attached file exists - if (empty($message) && !$hasFile) { - throw new ServerErrorHttpException(Yii::t('CommentModule.base', 'The comment must not be empty!')); + if (!empty($message)) { + return false; } + + // Allow empty message only with file attachments + if (!empty($this->fileList) || (!$this->comment->isNewRecord && $this->comment->fileManager->find()->count())) { + return false; + } + + throw new ServerErrorHttpException(Yii::t('CommentModule.base', 'The comment must not be empty!')); }], [['fileList'], 'safe'], ]; @@ -112,7 +116,7 @@ class CommentForm extends yii\base\Model */ public function save() { - /**@var Comment $this->comment*/ + /**@var Comment $this ->comment */ $this->comment->setPolyMorphicRelation($this->target); //check if model saved