作者:林世光_519 | 来源:互联网 | 2023-08-22 17:27
What steps will reproduce the problem?
Without typing anything in comment, upload a picture and hit send. Put anything in comment with picture, operates normal. I believe this uses the same validation as normal posting where the main message can't be left blank (which should probably also change when someone only wants to post a picture with no text).
What is the expected result?
Picture posted in comment with no text needed.
What do you get instead?
Debug Error popup on debug instance.
Additional info
1
| PHP Notice 'yii\\base\\ErrorException' with message 'Trying to get property of non-object' \n\nin /var/www/socialrealms/html/protected/humhub/modules/comment/widgets/views/comment.php:68\n\nStack trace:\n#0 /var/www/socialrealms/html/protected/humhub/modules/comment/widgets/views/comment.php(68): yii\\base\\ErrorHandler->handleError(8, 'Trying to get p...', '/var/www/social...', 68, Array)\n#1 /var/www/socialrealms/html/protected/vendor/yiisoft/yii2/base/Vie...", |
| Q | A
| ---------------- | ---
| HumHub version | 1.6.5 AND current dev branch.
| PHP version | 7.4
| Operating system | Ubuntu 16 server
该提问来源于开源项目:humhub/humhub
Hi guys,
Thank you for your replay
Seems we're still seeing the original error above, with the current code patched we still receive:
How did you patch this correction code? Did you manually put it inside /humhub/protected/humhub/modules/comment/models/Comment.php
or maybe you simply took code from the "master" branch of humhub repository?
I am sorry, but at the moment this correction did not deliver to the master branch and to the production Humhub.com as well. Please wait for us put it there. It will not take long.
Could
1
| $user->contentcontainer_id |
be replaced with
1
| $user->contentContainer->id |
in this case or does this go against the container id rules ?
PHP language is strict to a using case of variables, properties, and methods. Expression $user->contentcontainer_id - is correct.
Why this issue appeared in the view /var/www/socialrealms/html/protected/humhub/modules/comment/widgets/views/comment.php at 68 string.
Please look into this code:
1 2
| UserImage::widget(['user' => $user, 'width' => 40, 'htmlOptions' => ['class' => 'pull-left', 'data-contentcontainer-id' =>
$user->contentcontainer_id]]); |
We are extracting the property from the User model $user->contentcontainer_id. But $user (the User model object instance) is empty. You can't take property from the void (from an empty object).
Why $user empty? That's happened because the system did not create an instance of Comment model in the CommentController actionPost method string 140:
1 2 3 4
| $comment = new Comment(['message' => $message]);
$comment->setPolyMorphicRelation($this->target);
$comment->save();
$comment->fileManager->attach($files); |
And setPolyMorphicRelation did not work and the related model User did not fill up. It is empty.
And when the system processed the widget Comment in this code:
1
| return $this->renderAjaxContent(CommentWidget::widget(['comment' => $comment])); |
It passed the Comment model to a widget controller.
in widgets/comment.php in 48 string
1 2 3 4 5 6 7 8 9 10 11 12
| return $this->render('comment', [
'comment' => $this->comment,
** 'user' => $this->comment->user,** -- _here system have passed_ **empty object**
'justEdited' => $this->justEdited,
'deleteUrl' => $deleteUrl,
'editUrl' => $editUrl,
'loadUrl' => $loadUrl,
'createdAt' => $this->comment->created_at,
'updatedAt' => $updatedAt,
'canEdit' => $this->comment->canEdit(),
'canDelete' => $this->comment->canDelete(),
]); |
Why Comment model instance did not create? Because of the rule of validation on the "message" column.
See you
Alex