mirror of
https://github.com/humhub/humhub.git
synced 2025-01-16 21:58:17 +01:00
Fix comment highlighting on permalink (#5474)
This commit is contained in:
parent
46004a8670
commit
073af01acc
@ -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)
|
||||
-------------------------
|
||||
|
@ -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'));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user