Fix comment highlighting on permalink (#5474)

This commit is contained in:
Yuriy Bakhtin 2021-12-16 13:58:17 +03:00 committed by GitHub
parent 46004a8670
commit 073af01acc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 11 deletions

View File

@ -6,7 +6,7 @@ HumHub Changelog
- Fix #5465: Fix empty RichText
- Fix #5466: Default `.htaccess.dist` broken
- Fix #5469: Mixed up title for Space membership button
-
- Fix #5464: Fix comment highlighting on permalink
1.10.2 (December 7, 2021)
-------------------------

View File

@ -223,21 +223,35 @@ class Comment extends ContentAddonActiveRecord implements ContentOwner
$cacheID = sprintf(static::CACHE_KEY_LIMITED, $model, $id);
$comments = $useCaching ? Yii::$app->cache->get($cacheID) : false;
if (!$useCaching || $comments === false) {
$commentCount = self::GetCommentCount($model, $id);
if ($comments === false) {
$objectCondition = ['object_model' => $model, 'object_id' => $id];
$query = Comment::find();
$query->offset($commentCount - $limit);
if ($currentCommentId && Comment::findOne(['id' => $currentCommentId])) {
$query->orderBy('`comment`.`id` <= ' . ($currentCommentId + intval($limit) - 1));
$nearCommentIds = Comment::find()
->select('id')
->where($objectCondition)
->andWhere(['<=', 'id', $currentCommentId])
->orderBy('created_at DESC')
->limit($limit)
->column();
if (count($nearCommentIds) < $limit) {
$newerCommentIds = Comment::find()
->select('id')
->where($objectCondition)
->andWhere(['>', 'id', $currentCommentId])
->orderBy('created_at ASC')
->limit($limit - count($nearCommentIds))
->column();
$nearCommentIds = array_merge($nearCommentIds, $newerCommentIds);
}
$query->where(['IN', 'id', $nearCommentIds]);
} else {
$query->orderBy('created_at ASC');
$query->where($objectCondition);
$query->limit($limit);
}
$query->limit($limit);
$query->where(['object_model' => $model, 'object_id' => $id]);
$query->joinWith('user');
$query->orderBy('created_at DESC');
$comments = array_reverse($query->all());
$comments = $query->all();
if ($useCaching) {
Yii::$app->cache->set($cacheID, $comments, Yii::$app->settings->get('cache.expireTime'));
}