mirror of
https://github.com/flarum/core.git
synced 2025-10-26 21:21:28 +01:00
Upgrade to L5 + huge refactor + more. closes #2
New stuff: - Signup + email confirmation. - Updated authentication strategy with remember cookies. closes #5 - New search system with some example gambits! This is cool - check out the source. Fulltext drivers will be implemented as decorators overriding the EloquentPostRepository’s findByContent method. - Lay down the foundation for bootstrapping the Ember app. - Update Web layer’s asset manager to properly publish CSS/JS files. - Console commands to run installation migrations and seeds. Refactoring: - New structure: move models, repositories, commands, and events into their own namespaces, rather than grouping by entity. - All events are classes. - Use L5 middleware and command bus implementations. - Clearer use of repositories and the Active Record pattern. Repositories are used only for retrieval of ActiveRecord objects, and then save/delete operations are called directly on those ActiveRecords. This way, we don’t over-abstract at the cost of Eloquent magic, but testing is still easy. - Refactor of Web layer so that it uses the Actions routing architecture. - “Actor” concept instead of depending on Laravel’s Auth. - General cleanup!
This commit is contained in:
17
src/Core/Seeders/ConfigTableSeeder.php
Normal file
17
src/Core/Seeders/ConfigTableSeeder.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php namespace Flarum\Core\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ConfigTableSeeder extends Seeder {
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
}
|
||||
137
src/Core/Seeders/DiscussionsTableSeeder.php
Normal file
137
src/Core/Seeders/DiscussionsTableSeeder.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php namespace Flarum\Core\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use DB;
|
||||
use Flarum\Core\Models\Discussion;
|
||||
use Flarum\Core\Models\Post;
|
||||
use Flarum\Core\Models\User;
|
||||
use Flarum\Core\Models\DiscussionState;
|
||||
|
||||
class DiscussionsTableSeeder extends Seeder
|
||||
{
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Discussion::unguard();
|
||||
Post::unguard();
|
||||
|
||||
$faker = \Faker\Factory::create();
|
||||
|
||||
$users = User::count();
|
||||
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
$posts_count = $i == 1 ? 400 : rand(1, rand(1, rand(1, 100)));
|
||||
$discussion = Discussion::create([
|
||||
'title' => str_replace("'", '', rtrim($faker->realText(rand(20, 80)), '.')),
|
||||
'start_time' => $faker->dateTimeThisYear,
|
||||
'start_user_id' => rand(1, $users)
|
||||
]);
|
||||
$discussion->comments_count = $posts_count;
|
||||
|
||||
$post = Post::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))
|
||||
]);
|
||||
|
||||
$discussion->start_post_id = $post->id;
|
||||
|
||||
$discussion->last_time = $post->time;
|
||||
$discussion->last_user_id = $post->user_id;
|
||||
$discussion->last_post_id = $post->id;
|
||||
$discussion->last_post_number = $post->number;
|
||||
$discussion->number_index = $post->number;
|
||||
|
||||
$lastPost = null;
|
||||
$count = $posts_count;
|
||||
$posts = [];
|
||||
$startTime = $discussion->start_time;
|
||||
$numberOffset = 0;
|
||||
|
||||
for ($j = 0; $j < $count - 1; $j++) {
|
||||
if (rand(1, 100) == 1) {
|
||||
$discussion->comments_count--;
|
||||
|
||||
$post = Post::create([
|
||||
'discussion_id' => $discussion->id,
|
||||
'time' => $startTime = date_add($startTime, date_interval_create_from_date_string('1 second')),
|
||||
'user_id' => rand(1, $users),
|
||||
'type' => 'renamed',
|
||||
'content' => json_encode(array($faker->realText(rand(20, 40)), $discussion->title))
|
||||
]);
|
||||
} else {
|
||||
$edited = rand(1, 20) == 1;
|
||||
$hidden = rand(1, 100) == 1;
|
||||
|
||||
if ($hidden) {
|
||||
$discussion->comments_count--;
|
||||
}
|
||||
|
||||
$post = Post::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,
|
||||
'hide_time' => $hidden ? $startTime = date_add($startTime, date_interval_create_from_date_string('1 second')) : null,
|
||||
'hide_user_id' => $hidden ? rand(1, $users) : null,
|
||||
]);
|
||||
|
||||
$posts[] = $post;
|
||||
|
||||
if (! $lastPost or $post->time >= $lastPost->time) {
|
||||
$lastPost = $post;
|
||||
}
|
||||
}
|
||||
|
||||
if (rand(1, 20) == 1) {
|
||||
$numberOffset += rand(0, 3);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the discussion's last post details.
|
||||
if ($lastPost) {
|
||||
$discussion->last_time = $lastPost->time;
|
||||
$discussion->last_user_id = $lastPost->user_id;
|
||||
$discussion->last_post_id = $lastPost->id;
|
||||
$discussion->last_post_number = $lastPost->number;
|
||||
}
|
||||
|
||||
$discussion->number_index = $j + 1 + $numberOffset;
|
||||
|
||||
$discussion->save();
|
||||
|
||||
// Give some users some random discussion state data.
|
||||
for ($j = rand(0, 100); $j < 100; $j++) {
|
||||
try {
|
||||
DiscussionState::create([
|
||||
'discussion_id' => $discussion->id,
|
||||
'user_id' => rand(1, $users),
|
||||
'read_number' => rand(0, $posts_count - 1),
|
||||
'read_time' => $faker->dateTimeBetween($discussion->start_time, 'now')
|
||||
]);
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update user post and discussion counts.
|
||||
$prefix = DB::getTablePrefix();
|
||||
DB::table('users')->update([
|
||||
'discussions_count' => DB::raw('(SELECT COUNT(id) FROM '.$prefix.'discussions WHERE start_user_id = '.$prefix.'users.id)'),
|
||||
'posts_count' => DB::raw('(SELECT COUNT(id) FROM '.$prefix.'posts WHERE user_id = '.$prefix.'users.id and type = "comment")'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
24
src/Core/Seeders/GroupsTableSeeder.php
Normal file
24
src/Core/Seeders/GroupsTableSeeder.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php namespace Flarum\Core\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Flarum\Core\Models\Group;
|
||||
|
||||
class GroupsTableSeeder extends Seeder {
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Group::unguard();
|
||||
Group::truncate();
|
||||
|
||||
$groups = ['Administrator', 'Guest', 'Member', 'Moderator', 'Staff'];
|
||||
foreach ($groups as $group) {
|
||||
Group::create(['name' => $group]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
47
src/Core/Seeders/PermissionsTableSeeder.php
Normal file
47
src/Core/Seeders/PermissionsTableSeeder.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php namespace Flarum\Core\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Flarum\Core\Models\Permission;
|
||||
|
||||
class PermissionsTableSeeder extends Seeder {
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Permission::truncate();
|
||||
|
||||
$permissions = [
|
||||
|
||||
// Guests can view the forum
|
||||
['group.2' , 'forum' , 'view'],
|
||||
['group.2' , 'forum' , 'register'],
|
||||
|
||||
// Members can create and reply to discussions + edit their own stuff
|
||||
['group.3' , 'forum' , 'startDiscussion'],
|
||||
['group.3' , 'discussion' , 'editOwn'],
|
||||
['group.3' , 'discussion' , 'reply'],
|
||||
['group.3' , 'post' , 'editOwn'],
|
||||
|
||||
// Moderators can edit + delete stuff and suspend users
|
||||
['group.4' , 'discussion' , 'delete'],
|
||||
['group.4' , 'discussion' , 'edit'],
|
||||
['group.4' , 'post' , 'delete'],
|
||||
['group.4' , 'post' , 'edit'],
|
||||
['group.4' , 'user' , 'suspend'],
|
||||
|
||||
];
|
||||
foreach ($permissions as &$permission) {
|
||||
$permission = [
|
||||
'grantee' => $permission[0],
|
||||
'entity' => $permission[1],
|
||||
'permission' => $permission[2]
|
||||
];
|
||||
}
|
||||
Permission::insert($permissions);
|
||||
}
|
||||
|
||||
}
|
||||
42
src/Core/Seeders/UsersTableSeeder.php
Normal file
42
src/Core/Seeders/UsersTableSeeder.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php namespace Flarum\Core\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Flarum\Core\Models\User;
|
||||
|
||||
class UsersTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
User::unguard();
|
||||
|
||||
$faker = \Faker\Factory::create();
|
||||
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
$user = User::create([
|
||||
'username' => $faker->userName,
|
||||
'email' => $faker->safeEmail,
|
||||
'is_confirmed' => true,
|
||||
'is_activated' => true,
|
||||
'password' => 'password',
|
||||
'join_time' => $faker->dateTimeThisYear
|
||||
]);
|
||||
|
||||
// Assign the users to the 'Member' group, and possibly some others.
|
||||
$user->groups()->attach(3);
|
||||
if (rand(1, 50) == 1) {
|
||||
$user->groups()->attach(4);
|
||||
}
|
||||
if (rand(1, 20) == 1) {
|
||||
$user->groups()->attach(5);
|
||||
}
|
||||
if (rand(1, 20) == 1) {
|
||||
$user->groups()->attach(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user