mirror of
https://github.com/flarum/framework.git
synced 2025-03-22 21:15:16 +08:00
Database changes (#11)
* Update core references * Update remaining core references
This commit is contained in:
parent
6b67263f01
commit
c4692d2bcd
@ -5,17 +5,17 @@ import { truncate } from 'flarum/utils/string';
|
||||
|
||||
export default function addStickyControl() {
|
||||
extend(DiscussionList.prototype, 'requestParams', function(params) {
|
||||
params.include.push('startPost');
|
||||
params.include.push('firstPost');
|
||||
});
|
||||
|
||||
extend(DiscussionListItem.prototype, 'infoItems', function(items) {
|
||||
const discussion = this.props.discussion;
|
||||
|
||||
if (discussion.isSticky() && !this.props.params.q && !discussion.readNumber()) {
|
||||
const startPost = discussion.startPost();
|
||||
if (discussion.isSticky() && !this.props.params.q && !discussion.lastReadPostNumber()) {
|
||||
const firstPost = discussion.firstPost();
|
||||
|
||||
if (startPost) {
|
||||
const excerpt = truncate(startPost.contentPlain(), 175);
|
||||
if (firstPost) {
|
||||
const excerpt = truncate(firstPost.contentPlain(), 175);
|
||||
|
||||
items.add('excerpt', excerpt, -100);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class AddApiAttributes
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(Serializing::class, [$this, 'prepareApiAttributes']);
|
||||
$events->listen(WillGetData::class, [$this, 'includeStartPost']);
|
||||
$events->listen(WillGetData::class, [$this, 'includeFirstPost']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,10 +42,10 @@ class AddApiAttributes
|
||||
/**
|
||||
* @param WillGetData $event
|
||||
*/
|
||||
public function includeStartPost(WillGetData $event)
|
||||
public function includeFirstPost(WillGetData $event)
|
||||
{
|
||||
if ($event->isController(ListDiscussionsController::class)) {
|
||||
$event->addInclude('startPost');
|
||||
$event->addInclude('firstPost');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,15 +74,15 @@ class PinStickiedDiscussionsToTop
|
||||
|
||||
$read = $query->newQuery()
|
||||
->selectRaw(1)
|
||||
->from('users_discussions as sticky')
|
||||
->from('discussion_user as sticky')
|
||||
->whereColumn('sticky.discussion_id', 'id')
|
||||
->where('sticky.user_id', '=', $search->getActor()->id)
|
||||
->whereColumn('sticky.read_number', '>=', 'last_post_number');
|
||||
->whereColumn('sticky.last_read_post_number', '>=', 'last_post_number');
|
||||
|
||||
// Add the bindings manually (rather than as the second
|
||||
// argument in orderByRaw) for now due to a bug in Laravel which
|
||||
// would add the bindings in the wrong order.
|
||||
$query->orderByRaw('is_sticky and not exists ('.$read->toSql().') and last_time > ? desc')
|
||||
$query->orderByRaw('is_sticky and not exists ('.$read->toSql().') and last_posted_at > ? desc')
|
||||
->addBinding(array_merge($read->getBindings(), [$search->getActor()->read_time ?: 0]), 'union');
|
||||
|
||||
$query->unionOrders = array_merge($query->unionOrders, $query->orders);
|
||||
|
@ -61,7 +61,7 @@ class DiscussionStickiedPost extends AbstractEventPost implements MergeableInter
|
||||
$post = new static;
|
||||
|
||||
$post->content = static::buildContent($isSticky);
|
||||
$post->time = time();
|
||||
$post->created_at = time();
|
||||
$post->discussion_id = $discussionId;
|
||||
$post->user_id = $userId;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user