mirror of
https://github.com/flarum/framework.git
synced 2025-04-25 14:14:03 +08:00
possibly fixes the issue with post number calculation
This commit is contained in:
parent
105481a181
commit
e429558d0e
@ -16,7 +16,9 @@ use Flarum\Foundation\EventGeneratorTrait;
|
|||||||
use Flarum\Notification\Notification;
|
use Flarum\Notification\Notification;
|
||||||
use Flarum\Post\Event\Deleted;
|
use Flarum\Post\Event\Deleted;
|
||||||
use Flarum\User\User;
|
use Flarum\User\User;
|
||||||
|
use Illuminate\Database\ConnectionInterface;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Query\Expression;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property int $id
|
* @property int $id
|
||||||
@ -91,7 +93,19 @@ class Post extends AbstractModel
|
|||||||
// discussion.
|
// discussion.
|
||||||
static::creating(function (self $post) {
|
static::creating(function (self $post) {
|
||||||
$post->type = $post::$type;
|
$post->type = $post::$type;
|
||||||
$post->number = ++$post->discussion->post_number_index;
|
|
||||||
|
/** @var ConnectionInterface $db */
|
||||||
|
$db = static::getConnectionResolver();
|
||||||
|
$post->number = new Expression('('. $db
|
||||||
|
->table('posts', 'pn')
|
||||||
|
->whereRaw('pn.discussion_id = ' . intval($post->discussion_id))
|
||||||
|
->select($db->raw('max(pn.number) + 1'))
|
||||||
|
->toSql()
|
||||||
|
.')');
|
||||||
|
});
|
||||||
|
|
||||||
|
static::created(function (self $post) {
|
||||||
|
$post->refresh();
|
||||||
$post->discussion->save();
|
$post->discussion->save();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user