3 namespace Database\Seeders;
5 use BookStack\Auth\Permissions\PermissionService;
6 use BookStack\Auth\Role;
7 use BookStack\Auth\User;
8 use BookStack\Entities\Models\Book;
9 use BookStack\Entities\Models\Chapter;
10 use BookStack\Entities\Models\Page;
11 use BookStack\Entities\Tools\SearchIndex;
12 use Illuminate\Database\Seeder;
13 use Illuminate\Support\Str;
15 class LargeContentSeeder extends Seeder
18 * Run the database seeds.
24 // Create an editor user
25 $editorUser = User::factory()->create();
26 $editorRole = Role::getRole('editor');
27 $editorUser->attachRole($editorRole);
29 /** @var Book $largeBook */
30 $largeBook = Book::factory()->create(['name' => 'Large book' . Str::random(10), 'created_by' => $editorUser->id, 'updated_by' => $editorUser->id]);
31 $pages = Page::factory()->count(200)->make(['created_by' => $editorUser->id, 'updated_by' => $editorUser->id]);
32 $chapters = Chapter::factory()->count(50)->make(['created_by' => $editorUser->id, 'updated_by' => $editorUser->id]);
34 $largeBook->pages()->saveMany($pages);
35 $largeBook->chapters()->saveMany($chapters);
36 $all = array_merge([$largeBook], array_values($pages->all()), array_values($chapters->all()));
38 app()->make(PermissionService::class)->buildJointPermissionsForEntity($largeBook);
39 app()->make(SearchIndex::class)->indexEntities($all);