mirror of
https://github.com/flarum/framework.git
synced 2024-12-04 08:13:39 +08:00
Fix discussion seeder not using the correct post subtypes.
Related to #67.
This commit is contained in:
parent
4b9055ca70
commit
00bf235809
|
@ -3,7 +3,7 @@
|
|||
use Tobscure\Permissible\Permissible;
|
||||
use Flarum\Core\Events\PostWasDeleted;
|
||||
|
||||
class Post extends Model
|
||||
abstract class Post extends Model
|
||||
{
|
||||
use Permissible;
|
||||
|
||||
|
@ -46,6 +46,17 @@ class Post extends Model
|
|||
*/
|
||||
protected static $types = [];
|
||||
|
||||
/**
|
||||
* The type of post this is, to be stored in the posts table.
|
||||
*
|
||||
* Should be overwritten by subclasses with the value that is
|
||||
* to be stored in the database, which will then be used for
|
||||
* mapping the hydrated model instance to the proper subtype.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $type = '';
|
||||
|
||||
/**
|
||||
* Raise an event when a post is deleted. Add an event listener to set the
|
||||
* post's number, and update the discussion's number index, when inserting
|
||||
|
@ -58,6 +69,7 @@ class Post extends Model
|
|||
parent::boot();
|
||||
|
||||
static::creating(function ($post) {
|
||||
$post->type = $post::$type;
|
||||
$post->number = ++$post->discussion->number_index;
|
||||
$post->discussion->save();
|
||||
});
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
use Illuminate\Database\Seeder;
|
||||
use DB;
|
||||
use Flarum\Core\Models\CommentPost;
|
||||
use Flarum\Core\Models\Discussion;
|
||||
use Flarum\Core\Models\DiscussionRenamedPost;
|
||||
use Flarum\Core\Models\Post;
|
||||
use Flarum\Core\Models\User;
|
||||
use Flarum\Core\Models\DiscussionState;
|
||||
|
@ -33,12 +35,11 @@ class DiscussionsTableSeeder extends Seeder
|
|||
]);
|
||||
$discussion->comments_count = $posts_count;
|
||||
|
||||
$post = Post::create([
|
||||
$post = CommentPost::create([
|
||||
'discussion_id' => $discussion->id,
|
||||
'number' => 1,
|
||||
'time' => $discussion->start_time,
|
||||
'user_id' => $discussion->start_user_id,
|
||||
'type' => 'comment',
|
||||
'content' => $faker->realText(rand(100, 1000))
|
||||
]);
|
||||
|
||||
|
@ -60,11 +61,10 @@ class DiscussionsTableSeeder extends Seeder
|
|||
if (rand(1, 100) == 1) {
|
||||
$discussion->comments_count--;
|
||||
|
||||
$post = Post::create([
|
||||
$post = DiscussionRenamedPost::create([
|
||||
'discussion_id' => $discussion->id,
|
||||
'time' => $startTime = date_add($startTime, date_interval_create_from_date_string('1 second')),
|
||||
'user_id' => rand(1, $users),
|
||||
'type' => 'discussionRenamed',
|
||||
'content' => json_encode(array($faker->realText(rand(20, 40)), $discussion->title))
|
||||
]);
|
||||
} else {
|
||||
|
@ -75,12 +75,11 @@ class DiscussionsTableSeeder extends Seeder
|
|||
$discussion->comments_count--;
|
||||
}
|
||||
|
||||
$post = Post::create([
|
||||
$post = CommentPost::create([
|
||||
'discussion_id' => $discussion->id,
|
||||
'number' => $j + 2 + $numberOffset,
|
||||
'time' => $startTime = date_add($startTime, date_interval_create_from_date_string('1 second')),
|
||||
'user_id' => rand(1, $users),
|
||||
'type' => 'comment',
|
||||
'content' => $faker->realText(rand(50, 500)),
|
||||
'edit_time' => $edited ? $startTime = date_add($startTime, date_interval_create_from_date_string('1 second')) : null,
|
||||
'edit_user_id' => $edited ? rand(1, $users) : null,
|
||||
|
|
Loading…
Reference in New Issue
Block a user