repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Commands/RegeneratePermissionsCommandTest.php
tests/Commands/RegeneratePermissionsCommandTest.php
<?php namespace Tests\Commands; use BookStack\Auth\Permissions\CollapsedPermission; use BookStack\Permissions\Models\JointPermission; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\DB; use Tests\TestCase; class RegeneratePermissionsCommandTest extends TestCase { public function test_regen_permissions_command() { DB::rollBack(); $page = $this->entities->page(); $editor = $this->users->editor(); $role = $editor->roles()->first(); $this->permissions->addEntityPermission($page, ['view'], $role); JointPermission::query()->truncate(); $this->assertDatabaseMissing('joint_permissions', ['entity_id' => $page->id]); $exitCode = Artisan::call('bookstack:regenerate-permissions'); $this->assertTrue($exitCode === 0, 'Command executed successfully'); $this->assertDatabaseHas('joint_permissions', [ 'entity_id' => $page->id, 'entity_type' => 'page', 'role_id' => $role->id, 'status' => 3, // Explicit allow ]); $page->permissions()->delete(); $page->rebuildPermissions(); DB::beginTransaction(); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Commands/ClearActivityCommandTest.php
tests/Commands/ClearActivityCommandTest.php
<?php namespace Tests\Commands; use BookStack\Activity\ActivityType; use BookStack\Facades\Activity; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\DB; use Tests\TestCase; class ClearActivityCommandTest extends TestCase { public function test_clear_activity_command() { $this->asEditor(); $page = $this->entities->page(); Activity::add(ActivityType::PAGE_UPDATE, $page); $this->assertDatabaseHas('activities', [ 'type' => 'page_update', 'loggable_id' => $page->id, 'user_id' => $this->users->editor()->id, ]); DB::rollBack(); $exitCode = Artisan::call('bookstack:clear-activity'); DB::beginTransaction(); $this->assertTrue($exitCode === 0, 'Command executed successfully'); $this->assertDatabaseMissing('activities', [ 'type' => 'page_update', ]); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Commands/CreateAdminCommandTest.php
tests/Commands/CreateAdminCommandTest.php
<?php namespace Tests\Commands; use BookStack\Users\Models\Role; use BookStack\Users\Models\User; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Tests\TestCase; class CreateAdminCommandTest extends TestCase { public function test_standard_command_usage() { $this->artisan('bookstack:create-admin', [ '--email' => 'admintest@example.com', '--name' => 'Admin Test', '--password' => 'testing-4', ])->assertExitCode(0); $this->assertDatabaseHas('users', [ 'email' => 'admintest@example.com', 'name' => 'Admin Test', ]); /** @var User $user */ $user = User::query()->where('email', '=', 'admintest@example.com')->first(); $this->assertTrue($user->hasSystemRole('admin')); $this->assertTrue(Auth::attempt(['email' => 'admintest@example.com', 'password' => 'testing-4'])); } public function test_providing_external_auth_id() { $this->artisan('bookstack:create-admin', [ '--email' => 'admintest@example.com', '--name' => 'Admin Test', '--external-auth-id' => 'xX_admin_Xx', ])->assertExitCode(0); $this->assertDatabaseHas('users', [ 'email' => 'admintest@example.com', 'name' => 'Admin Test', 'external_auth_id' => 'xX_admin_Xx', ]); /** @var User $user */ $user = User::query()->where('email', '=', 'admintest@example.com')->first(); $this->assertNotEmpty($user->password); } public function test_password_required_if_external_auth_id_not_given() { $this->artisan('bookstack:create-admin', [ '--email' => 'admintest@example.com', '--name' => 'Admin Test', ])->expectsQuestion('Please specify a password for the new admin user (8 characters min)', 'hunter2000') ->assertExitCode(0); $this->assertDatabaseHas('users', [ 'email' => 'admintest@example.com', 'name' => 'Admin Test', ]); $this->assertTrue(Auth::attempt(['email' => 'admintest@example.com', 'password' => 'hunter2000'])); } public function test_generate_password_option() { $this->withoutMockingConsoleOutput() ->artisan('bookstack:create-admin', [ '--email' => 'admintest@example.com', '--name' => 'Admin Test', '--generate-password' => true, ]); $output = trim(Artisan::output()); $this->assertMatchesRegularExpression('/^[a-zA-Z0-9]{32}$/', $output); $user = User::query()->where('email', '=', 'admintest@example.com')->first(); $this->assertTrue(Hash::check($output, $user->password)); } public function test_initial_option_updates_default_admin() { $defaultAdmin = User::query()->where('email', '=', 'admin@admin.com')->first(); $this->artisan('bookstack:create-admin', [ '--email' => 'firstadmin@example.com', '--name' => 'Admin Test', '--password' => 'testing-7', '--initial' => true, ])->expectsOutput('The default admin user has been updated with the provided details!') ->assertExitCode(0); $defaultAdmin->refresh(); $this->assertEquals('firstadmin@example.com', $defaultAdmin->email); } public function test_initial_option_does_not_update_if_only_non_default_admin_exists() { $defaultAdmin = User::query()->where('email', '=', 'admin@admin.com')->first(); $defaultAdmin->email = 'testadmin@example.com'; $defaultAdmin->save(); $this->artisan('bookstack:create-admin', [ '--email' => 'firstadmin@example.com', '--name' => 'Admin Test', '--password' => 'testing-7', '--initial' => true, ])->expectsOutput('Non-default admin user already exists. Skipping creation of new admin user.') ->assertExitCode(2); $defaultAdmin->refresh(); $this->assertEquals('testadmin@example.com', $defaultAdmin->email); } public function test_initial_option_updates_creates_new_admin_if_none_exists() { $adminRole = Role::getSystemRole('admin'); $adminRole->users()->delete(); $this->assertEquals(0, $adminRole->users()->count()); $this->artisan('bookstack:create-admin', [ '--email' => 'firstadmin@example.com', '--name' => 'My initial admin', '--password' => 'testing-7', '--initial' => true, ])->expectsOutput("Admin account with email \"firstadmin@example.com\" successfully created!") ->assertExitCode(0); $this->assertEquals(1, $adminRole->users()->count()); $this->assertDatabaseHas('users', [ 'email' => 'firstadmin@example.com', 'name' => 'My initial admin', ]); } public function test_initial_rerun_does_not_error_but_skips() { $adminRole = Role::getSystemRole('admin'); $adminRole->users()->delete(); $this->artisan('bookstack:create-admin', [ '--email' => 'firstadmin@example.com', '--name' => 'My initial admin', '--password' => 'testing-7', '--initial' => true, ])->expectsOutput("Admin account with email \"firstadmin@example.com\" successfully created!") ->assertExitCode(0); $this->artisan('bookstack:create-admin', [ '--email' => 'firstadmin@example.com', '--name' => 'My initial admin', '--password' => 'testing-7', '--initial' => true, ])->expectsOutput("Non-default admin user already exists. Skipping creation of new admin user.") ->assertExitCode(2); } public function test_initial_option_creation_errors_if_email_already_exists() { $adminRole = Role::getSystemRole('admin'); $adminRole->users()->delete(); $editor = $this->users->editor(); $this->artisan('bookstack:create-admin', [ '--email' => $editor->email, '--name' => 'My initial admin', '--password' => 'testing-7', '--initial' => true, ])->expectsOutput("Could not create admin account.") ->expectsOutput("An account with the email address \"{$editor->email}\" already exists.") ->assertExitCode(1); } public function test_initial_option_updating_errors_if_email_already_exists() { $editor = $this->users->editor(); $defaultAdmin = User::query()->where('email', '=', 'admin@admin.com')->first(); $this->assertNotNull($defaultAdmin); $this->artisan('bookstack:create-admin', [ '--email' => $editor->email, '--name' => 'My initial admin', '--password' => 'testing-7', '--initial' => true, ])->expectsOutput("Could not create admin account.") ->expectsOutput("An account with the email address \"{$editor->email}\" already exists.") ->assertExitCode(1); } public function test_initial_option_does_not_require_name_or_email_to_be_passed() { $adminRole = Role::getSystemRole('admin'); $adminRole->users()->delete(); $this->assertEquals(0, $adminRole->users()->count()); $this->artisan('bookstack:create-admin', [ '--generate-password' => true, '--initial' => true, ])->assertExitCode(0); $this->assertEquals(1, $adminRole->users()->count()); $this->assertDatabaseHas('users', [ 'email' => 'admin@example.com', 'name' => 'Admin', ]); } public function test_initial_option_updating_existing_user_with_generate_password_only_outputs_password() { $defaultAdmin = User::query()->where('email', '=', 'admin@admin.com')->first(); $this->withoutMockingConsoleOutput() ->artisan('bookstack:create-admin', [ '--email' => 'firstadmin@example.com', '--name' => 'Admin Test', '--generate-password' => true, '--initial' => true, ]); $output = Artisan::output(); $this->assertMatchesRegularExpression('/^[a-zA-Z0-9]{32}$/', $output); $defaultAdmin->refresh(); $this->assertEquals('firstadmin@example.com', $defaultAdmin->email); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Commands/CleanupImagesCommandTest.php
tests/Commands/CleanupImagesCommandTest.php
<?php namespace Tests\Commands; use BookStack\Uploads\Image; use Tests\TestCase; class CleanupImagesCommandTest extends TestCase { public function test_command_defaults_to_dry_run() { $page = $this->entities->page(); $image = Image::factory()->create(['uploaded_to' => $page->id]); $this->artisan('bookstack:cleanup-images -v') ->expectsOutput('Dry run, no images have been deleted') ->expectsOutput('1 image(s) found that would have been deleted') ->expectsOutputToContain($image->path) ->assertExitCode(0); $this->assertDatabaseHas('images', ['id' => $image->id]); } public function test_command_force_run() { $page = $this->entities->page(); $image = Image::factory()->create(['uploaded_to' => $page->id]); $this->artisan('bookstack:cleanup-images --force') ->expectsOutputToContain('This operation is destructive and is not guaranteed to be fully accurate') ->expectsConfirmation('Are you sure you want to proceed?', 'yes') ->expectsOutput('1 image(s) deleted') ->assertExitCode(0); $this->assertDatabaseMissing('images', ['id' => $image->id]); } public function test_command_force_run_negative_confirmation() { $page = $this->entities->page(); $image = Image::factory()->create(['uploaded_to' => $page->id]); $this->artisan('bookstack:cleanup-images --force') ->expectsConfirmation('Are you sure you want to proceed?', 'no') ->assertExitCode(0); $this->assertDatabaseHas('images', ['id' => $image->id]); } public function test_command_force_no_interaction_run() { $page = $this->entities->page(); $image = Image::factory()->create(['uploaded_to' => $page->id]); $this->artisan('bookstack:cleanup-images --force --no-interaction') ->expectsOutputToContain('This operation is destructive and is not guaranteed to be fully accurate') ->expectsOutput('1 image(s) deleted') ->assertExitCode(0); $this->assertDatabaseMissing('images', ['id' => $image->id]); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Commands/ClearViewsCommandTest.php
tests/Commands/ClearViewsCommandTest.php
<?php namespace Tests\Commands; use BookStack\Entities\Models\Page; use Illuminate\Support\Facades\DB; use Tests\TestCase; class ClearViewsCommandTest extends TestCase { public function test_clear_views_command() { $this->asEditor(); $page = Page::first(); $this->get($page->getUrl()); $this->assertDatabaseHas('views', [ 'user_id' => $this->users->editor()->id, 'viewable_id' => $page->id, 'views' => 1, ]); DB::rollBack(); $exitCode = \Artisan::call('bookstack:clear-views'); DB::beginTransaction(); $this->assertTrue($exitCode === 0, 'Command executed successfully'); $this->assertDatabaseMissing('views', [ 'user_id' => $this->users->editor()->id, ]); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Commands/UpgradeDatabaseEncodingCommandTest.php
tests/Commands/UpgradeDatabaseEncodingCommandTest.php
<?php namespace Tests\Commands; use Tests\TestCase; class UpgradeDatabaseEncodingCommandTest extends TestCase { public function test_command_outputs_sql() { $this->artisan('bookstack:db-utf8mb4') ->expectsOutputToContain('ALTER DATABASE') ->expectsOutputToContain('ALTER TABLE `users` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;'); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Commands/RegenerateSearchCommandTest.php
tests/Commands/RegenerateSearchCommandTest.php
<?php namespace Tests\Commands; use BookStack\Search\SearchTerm; use Illuminate\Support\Facades\DB; use Tests\TestCase; class RegenerateSearchCommandTest extends TestCase { public function test_command_regenerates_index() { DB::rollBack(); $page = $this->entities->page(); SearchTerm::truncate(); $this->assertDatabaseMissing('search_terms', ['entity_id' => $page->id]); $this->artisan('bookstack:regenerate-search') ->expectsOutput('Search index regenerated!') ->assertExitCode(0); $this->assertDatabaseHas('search_terms', [ 'entity_type' => 'page', 'entity_id' => $page->id ]); DB::beginTransaction(); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Commands/UpdateUrlCommandTest.php
tests/Commands/UpdateUrlCommandTest.php
<?php namespace Tests\Commands; use BookStack\Entities\Models\Entity; use Illuminate\Support\Facades\Artisan; use Symfony\Component\Console\Exception\RuntimeException; use Tests\TestCase; class UpdateUrlCommandTest extends TestCase { public function test_command_updates_page_content() { $page = $this->entities->page(); $page->html = '<a href="https://example.com/donkeys"></a>'; $page->save(); $this->artisan('bookstack:update-url https://example.com https://cats.example.com') ->expectsQuestion("This will search for \"https://example.com\" in your database and replace it with \"https://cats.example.com\".\nAre you sure you want to proceed?", 'y') ->expectsQuestion('This operation could cause issues if used incorrectly. Have you made a backup of your existing database?', 'y'); $this->assertDatabaseHasEntityData('page', [ 'id' => $page->id, 'html' => '<a href="https://cats.example.com/donkeys"></a>', ]); } public function test_command_updates_description_html() { /** @var Entity[] $models */ $models = [$this->entities->book(), $this->entities->chapter(), $this->entities->shelf()]; foreach ($models as $model) { $model->description_html = '<a href="https://example.com/donkeys"></a>'; $model->save(); } $this->artisan('bookstack:update-url https://example.com https://cats.example.com') ->expectsQuestion("This will search for \"https://example.com\" in your database and replace it with \"https://cats.example.com\".\nAre you sure you want to proceed?", 'y') ->expectsQuestion('This operation could cause issues if used incorrectly. Have you made a backup of your existing database?', 'y'); foreach ($models as $model) { $this->assertDatabaseHasEntityData($model->getMorphClass(), [ 'id' => $model->id, 'description_html' => '<a href="https://cats.example.com/donkeys"></a>', ]); } } public function test_command_requires_valid_url() { $badUrlMessage = 'The given urls are expected to be full urls starting with http:// or https://'; $this->artisan('bookstack:update-url //example.com https://cats.example.com')->expectsOutput($badUrlMessage); $this->artisan('bookstack:update-url https://example.com htts://cats.example.com')->expectsOutput($badUrlMessage); $this->artisan('bookstack:update-url example.com https://cats.example.com')->expectsOutput($badUrlMessage); $this->expectException(RuntimeException::class); $this->artisan('bookstack:update-url https://cats.example.com'); } public function test_command_force_option_skips_prompt() { $this->artisan('bookstack:update-url --force https://cats.example.com/donkey https://cats.example.com/monkey') ->expectsOutputToContain('URL update procedure complete') ->assertSuccessful(); } public function test_command_updates_settings() { setting()->put('my-custom-item', 'https://example.com/donkey/cat'); $this->runUpdate('https://example.com', 'https://cats.example.com'); setting()->flushCache(); $settingVal = setting('my-custom-item'); $this->assertEquals('https://cats.example.com/donkey/cat', $settingVal); } public function test_command_updates_array_settings() { setting()->put('my-custom-array-item', [['name' => 'a https://example.com/donkey/cat url']]); $this->runUpdate('https://example.com', 'https://cats.example.com'); setting()->flushCache(); $settingVal = setting('my-custom-array-item'); $this->assertEquals('a https://cats.example.com/donkey/cat url', $settingVal[0]['name']); } public function test_command_updates_page_revisions() { $page = $this->entities->page(); for ($i = 0; $i < 2; $i++) { $this->entities->updatePage($page, [ 'name' => $page->name, 'markdown' => "[A link {$i}](https://example.com/donkey/cat)" ]); } $this->runUpdate('https://example.com', 'https://cats.example.com'); setting()->flushCache(); $this->assertDatabaseHas('page_revisions', [ 'page_id' => $page->id, 'markdown' => '[A link 1](https://cats.example.com/donkey/cat)', 'html' => '<p id="bkmrk-a-link-1"><a href="https://cats.example.com/donkey/cat">A link 1</a></p>' . "\n" ]); } protected function runUpdate(string $oldUrl, string $newUrl) { $this->artisan("bookstack:update-url {$oldUrl} {$newUrl}") ->expectsQuestion("This will search for \"{$oldUrl}\" in your database and replace it with \"{$newUrl}\".\nAre you sure you want to proceed?", 'y') ->expectsQuestion('This operation could cause issues if used incorrectly. Have you made a backup of your existing database?', 'y'); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Commands/RegenerateReferencesCommandTest.php
tests/Commands/RegenerateReferencesCommandTest.php
<?php namespace Tests\Commands; use Illuminate\Support\Facades\DB; use Tests\TestCase; class RegenerateReferencesCommandTest extends TestCase { public function test_regenerate_references_command() { $page = $this->entities->page(); $book = $page->book; $page->html = '<a href="' . $book->getUrl() . '">Book Link</a>'; $page->save(); DB::table('references')->delete(); $this->artisan('bookstack:regenerate-references') ->assertExitCode(0); $this->assertDatabaseHas('references', [ 'from_id' => $page->id, 'from_type' => $page->getMorphClass(), 'to_id' => $book->id, 'to_type' => $book->getMorphClass(), ]); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Commands/CopyShelfPermissionsCommandTest.php
tests/Commands/CopyShelfPermissionsCommandTest.php
<?php namespace Tests\Commands; use BookStack\Entities\Models\Bookshelf; use Tests\TestCase; class CopyShelfPermissionsCommandTest extends TestCase { public function test_copy_shelf_permissions_command_shows_error_when_no_required_option_given() { $this->artisan('bookstack:copy-shelf-permissions') ->expectsOutput('Either a --slug or --all option must be provided.') ->assertExitCode(1); } public function test_copy_shelf_permissions_command_using_slug() { $shelf = $this->entities->shelf(); $child = $shelf->books()->first(); $editorRole = $this->users->editor()->roles()->first(); $this->assertFalse($child->hasPermissions(), 'Child book should not be restricted by default'); $this->assertTrue($child->permissions()->count() === 0, 'Child book should have no permissions by default'); $this->permissions->setEntityPermissions($shelf, ['view', 'update'], [$editorRole]); $this->artisan('bookstack:copy-shelf-permissions', [ '--slug' => $shelf->slug, ]); $child = $shelf->books()->first(); $this->assertTrue($child->hasPermissions(), 'Child book should now be restricted'); $this->assertEquals(2, $child->permissions()->count(), 'Child book should have copied permissions'); $this->assertDatabaseHas('entity_permissions', [ 'entity_type' => 'book', 'entity_id' => $child->id, 'role_id' => $editorRole->id, 'view' => true, 'update' => true, 'create' => false, 'delete' => false, ]); } public function test_copy_shelf_permissions_command_using_all() { $shelf = $this->entities->shelf(); Bookshelf::query()->where('id', '!=', $shelf->id)->delete(); $child = $shelf->books()->first(); $editorRole = $this->users->editor()->roles()->first(); $this->assertFalse($child->hasPermissions(), 'Child book should not be restricted by default'); $this->assertTrue($child->permissions()->count() === 0, 'Child book should have no permissions by default'); $this->permissions->setEntityPermissions($shelf, ['view', 'update'], [$editorRole]); $this->artisan('bookstack:copy-shelf-permissions --all') ->expectsQuestion('Permission settings for all shelves will be cascaded. Books assigned to multiple shelves will receive only the permissions of it\'s last processed shelf. Are you sure you want to proceed?', 'y'); $child = $shelf->books()->first(); $this->assertTrue($child->hasPermissions(), 'Child book should now be restricted'); $this->assertEquals(2, $child->permissions()->count(), 'Child book should have copied permissions'); $this->assertDatabaseHas('entity_permissions', [ 'entity_type' => 'book', 'entity_id' => $child->id, 'role_id' => $editorRole->id, 'view' => true, 'update' => true, 'create' => false, 'delete' => false, ]); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Commands/DeleteUsersCommandTest.php
tests/Commands/DeleteUsersCommandTest.php
<?php namespace Tests\Commands; use BookStack\Users\Models\User; use Illuminate\Database\Eloquent\Collection; use Tests\TestCase; class DeleteUsersCommandTest extends TestCase { public function test_command_deletes_users() { $userCount = User::query()->count(); $normalUsers = $this->getNormalUsers(); $normalUserCount = $userCount - count($normalUsers); $this->artisan('bookstack:delete-users') ->expectsConfirmation('Are you sure you want to continue?', 'yes') ->expectsOutputToContain("Deleted $normalUserCount of $userCount total users.") ->assertExitCode(0); $this->assertDatabaseMissing('users', ['id' => $normalUsers->first()->id]); } public function test_command_requires_confirmation() { $normalUsers = $this->getNormalUsers(); $this->artisan('bookstack:delete-users') ->expectsConfirmation('Are you sure you want to continue?', 'no') ->assertExitCode(0); $this->assertDatabaseHas('users', ['id' => $normalUsers->first()->id]); } protected function getNormalUsers(): Collection { return User::query()->whereNull('system_name') ->get() ->filter(function (User $user) { return !$user->hasSystemRole('admin'); }); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Commands/AssignSortRuleCommandTest.php
tests/Commands/AssignSortRuleCommandTest.php
<?php namespace Tests\Commands; use BookStack\Entities\Models\Book; use BookStack\Sorting\SortRule; use Tests\TestCase; class AssignSortRuleCommandTest extends TestCase { public function test_no_given_sort_rule_lists_options() { $sortRules = SortRule::factory()->createMany(10); $commandRun = $this->artisan('bookstack:assign-sort-rule') ->expectsOutputToContain('Sort rule ID required!') ->assertExitCode(1); foreach ($sortRules as $sortRule) { $commandRun->expectsOutputToContain("{$sortRule->id}: {$sortRule->name}"); } } public function test_run_without_options_advises_help() { $this->artisan("bookstack:assign-sort-rule 100") ->expectsOutput("No option provided to specify target. Run with the -h option to see all available options.") ->assertExitCode(1); } public function test_run_without_valid_sort_advises_help() { $this->artisan("bookstack:assign-sort-rule 100342 --all-books") ->expectsOutput("Sort rule of provided id 100342 not found!") ->assertExitCode(1); } public function test_confirmation_required() { $sortRule = SortRule::factory()->create(); $this->artisan("bookstack:assign-sort-rule {$sortRule->id} --all-books") ->expectsConfirmation('Are you sure you want to continue?', 'no') ->assertExitCode(1); $booksWithSort = Book::query()->whereNotNull('sort_rule_id')->count(); $this->assertEquals(0, $booksWithSort); } public function test_assign_to_all_books() { $sortRule = SortRule::factory()->create(); $booksWithoutSort = Book::query()->whereNull('sort_rule_id')->count(); $this->assertGreaterThan(0, $booksWithoutSort); $this->artisan("bookstack:assign-sort-rule {$sortRule->id} --all-books") ->expectsOutputToContain("This will apply sort rule [{$sortRule->id}: {$sortRule->name}] to {$booksWithoutSort} book(s)") ->expectsConfirmation('Are you sure you want to continue?', 'yes') ->expectsOutputToContain("Sort applied to {$booksWithoutSort} book(s)") ->assertExitCode(0); $booksWithoutSort = Book::query()->whereNull('sort_rule_id')->count(); $this->assertEquals(0, $booksWithoutSort); } public function test_assign_to_all_books_without_sort() { $totalBooks = Book::query()->count(); $book = $this->entities->book(); $sortRuleA = SortRule::factory()->create(); $sortRuleB = SortRule::factory()->create(); $book->sort_rule_id = $sortRuleA->id; $book->save(); $booksWithoutSort = Book::query()->whereNull('sort_rule_id')->count(); $this->assertEquals($totalBooks, $booksWithoutSort + 1); $this->artisan("bookstack:assign-sort-rule {$sortRuleB->id} --books-without-sort") ->expectsConfirmation('Are you sure you want to continue?', 'yes') ->expectsOutputToContain("Sort applied to {$booksWithoutSort} book(s)") ->assertExitCode(0); $booksWithoutSort = Book::query()->whereNull('sort_rule_id')->count(); $this->assertEquals(0, $booksWithoutSort); $this->assertEquals($totalBooks, $sortRuleB->books()->count() + 1); } public function test_assign_to_all_books_with_sort() { $book = $this->entities->book(); $sortRuleA = SortRule::factory()->create(); $sortRuleB = SortRule::factory()->create(); $book->sort_rule_id = $sortRuleA->id; $book->save(); $this->artisan("bookstack:assign-sort-rule {$sortRuleB->id} --books-with-sort={$sortRuleA->id}") ->expectsConfirmation('Are you sure you want to continue?', 'yes') ->expectsOutputToContain("Sort applied to 1 book(s)") ->assertExitCode(0); $book->refresh(); $this->assertEquals($sortRuleB->id, $book->sort_rule_id); $this->assertEquals(1, $sortRuleB->books()->count()); } public function test_assign_to_all_books_with_sort_id_is_validated() { $this->artisan("bookstack:assign-sort-rule 50 --books-with-sort=beans") ->expectsOutputToContain("Provided --books-with-sort option value is invalid") ->assertExitCode(1); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Commands/ClearRevisionsCommandTest.php
tests/Commands/ClearRevisionsCommandTest.php
<?php namespace Tests\Commands; use BookStack\Entities\Models\Page; use BookStack\Entities\Repos\PageRepo; use Illuminate\Support\Facades\Artisan; use Tests\TestCase; class ClearRevisionsCommandTest extends TestCase { public function test_clear_revisions_command() { $this->asEditor(); $pageRepo = app(PageRepo::class); $page = Page::first(); $pageRepo->update($page, ['name' => 'updated page', 'html' => '<p>new content</p>', 'summary' => 'page revision testing']); $pageRepo->updatePageDraft($page, ['name' => 'updated page', 'html' => '<p>new content in draft</p>', 'summary' => 'page revision testing']); $this->assertDatabaseHas('page_revisions', [ 'page_id' => $page->id, 'type' => 'version', ]); $this->assertDatabaseHas('page_revisions', [ 'page_id' => $page->id, 'type' => 'update_draft', ]); $exitCode = Artisan::call('bookstack:clear-revisions'); $this->assertTrue($exitCode === 0, 'Command executed successfully'); $this->assertDatabaseMissing('page_revisions', [ 'page_id' => $page->id, 'type' => 'version', ]); $this->assertDatabaseHas('page_revisions', [ 'page_id' => $page->id, 'type' => 'update_draft', ]); $exitCode = Artisan::call('bookstack:clear-revisions', ['--all' => true]); $this->assertTrue($exitCode === 0, 'Command executed successfully'); $this->assertDatabaseMissing('page_revisions', [ 'page_id' => $page->id, 'type' => 'update_draft', ]); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Sorting/SortRuleTest.php
tests/Sorting/SortRuleTest.php
<?php namespace Tests\Sorting; use BookStack\Activity\ActivityType; use BookStack\Entities\Models\Book; use BookStack\Sorting\SortRule; use BookStack\Sorting\SortRuleOperation; use Tests\Api\TestsApi; use Tests\TestCase; class SortRuleTest extends TestCase { use TestsApi; public function test_manage_settings_permission_required() { $rule = SortRule::factory()->create(); $user = $this->users->viewer(); $this->actingAs($user); $actions = [ ['GET', '/settings/sorting'], ['POST', '/settings/sorting/rules'], ['GET', "/settings/sorting/rules/{$rule->id}"], ['PUT', "/settings/sorting/rules/{$rule->id}"], ['DELETE', "/settings/sorting/rules/{$rule->id}"], ]; foreach ($actions as [$method, $path]) { $resp = $this->call($method, $path); $this->assertPermissionError($resp); } $this->permissions->grantUserRolePermissions($user, ['settings-manage']); foreach ($actions as [$method, $path]) { $resp = $this->call($method, $path); $this->assertNotPermissionError($resp); } } public function test_create_flow() { $resp = $this->asAdmin()->get('/settings/sorting'); $this->withHtml($resp)->assertLinkExists(url('/settings/sorting/rules/new')); $resp = $this->get('/settings/sorting/rules/new'); $this->withHtml($resp)->assertElementExists('form[action$="/settings/sorting/rules"] input[name="name"]'); $resp->assertSeeText('Name - Alphabetical (Asc)'); $details = ['name' => 'My new sort', 'sequence' => 'name_asc']; $resp = $this->post('/settings/sorting/rules', $details); $resp->assertRedirect('/settings/sorting'); $this->assertActivityExists(ActivityType::SORT_RULE_CREATE); $this->assertDatabaseHas('sort_rules', $details); } public function test_listing_in_settings() { $rule = SortRule::factory()->create(['name' => 'My super sort rule', 'sequence' => 'name_asc']); $books = Book::query()->limit(5)->get(); foreach ($books as $book) { $book->sort_rule_id = $rule->id; $book->save(); } $resp = $this->asAdmin()->get('/settings/sorting'); $resp->assertSeeText('My super sort rule'); $resp->assertSeeText('Name - Alphabetical (Asc)'); $this->withHtml($resp)->assertElementContains('.item-list-row [title="Assigned to 5 Books"]', '5'); } public function test_update_flow() { $rule = SortRule::factory()->create(['name' => 'My sort rule to update', 'sequence' => 'name_asc']); $resp = $this->asAdmin()->get("/settings/sorting/rules/{$rule->id}"); $respHtml = $this->withHtml($resp); $respHtml->assertElementContains('.configured-option-list', 'Name - Alphabetical (Asc)'); $respHtml->assertElementNotContains('.available-option-list', 'Name - Alphabetical (Asc)'); $updateData = ['name' => 'My updated sort', 'sequence' => 'name_desc,chapters_last']; $resp = $this->put("/settings/sorting/rules/{$rule->id}", $updateData); $resp->assertRedirect('/settings/sorting'); $this->assertActivityExists(ActivityType::SORT_RULE_UPDATE); $this->assertDatabaseHas('sort_rules', $updateData); } public function test_update_triggers_resort_on_assigned_books() { $book = $this->entities->bookHasChaptersAndPages(); $chapter = $book->chapters()->first(); $rule = SortRule::factory()->create(['name' => 'My sort rule to update', 'sequence' => 'name_asc']); $book->sort_rule_id = $rule->id; $book->save(); $chapter->priority = 10000; $chapter->save(); $resp = $this->asAdmin()->put("/settings/sorting/rules/{$rule->id}", ['name' => $rule->name, 'sequence' => 'chapters_last']); $resp->assertRedirect('/settings/sorting'); $chapter->refresh(); $this->assertNotEquals(10000, $chapter->priority); } public function test_delete_flow() { $rule = SortRule::factory()->create(); $resp = $this->asAdmin()->get("/settings/sorting/rules/{$rule->id}"); $resp->assertSeeText('Delete Sort Rule'); $resp = $this->delete("settings/sorting/rules/{$rule->id}"); $resp->assertRedirect('/settings/sorting'); $this->assertActivityExists(ActivityType::SORT_RULE_DELETE); $this->assertDatabaseMissing('sort_rules', ['id' => $rule->id]); } public function test_delete_requires_confirmation_if_books_assigned() { $rule = SortRule::factory()->create(); $books = Book::query()->limit(5)->get(); foreach ($books as $book) { $book->sort_rule_id = $rule->id; $book->save(); } $resp = $this->asAdmin()->get("/settings/sorting/rules/{$rule->id}"); $resp->assertSeeText('Delete Sort Rule'); $resp = $this->delete("settings/sorting/rules/{$rule->id}"); $resp->assertRedirect("/settings/sorting/rules/{$rule->id}#delete"); $resp = $this->followRedirects($resp); $resp->assertSeeText('This sort rule is currently used on 5 book(s). Are you sure you want to delete this?'); $this->assertDatabaseHas('sort_rules', ['id' => $rule->id]); $resp = $this->delete("settings/sorting/rules/{$rule->id}", ['confirm' => 'true']); $resp->assertRedirect('/settings/sorting'); $this->assertDatabaseMissing('sort_rules', ['id' => $rule->id]); $this->assertDatabaseMissing('entity_container_data', ['sort_rule_id' => $rule->id]); } public function test_page_create_triggers_book_sort() { $book = $this->entities->bookHasChaptersAndPages(); $rule = SortRule::factory()->create(['sequence' => 'name_asc,chapters_first']); $book->sort_rule_id = $rule->id; $book->save(); $resp = $this->actingAsApiEditor()->post("/api/pages", [ 'book_id' => $book->id, 'name' => '1111 page', 'markdown' => 'Hi' ]); $resp->assertOk(); $this->assertDatabaseHasEntityData('page', [ 'book_id' => $book->id, 'name' => '1111 page', 'priority' => $book->chapters()->count() + 1, ]); } public function test_auto_book_sort_does_not_touch_timestamps() { $book = $this->entities->bookHasChaptersAndPages(); $rule = SortRule::factory()->create(['sequence' => 'name_asc,chapters_first']); $book->sort_rule_id = $rule->id; $book->save(); $page = $book->pages()->first(); $chapter = $book->chapters()->first(); $resp = $this->actingAsApiEditor()->put("/api/pages/{$page->id}", [ 'name' => '1111 page', ]); $resp->assertOk(); $oldTime = $chapter->updated_at->unix(); $oldPriority = $chapter->priority; $chapter->refresh(); $this->assertEquals($oldTime, $chapter->updated_at->unix()); $this->assertNotEquals($oldPriority, $chapter->priority); } public function test_name_alphabetical_ordering() { $book = Book::factory()->create(); $rule = SortRule::factory()->create(['sequence' => 'name_asc']); $book->sort_rule_id = $rule->id; $book->save(); $this->permissions->regenerateForEntity($book); $namesToAdd = [ "Beans", "bread", "Éclaire", "egg", "É😀ire", "É🫠ire", "Milk", "pizza", "Tomato", ]; $reverseNamesToAdd = array_reverse($namesToAdd); foreach ($reverseNamesToAdd as $name) { $this->actingAsApiEditor()->post("/api/pages", [ 'book_id' => $book->id, 'name' => $name, 'markdown' => 'Hello' ]); } foreach ($namesToAdd as $index => $name) { $this->assertDatabaseHasEntityData('page', [ 'book_id' => $book->id, 'name' => $name, 'priority' => $index + 1, ]); } } public function test_name_numeric_ordering() { $book = Book::factory()->create(); $rule = SortRule::factory()->create(['sequence' => 'name_numeric_asc']); $book->sort_rule_id = $rule->id; $book->save(); $this->permissions->regenerateForEntity($book); $namesToAdd = [ "1 - Pizza", "2.0 - Tomato", "2.5 - Beans", "10 - Bread", "20 - Milk", ]; $reverseNamesToAdd = array_reverse($namesToAdd); foreach ($reverseNamesToAdd as $name) { $this->actingAsApiEditor()->post("/api/pages", [ 'book_id' => $book->id, 'name' => $name, 'markdown' => 'Hello' ]); } foreach ($namesToAdd as $index => $name) { $this->assertDatabaseHasEntityData('page', [ 'book_id' => $book->id, 'name' => $name, 'priority' => $index + 1, ]); } } public function test_each_sort_rule_operation_has_a_comparison_function() { $operations = SortRuleOperation::cases(); foreach ($operations as $operation) { $comparisonFunc = $operation->getSortFunction(); $this->assertIsCallable($comparisonFunc); } } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Sorting/BookSortTest.php
tests/Sorting/BookSortTest.php
<?php namespace Tests\Sorting; use BookStack\Entities\Models\Chapter; use BookStack\Entities\Models\Page; use BookStack\Entities\Repos\PageRepo; use BookStack\Sorting\SortRule; use Tests\TestCase; class BookSortTest extends TestCase { public function test_book_sort_page_shows() { $bookToSort = $this->entities->book(); $resp = $this->asAdmin()->get($bookToSort->getUrl()); $this->withHtml($resp)->assertElementExists('a[href="' . $bookToSort->getUrl('/sort') . '"]'); $resp = $this->get($bookToSort->getUrl('/sort')); $resp->assertStatus(200); $resp->assertSee($bookToSort->name); } public function test_drafts_do_not_show_up() { $this->asAdmin(); $pageRepo = app(PageRepo::class); $book = $this->entities->book(); $draft = $pageRepo->getNewDraftPage($book); $resp = $this->get($book->getUrl()); $resp->assertSee($draft->name); $resp = $this->get($book->getUrl('/sort')); $resp->assertDontSee($draft->name); } public function test_book_sort() { $oldBook = $this->entities->book(); $chapterToMove = $this->entities->newChapter(['name' => 'chapter to move'], $oldBook); $newBook = $this->entities->newBook(['name' => 'New sort book']); $pagesToMove = Page::query()->take(5)->get(); // Create request data $reqData = [ [ 'id' => $chapterToMove->id, 'sort' => 0, 'parentChapter' => false, 'type' => 'chapter', 'book' => $newBook->id, ], ]; foreach ($pagesToMove as $index => $page) { $reqData[] = [ 'id' => $page->id, 'sort' => $index, 'parentChapter' => $index === count($pagesToMove) - 1 ? $chapterToMove->id : false, 'type' => 'page', 'book' => $newBook->id, ]; } $sortResp = $this->asEditor()->put($newBook->getUrl() . '/sort', ['sort-tree' => json_encode($reqData)]); $sortResp->assertRedirect($newBook->getUrl()); $sortResp->assertStatus(302); $this->assertDatabaseHasEntityData('chapter', [ 'id' => $chapterToMove->id, 'book_id' => $newBook->id, 'priority' => 0, ]); $this->assertTrue($newBook->chapters()->count() === 1); $this->assertTrue($newBook->chapters()->first()->pages()->count() === 1); $checkPage = $pagesToMove[1]; $checkResp = $this->get($checkPage->refresh()->getUrl()); $checkResp->assertSee($newBook->name); } public function test_book_sort_makes_no_changes_if_new_chapter_does_not_align_with_new_book() { $page = $this->entities->pageWithinChapter(); $otherChapter = Chapter::query()->where('book_id', '!=', $page->book_id)->first(); $sortData = [ 'id' => $page->id, 'sort' => 0, 'parentChapter' => $otherChapter->id, 'type' => 'page', 'book' => $page->book_id, ]; $this->asEditor()->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect(); $this->assertDatabaseHasEntityData('page', [ 'id' => $page->id, 'chapter_id' => $page->chapter_id, 'book_id' => $page->book_id, ]); } public function test_book_sort_makes_no_changes_if_no_view_permissions_on_new_chapter() { $page = $this->entities->pageWithinChapter(); /** @var Chapter $otherChapter */ $otherChapter = Chapter::query()->where('book_id', '!=', $page->book_id)->first(); $this->permissions->setEntityPermissions($otherChapter); $sortData = [ 'id' => $page->id, 'sort' => 0, 'parentChapter' => $otherChapter->id, 'type' => 'page', 'book' => $otherChapter->book_id, ]; $this->asEditor()->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect(); $this->assertDatabaseHasEntityData('page', [ 'id' => $page->id, 'chapter_id' => $page->chapter_id, 'book_id' => $page->book_id, ]); } public function test_book_sort_makes_no_changes_if_no_view_permissions_on_new_book() { $page = $this->entities->pageWithinChapter(); /** @var Chapter $otherChapter */ $otherChapter = Chapter::query()->where('book_id', '!=', $page->book_id)->first(); $editor = $this->users->editor(); $this->permissions->setEntityPermissions($otherChapter->book, ['update', 'delete'], [$editor->roles()->first()]); $sortData = [ 'id' => $page->id, 'sort' => 0, 'parentChapter' => $otherChapter->id, 'type' => 'page', 'book' => $otherChapter->book_id, ]; $this->actingAs($editor)->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect(); $this->assertDatabaseHasEntityData('page', [ 'id' => $page->id, 'chapter_id' => $page->chapter_id, 'book_id' => $page->book_id, ]); } public function test_book_sort_makes_no_changes_if_no_update_or_create_permissions_on_new_chapter() { $page = $this->entities->pageWithinChapter(); /** @var Chapter $otherChapter */ $otherChapter = Chapter::query()->where('book_id', '!=', $page->book_id)->first(); $editor = $this->users->editor(); $this->permissions->setEntityPermissions($otherChapter, ['view', 'delete'], [$editor->roles()->first()]); $sortData = [ 'id' => $page->id, 'sort' => 0, 'parentChapter' => $otherChapter->id, 'type' => 'page', 'book' => $otherChapter->book_id, ]; $this->actingAs($editor)->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect(); $this->assertDatabaseHasEntityData('page', [ 'id' => $page->id, 'chapter_id' => $page->chapter_id, 'book_id' => $page->book_id, ]); } public function test_book_sort_makes_no_changes_if_no_update_permissions_on_moved_item() { $page = $this->entities->pageWithinChapter(); /** @var Chapter $otherChapter */ $otherChapter = Chapter::query()->where('book_id', '!=', $page->book_id)->first(); $editor = $this->users->editor(); $this->permissions->setEntityPermissions($page, ['view', 'delete'], [$editor->roles()->first()]); $sortData = [ 'id' => $page->id, 'sort' => 0, 'parentChapter' => $otherChapter->id, 'type' => 'page', 'book' => $otherChapter->book_id, ]; $this->actingAs($editor)->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect(); $this->assertDatabaseHasEntityData('page', [ 'id' => $page->id, 'chapter_id' => $page->chapter_id, 'book_id' => $page->book_id, ]); } public function test_book_sort_makes_no_changes_if_no_delete_permissions_on_moved_item() { $page = $this->entities->pageWithinChapter(); /** @var Chapter $otherChapter */ $otherChapter = Chapter::query()->where('book_id', '!=', $page->book_id)->first(); $editor = $this->users->editor(); $this->permissions->setEntityPermissions($page, ['view', 'update'], [$editor->roles()->first()]); $sortData = [ 'id' => $page->id, 'sort' => 0, 'parentChapter' => $otherChapter->id, 'type' => 'page', 'book' => $otherChapter->book_id, ]; $this->actingAs($editor)->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect(); $this->assertDatabaseHasEntityData('page', [ 'id' => $page->id, 'chapter_id' => $page->chapter_id, 'book_id' => $page->book_id, ]); } public function test_book_sort_does_not_change_timestamps_on_just_order_changes() { $book = $this->entities->bookHasChaptersAndPages(); $chapter = $book->chapters()->first(); Chapter::query()->where('id', '=', $chapter->id)->update([ 'priority' => 10001, 'updated_at' => \Carbon\Carbon::now()->subYear(5), ]); $chapter->refresh(); $oldUpdatedAt = $chapter->updated_at->unix(); $sortData = [ 'id' => $chapter->id, 'sort' => 0, 'parentChapter' => false, 'type' => 'chapter', 'book' => $book->id, ]; $this->asEditor()->put($book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect(); $chapter->refresh(); $this->assertNotEquals(10001, $chapter->priority); $this->assertEquals($oldUpdatedAt, $chapter->updated_at->unix()); } public function test_book_sort_item_returns_book_content() { $bookToSort = $this->entities->book(); $firstPage = $bookToSort->pages[0]; $firstChapter = $bookToSort->chapters[0]; $resp = $this->asAdmin()->get($bookToSort->getUrl('/sort-item')); // Ensure book details are returned $resp->assertSee($bookToSort->name); $resp->assertSee($firstPage->name); $resp->assertSee($firstChapter->name); } public function test_book_sort_item_shows_auto_sort_status() { $sort = SortRule::factory()->create(['name' => 'My sort']); $book = $this->entities->book(); $resp = $this->asAdmin()->get($book->getUrl('/sort-item')); $this->withHtml($resp)->assertElementNotExists("span[title='Auto Sort Active: My sort']"); $book->sort_rule_id = $sort->id; $book->save(); $resp = $this->asAdmin()->get($book->getUrl('/sort-item')); $this->withHtml($resp)->assertElementExists("span[title='Auto Sort Active: My sort']"); } public function test_auto_sort_options_shown_on_sort_page() { $sort = SortRule::factory()->create(); $book = $this->entities->book(); $resp = $this->asAdmin()->get($book->getUrl('/sort')); $this->withHtml($resp)->assertElementExists('select[name="auto-sort"] option[value="' . $sort->id . '"]'); } public function test_auto_sort_option_submit_saves_to_book() { $sort = SortRule::factory()->create(); $book = $this->entities->book(); $bookPage = $book->pages()->first(); $bookPage->priority = 10000; $bookPage->save(); $resp = $this->asAdmin()->put($book->getUrl('/sort'), [ 'auto-sort' => $sort->id, ]); $resp->assertRedirect($book->getUrl()); $book->refresh(); $bookPage->refresh(); $this->assertEquals($sort->id, $book->sort_rule_id); $this->assertNotEquals(10000, $bookPage->priority); $resp = $this->get($book->getUrl('/sort')); $this->withHtml($resp)->assertElementExists('select[name="auto-sort"] option[value="' . $sort->id . '"][selected]'); } public function test_pages_in_book_show_sorted_by_priority() { $book = $this->entities->bookHasChaptersAndPages(); $book->chapters()->forceDelete(); /** @var Page[] $pages */ $pages = $book->pages()->whereNull('chapter_id')->take(2)->get(); $book->pages()->whereNotIn('id', $pages->pluck('id'))->delete(); $resp = $this->asEditor()->get($book->getUrl()); $this->withHtml($resp)->assertElementContains('.content-wrap a.page:nth-child(1)', $pages[0]->name); $this->withHtml($resp)->assertElementContains('.content-wrap a.page:nth-child(2)', $pages[1]->name); $pages[0]->forceFill(['priority' => 10])->save(); $pages[1]->forceFill(['priority' => 5])->save(); $resp = $this->asEditor()->get($book->getUrl()); $this->withHtml($resp)->assertElementContains('.content-wrap a.page:nth-child(1)', $pages[1]->name); $this->withHtml($resp)->assertElementContains('.content-wrap a.page:nth-child(2)', $pages[0]->name); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Sorting/MoveTest.php
tests/Sorting/MoveTest.php
<?php namespace Tests\Sorting; use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Chapter; use BookStack\Entities\Models\Page; use Tests\TestCase; class MoveTest extends TestCase { public function test_page_move_into_book() { $page = $this->entities->page(); $currentBook = $page->book; $newBook = Book::query()->where('id', '!=', $currentBook->id)->first(); $resp = $this->asEditor()->get($page->getUrl('/move')); $resp->assertSee('Move Page'); $movePageResp = $this->put($page->getUrl('/move'), [ 'entity_selection' => 'book:' . $newBook->id, ])->assertRedirect(); $page->refresh(); $movePageResp->assertRedirect($page->getUrl()); $this->assertTrue($page->book->id == $newBook->id, 'Page book is now the new book'); $newBookResp = $this->get($newBook->getUrl()); $newBookResp->assertSee('moved page'); $newBookResp->assertSee($page->name); } public function test_page_move_into_chapter() { $page = $this->entities->page(); $currentBook = $page->book; $newBook = Book::query()->where('id', '!=', $currentBook->id)->first(); $newChapter = $newBook->chapters()->first(); $movePageResp = $this->actingAs($this->users->editor())->put($page->getUrl('/move'), [ 'entity_selection' => 'chapter:' . $newChapter->id, ]); $page->refresh(); $movePageResp->assertRedirect($page->getUrl()); $this->assertTrue($page->book->id == $newBook->id, 'Page parent is now the new chapter'); $newChapterResp = $this->get($newChapter->getUrl()); $newChapterResp->assertSee($page->name); } public function test_page_move_from_chapter_to_book() { $oldChapter = Chapter::query()->first(); $page = $oldChapter->pages()->first(); $newBook = Book::query()->where('id', '!=', $oldChapter->book_id)->first(); $movePageResp = $this->actingAs($this->users->editor())->put($page->getUrl('/move'), [ 'entity_selection' => 'book:' . $newBook->id, ]); $page->refresh(); $movePageResp->assertRedirect($page->getUrl()); $this->assertTrue($page->book->id == $newBook->id, 'Page parent is now the new book'); $this->assertTrue($page->chapter === null, 'Page has no parent chapter'); $newBookResp = $this->get($newBook->getUrl()); $newBookResp->assertSee($page->name); } public function test_page_move_requires_create_permissions_on_parent() { $page = $this->entities->page(); $currentBook = $page->book; $newBook = Book::query()->where('id', '!=', $currentBook->id)->first(); $editor = $this->users->editor(); $this->permissions->setEntityPermissions($newBook, ['view', 'update', 'delete'], $editor->roles->all()); $movePageResp = $this->actingAs($editor)->put($page->getUrl('/move'), [ 'entity_selection' => 'book:' . $newBook->id, ]); $this->assertPermissionError($movePageResp); $this->permissions->setEntityPermissions($newBook, ['view', 'update', 'delete', 'create'], $editor->roles->all()); $movePageResp = $this->put($page->getUrl('/move'), [ 'entity_selection' => 'book:' . $newBook->id, ]); $page->refresh(); $movePageResp->assertRedirect($page->getUrl()); $this->assertTrue($page->book->id == $newBook->id, 'Page book is now the new book'); } public function test_page_move_requires_delete_permissions() { $page = $this->entities->page(); $currentBook = $page->book; $newBook = Book::query()->where('id', '!=', $currentBook->id)->first(); $editor = $this->users->editor(); $this->permissions->setEntityPermissions($newBook, ['view', 'update', 'create', 'delete'], $editor->roles->all()); $this->permissions->setEntityPermissions($page, ['view', 'update', 'create'], $editor->roles->all()); $movePageResp = $this->actingAs($editor)->put($page->getUrl('/move'), [ 'entity_selection' => 'book:' . $newBook->id, ]); $this->assertPermissionError($movePageResp); $pageView = $this->get($page->getUrl()); $pageView->assertDontSee($page->getUrl('/move')); $this->permissions->setEntityPermissions($page, ['view', 'update', 'create', 'delete'], $editor->roles->all()); $movePageResp = $this->put($page->getUrl('/move'), [ 'entity_selection' => 'book:' . $newBook->id, ]); $page->refresh(); $movePageResp->assertRedirect($page->getUrl()); $this->assertTrue($page->book->id == $newBook->id, 'Page book is now the new book'); } public function test_chapter_move() { $chapter = $this->entities->chapter(); $currentBook = $chapter->book; $pageToCheck = $chapter->pages->first(); $newBook = Book::query()->where('id', '!=', $currentBook->id)->first(); $chapterMoveResp = $this->asEditor()->get($chapter->getUrl('/move')); $chapterMoveResp->assertSee('Move Chapter'); $moveChapterResp = $this->put($chapter->getUrl('/move'), [ 'entity_selection' => 'book:' . $newBook->id, ]); $chapter = Chapter::query()->find($chapter->id); $moveChapterResp->assertRedirect($chapter->getUrl()); $this->assertTrue($chapter->book->id === $newBook->id, 'Chapter Book is now the new book'); $newBookResp = $this->get($newBook->getUrl()); $newBookResp->assertSee('moved chapter'); $newBookResp->assertSee($chapter->name); $pageToCheck = Page::query()->find($pageToCheck->id); $this->assertTrue($pageToCheck->book_id === $newBook->id, 'Chapter child page\'s book id has changed to the new book'); $pageCheckResp = $this->get($pageToCheck->getUrl()); $pageCheckResp->assertSee($newBook->name); } public function test_chapter_move_requires_delete_permissions() { $chapter = $this->entities->chapter(); $currentBook = $chapter->book; $newBook = Book::query()->where('id', '!=', $currentBook->id)->first(); $editor = $this->users->editor(); $this->permissions->setEntityPermissions($newBook, ['view', 'update', 'create', 'delete'], $editor->roles->all()); $this->permissions->setEntityPermissions($chapter, ['view', 'update', 'create'], $editor->roles->all()); $moveChapterResp = $this->actingAs($editor)->put($chapter->getUrl('/move'), [ 'entity_selection' => 'book:' . $newBook->id, ]); $this->assertPermissionError($moveChapterResp); $pageView = $this->get($chapter->getUrl()); $pageView->assertDontSee($chapter->getUrl('/move')); $this->permissions->setEntityPermissions($chapter, ['view', 'update', 'create', 'delete'], $editor->roles->all()); $moveChapterResp = $this->put($chapter->getUrl('/move'), [ 'entity_selection' => 'book:' . $newBook->id, ]); $chapter = Chapter::query()->find($chapter->id); $moveChapterResp->assertRedirect($chapter->getUrl()); $this->assertTrue($chapter->book->id == $newBook->id, 'Page book is now the new book'); } public function test_chapter_move_requires_create_permissions_in_new_book() { $chapter = $this->entities->chapter(); $currentBook = $chapter->book; $newBook = Book::query()->where('id', '!=', $currentBook->id)->first(); $editor = $this->users->editor(); $this->permissions->setEntityPermissions($newBook, ['view', 'update', 'delete'], [$editor->roles->first()]); $this->permissions->setEntityPermissions($chapter, ['view', 'update', 'create', 'delete'], [$editor->roles->first()]); $moveChapterResp = $this->actingAs($editor)->put($chapter->getUrl('/move'), [ 'entity_selection' => 'book:' . $newBook->id, ]); $this->assertPermissionError($moveChapterResp); $this->permissions->setEntityPermissions($newBook, ['view', 'update', 'create', 'delete'], [$editor->roles->first()]); $moveChapterResp = $this->put($chapter->getUrl('/move'), [ 'entity_selection' => 'book:' . $newBook->id, ]); $chapter = Chapter::query()->find($chapter->id); $moveChapterResp->assertRedirect($chapter->getUrl()); $this->assertTrue($chapter->book->id == $newBook->id, 'Page book is now the new book'); } public function test_chapter_move_changes_book_for_deleted_pages_within() { /** @var Chapter $chapter */ $chapter = Chapter::query()->whereHas('pages')->first(); $currentBook = $chapter->book; $pageToCheck = $chapter->pages->first(); $newBook = Book::query()->where('id', '!=', $currentBook->id)->first(); $pageToCheck->delete(); $this->asEditor()->put($chapter->getUrl('/move'), [ 'entity_selection' => 'book:' . $newBook->id, ]); $pageToCheck->refresh(); $this->assertEquals($newBook->id, $pageToCheck->book_id); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Settings/RegenerateReferencesTest.php
tests/Settings/RegenerateReferencesTest.php
<?php namespace Tests\Settings; use BookStack\Activity\ActivityType; use BookStack\References\ReferenceStore; use Tests\TestCase; class RegenerateReferencesTest extends TestCase { public function test_option_visible_on_maintenance_page() { $pageView = $this->asAdmin()->get('/settings/maintenance'); $formCssSelector = 'form[action$="/settings/maintenance/regenerate-references"]'; $html = $this->withHtml($pageView); $html->assertElementExists('#regenerate-references'); $html->assertElementExists($formCssSelector); $html->assertElementContains($formCssSelector . ' button', 'Regenerate References'); } public function test_action_runs_reference_regen() { $this->mock(ReferenceStore::class) ->shouldReceive('updateForAll') ->once(); $resp = $this->asAdmin()->post('/settings/maintenance/regenerate-references'); $resp->assertRedirect('/settings/maintenance#regenerate-references'); $this->assertSessionHas('success', 'Reference index has been regenerated!'); $this->assertActivityExists(ActivityType::MAINTENANCE_ACTION_RUN, null, 'regenerate-references'); } public function test_settings_manage_permission_required() { $editor = $this->users->editor(); $resp = $this->actingAs($editor)->post('/settings/maintenance/regenerate-references'); $this->assertPermissionError($resp); $this->permissions->grantUserRolePermissions($editor, ['settings-manage']); $resp = $this->actingAs($editor)->post('/settings/maintenance/regenerate-references'); $this->assertNotPermissionError($resp); } public function test_action_failed_shown_as_error_notification() { $this->mock(ReferenceStore::class) ->shouldReceive('updateForAll') ->andThrow(\Exception::class, 'A badger stopped the task'); $resp = $this->asAdmin()->post('/settings/maintenance/regenerate-references'); $resp->assertRedirect('/settings/maintenance#regenerate-references'); $this->assertSessionError('A badger stopped the task'); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Settings/TestEmailTest.php
tests/Settings/TestEmailTest.php
<?php namespace Tests\Settings; use BookStack\Settings\TestEmailNotification; use Illuminate\Contracts\Notifications\Dispatcher; use Illuminate\Support\Facades\Notification; use Tests\TestCase; class TestEmailTest extends TestCase { public function test_a_send_test_button_shows() { $pageView = $this->asAdmin()->get('/settings/maintenance'); $formCssSelector = 'form[action$="/settings/maintenance/send-test-email"]'; $this->withHtml($pageView)->assertElementExists($formCssSelector); $this->withHtml($pageView)->assertElementContains($formCssSelector . ' button', 'Send Test Email'); } public function test_send_test_email_endpoint_sends_email_and_redirects_user_and_shows_notification() { Notification::fake(); $admin = $this->users->admin(); $sendReq = $this->actingAs($admin)->post('/settings/maintenance/send-test-email'); $sendReq->assertRedirect('/settings/maintenance#image-cleanup'); $this->assertSessionHas('success', 'Email sent to ' . $admin->email); Notification::assertSentTo($admin, TestEmailNotification::class); } public function test_send_test_email_failure_displays_error_notification() { $mockDispatcher = $this->mock(Dispatcher::class); $this->app[Dispatcher::class] = $mockDispatcher; $exception = new \Exception('A random error occurred when testing an email'); $mockDispatcher->shouldReceive('sendNow')->andThrow($exception); $admin = $this->users->admin(); $sendReq = $this->actingAs($admin)->post('/settings/maintenance/send-test-email'); $sendReq->assertRedirect('/settings/maintenance#image-cleanup'); $this->assertSessionHas('error'); $message = session()->get('error'); $this->assertStringContainsString('Error thrown when sending a test email:', $message); $this->assertStringContainsString('A random error occurred when testing an email', $message); } public function test_send_test_email_requires_settings_manage_permission() { Notification::fake(); $user = $this->users->viewer(); $sendReq = $this->actingAs($user)->post('/settings/maintenance/send-test-email'); Notification::assertNothingSent(); $this->permissions->grantUserRolePermissions($user, ['settings-manage']); $sendReq = $this->actingAs($user)->post('/settings/maintenance/send-test-email'); Notification::assertSentTo($user, TestEmailNotification::class); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Settings/PageListLimitsTest.php
tests/Settings/PageListLimitsTest.php
<?php namespace Tests\Settings; use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Bookshelf; use Tests\TestCase; class PageListLimitsTest extends TestCase { public function test_saving_setting_and_loading() { $resp = $this->asAdmin()->post('/settings/sorting', [ 'setting-lists-page-count-shelves' => '3', 'setting-lists-page-count-books' => '6', 'setting-lists-page-count-search' => '9', ]); $resp->assertRedirect('/settings/sorting'); $this->assertEquals(3, setting()->getInteger('lists-page-count-shelves', 18)); $this->assertEquals(6, setting()->getInteger('lists-page-count-books', 18)); $this->assertEquals(9, setting()->getInteger('lists-page-count-search', 18)); $resp = $this->get('/settings/sorting'); $html = $this->withHtml($resp); $html->assertFieldHasValue('setting-lists-page-count-shelves', '3'); $html->assertFieldHasValue('setting-lists-page-count-books', '6'); $html->assertFieldHasValue('setting-lists-page-count-search', '9'); } public function test_invalid_counts_will_use_default_when_fetched_as_an_integer() { $this->asAdmin()->post('/settings/sorting', [ 'setting-lists-page-count-shelves' => 'cat', ]); $this->assertEquals(18, setting()->getInteger('lists-page-count-shelves', 18)); } public function test_shelf_count_is_used_on_shelves_view() { $resp = $this->asAdmin()->get('/shelves'); $defaultCount = min(Bookshelf::query()->count(), 18); $this->withHtml($resp)->assertElementCount('main [data-entity-type="bookshelf"]', $defaultCount); $this->post('/settings/sorting', [ 'setting-lists-page-count-shelves' => '1', ]); $resp = $this->get('/shelves'); $this->withHtml($resp)->assertElementCount('main [data-entity-type="bookshelf"]', 1); } public function test_book_count_is_used_on_books_view() { $resp = $this->asAdmin()->get('/books'); $defaultCount = min(Book::query()->count(), 18); $this->withHtml($resp)->assertElementCount('main [data-entity-type="book"]', $defaultCount); $this->post('/settings/sorting', [ 'setting-lists-page-count-books' => '1', ]); $resp = $this->get('/books'); $this->withHtml($resp)->assertElementCount('main [data-entity-type="book"]', 1); } public function test_search_count_is_used_on_search_view() { $resp = $this->asAdmin()->get('/search'); $this->withHtml($resp)->assertElementCount('.entity-list [data-entity-id]', 18); $this->post('/settings/sorting', [ 'setting-lists-page-count-search' => '1', ]); $resp = $this->get('/search'); $this->withHtml($resp)->assertElementCount('.entity-list [data-entity-id]', 1); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Settings/CustomHeadContentTest.php
tests/Settings/CustomHeadContentTest.php
<?php namespace Tests\Settings; use BookStack\Util\CspService; use Tests\TestCase; class CustomHeadContentTest extends TestCase { public function test_configured_content_shows_on_pages() { $this->setSettings(['app-custom-head' => '<script>console.log("cat");</script>']); $resp = $this->get('/login'); $resp->assertSee('console.log("cat")', false); } public function test_content_wrapped_in_specific_html_comments() { // These comments are used to identify head content for editor injection $this->setSettings(['app-custom-head' => '<script>console.log("cat");</script>']); $resp = $this->get('/login'); $resp->assertSee('<!-- Start: custom user content -->', false); $resp->assertSee('<!-- End: custom user content -->', false); } public function test_configured_content_does_not_show_on_settings_page() { $this->setSettings(['app-custom-head' => '<script>console.log("cat");</script>']); $resp = $this->asAdmin()->get('/settings/features'); $resp->assertDontSee('console.log("cat")', false); } public function test_divs_in_js_preserved_in_configured_content() { $this->setSettings(['app-custom-head' => '<script><div id="hello">cat</div></script>']); $resp = $this->get('/login'); $resp->assertSee('<div id="hello">cat</div>', false); } public function test_nonce_application_handles_edge_cases() { $mockCSP = $this->mock(CspService::class); $mockCSP->shouldReceive('getNonce')->andReturn('abc123'); $content = trim(' <script>console.log("cat");</script> <script type="text/html"><\script>const a = `<div></div>`<\/\script></script> <script >const a = `<div></div>`;</script> <script type="<script text>test">const c = `<div></div>`;</script> <script type="text/html" > const a = `<\script><\/script>`; const b = `<script`; </script> <SCRIPT>const b = `↗️£`;</SCRIPT> '); $expectedOutput = trim(' <script nonce="abc123">console.log("cat");</script> <script type="text/html" nonce="abc123"><\script>const a = `<div></div>`<\/\script></script> <script nonce="abc123">const a = `<div></div>`;</script> <script type="&lt;script text&gt;test" nonce="abc123">const c = `<div></div>`;</script> <script type="text/html" nonce="abc123"> const a = `<\script><\/script>`; const b = `<script`; </script> <script nonce="abc123">const b = `↗️£`;</script> '); $this->setSettings(['app-custom-head' => $content]); $resp = $this->get('/login'); $resp->assertSee($expectedOutput, false); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Settings/RecycleBinTest.php
tests/Settings/RecycleBinTest.php
<?php namespace Tests\Settings; use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Chapter; use BookStack\Entities\Models\Deletion; use BookStack\Entities\Models\Page; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; use Tests\TestCase; class RecycleBinTest extends TestCase { public function test_recycle_bin_routes_permissions() { $page = $this->entities->page(); $editor = $this->users->editor(); $this->actingAs($editor)->delete($page->getUrl()); $deletion = Deletion::query()->firstOrFail(); $routes = [ 'GET:/settings/recycle-bin', 'POST:/settings/recycle-bin/empty', "GET:/settings/recycle-bin/{$deletion->id}/destroy", "GET:/settings/recycle-bin/{$deletion->id}/restore", "POST:/settings/recycle-bin/{$deletion->id}/restore", "DELETE:/settings/recycle-bin/{$deletion->id}", ]; foreach ($routes as $route) { [$method, $url] = explode(':', $route); $resp = $this->call($method, $url); $this->assertPermissionError($resp); } $this->permissions->grantUserRolePermissions($editor, ['restrictions-manage-all']); foreach ($routes as $route) { [$method, $url] = explode(':', $route); $resp = $this->call($method, $url); $this->assertPermissionError($resp); } $this->permissions->grantUserRolePermissions($editor, ['settings-manage']); foreach ($routes as $route) { DB::beginTransaction(); [$method, $url] = explode(':', $route); $resp = $this->call($method, $url); $this->assertNotPermissionError($resp); DB::rollBack(); } } public function test_recycle_bin_view() { $page = $this->entities->page(); $book = Book::query()->whereHas('pages')->whereHas('chapters')->withCount(['pages', 'chapters'])->first(); $editor = $this->users->editor(); $this->actingAs($editor)->delete($page->getUrl()); $this->actingAs($editor)->delete($book->getUrl()); $viewReq = $this->asAdmin()->get('/settings/recycle-bin'); $html = $this->withHtml($viewReq); $html->assertElementContains('.item-list-row', $page->name); $html->assertElementContains('.item-list-row', $editor->name); $html->assertElementContains('.item-list-row', $book->name); $html->assertElementContains('.item-list-row', $book->pages_count . ' Pages'); $html->assertElementContains('.item-list-row', $book->chapters_count . ' Chapters'); } public function test_recycle_bin_empty() { $page = $this->entities->page(); $book = Book::query()->where('id', '!=', $page->book_id)->whereHas('pages')->whereHas('chapters')->with(['pages', 'chapters'])->firstOrFail(); $editor = $this->users->editor(); $this->actingAs($editor)->delete($page->getUrl()); $this->actingAs($editor)->delete($book->getUrl()); $this->assertTrue(Deletion::query()->count() === 2); $emptyReq = $this->asAdmin()->post('/settings/recycle-bin/empty'); $emptyReq->assertRedirect('/settings/recycle-bin'); $this->assertTrue(Deletion::query()->count() === 0); $this->assertDatabaseMissing('entities', ['id' => $book->id, 'type' => 'book']); $this->assertDatabaseMissing('entity_container_data', ['entity_id' => $book->id, 'entity_type' => 'book']); $this->assertDatabaseMissing('entities', ['id' => $book->pages->first()->id, 'type' => 'page']); $this->assertDatabaseMissing('entity_page_data', ['page_id' => $book->pages->first()->id]); $this->assertDatabaseMissing('entities', ['id' => $book->chapters->first()->id, 'type' => 'chapter']); $this->assertDatabaseMissing('entity_container_data', ['entity_id' => $book->chapters->first()->id, 'entity_type' => 'chapter']); $itemCount = 2 + $book->pages->count() + $book->chapters->count(); $redirectReq = $this->get('/settings/recycle-bin'); $this->assertNotificationContains($redirectReq, 'Deleted ' . $itemCount . ' total items from the recycle bin'); } public function test_entity_restore() { $book = $this->entities->bookHasChaptersAndPages(); $this->asEditor()->delete($book->getUrl())->assertRedirect(); $deletion = Deletion::query()->firstOrFail(); $this->assertEquals($book->pages->count(), Page::query()->withTrashed()->where('book_id', '=', $book->id)->whereNotNull('deleted_at')->count()); $this->assertEquals($book->chapters->count(), Chapter::query()->withTrashed()->where('book_id', '=', $book->id)->whereNotNull('deleted_at')->count()); $restoreReq = $this->asAdmin()->post("/settings/recycle-bin/{$deletion->id}/restore"); $restoreReq->assertRedirect('/settings/recycle-bin'); $this->assertTrue(Deletion::query()->count() === 0); $this->assertEquals($book->pages->count(), Page::query()->where('book_id', '=', $book->id)->whereNull('deleted_at')->count()); $this->assertEquals($book->chapters->count(), Chapter::query()->where('book_id', '=', $book->id)->whereNull('deleted_at')->count()); $itemCount = 1 + $book->pages->count() + $book->chapters->count(); $redirectReq = $this->get('/settings/recycle-bin'); $this->assertNotificationContains($redirectReq, 'Restored ' . $itemCount . ' total items from the recycle bin'); } public function test_permanent_delete() { $book = $this->entities->bookHasChaptersAndPages(); $this->asEditor()->delete($book->getUrl()); $deletion = Deletion::query()->firstOrFail(); $deleteReq = $this->asAdmin()->delete("/settings/recycle-bin/{$deletion->id}"); $deleteReq->assertRedirect('/settings/recycle-bin'); $this->assertTrue(Deletion::query()->count() === 0); $this->assertDatabaseMissing('entities', ['id' => $book->id, 'type' => 'book']); $this->assertDatabaseMissing('entity_container_data', ['entity_id' => $book->id, 'entity_type' => 'book']); $this->assertDatabaseMissing('entities', ['id' => $book->pages->first()->id, 'type' => 'page']); $this->assertDatabaseMissing('entity_page_data', ['page_id' => $book->pages->first()->id]); $this->assertDatabaseMissing('entities', ['id' => $book->chapters->first()->id, 'type' => 'chapter']); $this->assertDatabaseMissing('entity_container_data', ['entity_id' => $book->chapters->first()->id, 'entity_type' => 'chapter']); $itemCount = 1 + $book->pages->count() + $book->chapters->count(); $redirectReq = $this->get('/settings/recycle-bin'); $this->assertNotificationContains($redirectReq, 'Deleted ' . $itemCount . ' total items from the recycle bin'); } public function test_permanent_delete_for_each_type() { foreach ($this->entities->all() as $type => $entity) { $this->asEditor()->delete($entity->getUrl()); $deletion = Deletion::query()->orderBy('id', 'desc')->firstOrFail(); $deleteReq = $this->asAdmin()->delete("/settings/recycle-bin/{$deletion->id}"); $deleteReq->assertRedirect('/settings/recycle-bin'); $this->assertDatabaseMissing('deletions', ['id' => $deletion->id]); $this->assertDatabaseMissing($entity->getTable(), ['id' => $entity->id]); } } public function test_permanent_entity_delete_updates_existing_activity_with_entity_name() { $page = $this->entities->page(); $this->asEditor()->delete($page->getUrl()); $deletion = $page->deletions()->firstOrFail(); $this->assertDatabaseHas('activities', [ 'type' => 'page_delete', 'loggable_id' => $page->id, 'loggable_type' => $page->getMorphClass(), ]); $this->asAdmin()->delete("/settings/recycle-bin/{$deletion->id}"); $this->assertDatabaseMissing('activities', [ 'type' => 'page_delete', 'loggable_id' => $page->id, 'loggable_type' => $page->getMorphClass(), ]); $this->assertDatabaseHas('activities', [ 'type' => 'page_delete', 'loggable_id' => null, 'loggable_type' => null, 'detail' => $page->name, ]); } public function test_permanent_book_delete_removes_shelf_relation_data() { $book = $this->entities->book(); $shelf = $this->entities->shelf(); $shelf->books()->attach($book); $this->assertDatabaseHas('bookshelves_books', ['book_id' => $book->id]); $this->asEditor()->delete($book->getUrl()); $deletion = $book->deletions()->firstOrFail(); $this->asAdmin()->delete("/settings/recycle-bin/{$deletion->id}")->assertRedirect(); $this->assertDatabaseMissing('bookshelves_books', ['book_id' => $book->id]); } public function test_permanent_shelf_delete_removes_book_relation_data() { $book = $this->entities->book(); $shelf = $this->entities->shelf(); $shelf->books()->attach($book); $this->assertDatabaseHas('bookshelves_books', ['bookshelf_id' => $shelf->id]); $this->asEditor()->delete($shelf->getUrl()); $deletion = $shelf->deletions()->firstOrFail(); $this->asAdmin()->delete("/settings/recycle-bin/{$deletion->id}")->assertRedirect(); $this->assertDatabaseMissing('bookshelves_books', ['bookshelf_id' => $shelf->id]); } public function test_auto_clear_functionality_works() { config()->set('app.recycle_bin_lifetime', 5); $page = $this->entities->page(); $otherPage = $this->entities->page(); $this->asEditor()->delete($page->getUrl()); $this->assertDatabaseHasEntityData('page', ['id' => $page->id]); $this->assertEquals(1, Deletion::query()->count()); Carbon::setTestNow(Carbon::now()->addDays(6)); $this->asEditor()->delete($otherPage->getUrl()); $this->assertEquals(1, Deletion::query()->count()); $this->assertDatabaseMissing('entities', ['id' => $page->id, 'type' => 'page']); } public function test_auto_clear_functionality_with_negative_time_keeps_forever() { config()->set('app.recycle_bin_lifetime', -1); $page = $this->entities->page(); $otherPage = $this->entities->page(); $this->asEditor()->delete($page->getUrl()); $this->assertEquals(1, Deletion::query()->count()); Carbon::setTestNow(Carbon::now()->addDays(6000)); $this->asEditor()->delete($otherPage->getUrl()); $this->assertEquals(2, Deletion::query()->count()); $this->assertDatabaseHasEntityData('page', ['id' => $page->id]); } public function test_auto_clear_functionality_with_zero_time_deletes_instantly() { config()->set('app.recycle_bin_lifetime', 0); $page = $this->entities->page(); $this->asEditor()->delete($page->getUrl()); $this->assertDatabaseMissing('entities', ['id' => $page->id, 'type' => 'page']); $this->assertEquals(0, Deletion::query()->count()); } public function test_restore_flow_when_restoring_nested_delete_first() { $book = Book::query()->whereHas('pages')->whereHas('chapters')->with(['pages', 'chapters'])->firstOrFail(); $chapter = $book->chapters->first(); $this->asEditor()->delete($chapter->getUrl()); $this->asEditor()->delete($book->getUrl()); $bookDeletion = $book->deletions()->first(); $chapterDeletion = $chapter->deletions()->first(); $chapterRestoreView = $this->asAdmin()->get("/settings/recycle-bin/{$chapterDeletion->id}/restore"); $chapterRestoreView->assertStatus(200); $chapterRestoreView->assertSeeText($chapter->name); $chapterRestore = $this->post("/settings/recycle-bin/{$chapterDeletion->id}/restore"); $chapterRestore->assertRedirect('/settings/recycle-bin'); $this->assertDatabaseMissing('deletions', ['id' => $chapterDeletion->id]); $chapter->refresh(); $this->assertNotNull($chapter->deleted_at); $bookRestoreView = $this->asAdmin()->get("/settings/recycle-bin/{$bookDeletion->id}/restore"); $bookRestoreView->assertStatus(200); $bookRestoreView->assertSeeText($chapter->name); $this->post("/settings/recycle-bin/{$bookDeletion->id}/restore"); $chapter->refresh(); $this->assertNull($chapter->deleted_at); } public function test_restore_page_shows_link_to_parent_restore_if_parent_also_deleted() { $book = $this->entities->bookHasChaptersAndPages(); $chapter = $book->chapters->first(); /** @var Page $page */ $page = $chapter->pages->first(); $this->asEditor()->delete($page->getUrl()); $this->asEditor()->delete($book->getUrl()); $bookDeletion = $book->deletions()->first(); $pageDeletion = $page->deletions()->first(); $pageRestoreView = $this->asAdmin()->get("/settings/recycle-bin/{$pageDeletion->id}/restore"); $pageRestoreView->assertSee('The parent of this item has also been deleted.'); $this->withHtml($pageRestoreView)->assertElementContains('a[href$="/settings/recycle-bin/' . $bookDeletion->id . '/restore"]', 'Restore Parent'); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Settings/FooterLinksTest.php
tests/Settings/FooterLinksTest.php
<?php namespace Tests\Settings; use Tests\TestCase; class FooterLinksTest extends TestCase { public function test_saving_setting() { $resp = $this->asAdmin()->post('/settings/customization', [ 'setting-app-footer-links' => [ ['label' => 'My custom link 1', 'url' => 'https://example.com/1'], ['label' => 'My custom link 2', 'url' => 'https://example.com/2'], ], ]); $resp->assertRedirect('/settings/customization'); $result = setting('app-footer-links'); $this->assertIsArray($result); $this->assertCount(2, $result); $this->assertEquals('My custom link 2', $result[1]['label']); $this->assertEquals('https://example.com/1', $result[0]['url']); } public function test_set_options_visible_on_settings_page() { $this->setSettings(['app-footer-links' => [ ['label' => 'My custom link', 'url' => 'https://example.com/link-a'], ['label' => 'Another Link', 'url' => 'https://example.com/link-b'], ]]); $resp = $this->asAdmin()->get('/settings/customization'); $resp->assertSee('value="My custom link"', false); $resp->assertSee('value="Another Link"', false); $resp->assertSee('value="https://example.com/link-a"', false); $resp->assertSee('value="https://example.com/link-b"', false); } public function test_footer_links_show_on_pages() { $this->setSettings(['app-footer-links' => [ ['label' => 'My custom link', 'url' => 'https://example.com/link-a'], ['label' => 'Another Link', 'url' => 'https://example.com/link-b'], ]]); $resp = $this->get('/login'); $this->withHtml($resp)->assertElementContains('footer a[href="https://example.com/link-a"]', 'My custom link'); $resp = $this->asEditor()->get('/'); $this->withHtml($resp)->assertElementContains('footer a[href="https://example.com/link-b"]', 'Another link'); } public function test_using_translation_system_for_labels() { $this->setSettings(['app-footer-links' => [ ['label' => 'trans::common.privacy_policy', 'url' => 'https://example.com/privacy'], ['label' => 'trans::common.terms_of_service', 'url' => 'https://example.com/terms'], ]]); $resp = $this->get('/login'); $this->withHtml($resp)->assertElementContains('footer a[href="https://example.com/privacy"]', 'Privacy Policy'); $this->withHtml($resp)->assertElementContains('footer a[href="https://example.com/terms"]', 'Terms of Service'); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/tests/Settings/SettingsTest.php
tests/Settings/SettingsTest.php
<?php namespace Tests\Settings; use Tests\TestCase; class SettingsTest extends TestCase { public function test_admin_can_see_settings() { $this->asAdmin()->get('/settings/features')->assertSee('Settings'); } public function test_settings_endpoint_redirects_to_settings_view() { $resp = $this->asAdmin()->get('/settings'); $resp->assertStatus(302); // Manually check path to ensure it's generated as the full path $location = $resp->headers->get('location'); $this->assertEquals(url('/settings/features'), $location); } public function test_settings_category_links_work_as_expected() { $this->asAdmin(); $categories = [ 'features' => 'Features & Security', 'customization' => 'Customization', 'registration' => 'Registration', ]; foreach ($categories as $category => $title) { $resp = $this->get("/settings/{$category}"); $this->withHtml($resp)->assertElementContains('h1', $title); $this->withHtml($resp)->assertElementExists("form[action$=\"/settings/{$category}\"]"); } } public function test_not_found_setting_category_throws_404() { $resp = $this->asAdmin()->get('/settings/biscuits'); $resp->assertStatus(404); $resp->assertSee('Page Not Found'); } public function test_updating_and_removing_app_icon() { $this->asAdmin(); $galleryFile = $this->files->uploadedImage('my-app-icon.png'); $expectedPath = public_path('uploads/images/system/' . date('Y-m') . '/my-app-icon.png'); $this->assertFalse(setting()->get('app-icon')); $this->assertFalse(setting()->get('app-icon-180')); $this->assertFalse(setting()->get('app-icon-128')); $this->assertFalse(setting()->get('app-icon-64')); $this->assertFalse(setting()->get('app-icon-32')); $this->assertEquals( file_get_contents(public_path('icon.ico')), file_get_contents(public_path('favicon.ico')), ); $prevFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png')); $upload = $this->call('POST', '/settings/customization', [], [], ['app_icon' => $galleryFile], []); $upload->assertRedirect('/settings/customization'); $this->assertTrue(file_exists($expectedPath), 'Uploaded image not found at path: ' . $expectedPath); $this->assertStringContainsString('my-app-icon', setting()->get('app-icon')); $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-180')); $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-128')); $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-64')); $this->assertStringContainsString('my-app-icon', setting()->get('app-icon-32')); $newFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png')); $this->assertEquals(5, $newFileCount - $prevFileCount); $resp = $this->get('/'); $this->withHtml($resp)->assertElementCount('link[sizes][href*="my-app-icon"]', 6); $this->assertNotEquals( file_get_contents(public_path('icon.ico')), file_get_contents(public_path('favicon.ico')), ); $reset = $this->post('/settings/customization', ['app_icon_reset' => 'true']); $reset->assertRedirect('/settings/customization'); $resetFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png')); $this->assertEquals($prevFileCount, $resetFileCount); $this->assertFalse(setting()->get('app-icon')); $this->assertFalse(setting()->get('app-icon-180')); $this->assertFalse(setting()->get('app-icon-128')); $this->assertFalse(setting()->get('app-icon-64')); $this->assertFalse(setting()->get('app-icon-32')); $this->assertEquals( file_get_contents(public_path('icon.ico')), file_get_contents(public_path('favicon.ico')), ); } public function test_both_light_and_dark_colors_are_used_in_the_base_view() { // To allow for dynamic color changes on the front-end where desired. $this->setSettings(['page-color' => 'superlightblue', 'page-color-dark' => 'superdarkblue']); $resp = $this->get('/login'); $resp->assertSee(':root {'); $resp->assertSee('superlightblue'); $resp->assertSee(':root.dark-mode {'); $resp->assertSee('superdarkblue'); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/routes/web.php
routes/web.php
<?php use BookStack\Access\Controllers as AccessControllers; use BookStack\Activity\Controllers as ActivityControllers; use BookStack\Api\ApiDocsController; use BookStack\Api\UserApiTokenController; use BookStack\App\HomeController; use BookStack\App\MetaController; use BookStack\Entities\Controllers as EntityControllers; use BookStack\Exports\Controllers as ExportControllers; use BookStack\Http\Middleware\VerifyCsrfToken; use BookStack\Permissions\PermissionsController; use BookStack\References\ReferenceController; use BookStack\Search\SearchController; use BookStack\Settings as SettingControllers; use BookStack\Sorting as SortingControllers; use BookStack\Theming\ThemeController; use BookStack\Uploads\Controllers as UploadControllers; use BookStack\Users\Controllers as UserControllers; use Illuminate\Session\Middleware\StartSession; use Illuminate\Support\Facades\Route; use Illuminate\View\Middleware\ShareErrorsFromSession; // Status & Meta routes Route::get('/status', [SettingControllers\StatusController::class, 'show']); Route::get('/robots.txt', [MetaController::class, 'robots']); Route::get('/favicon.ico', [MetaController::class, 'favicon']); Route::get('/manifest.json', [MetaController::class, 'pwaManifest']); Route::get('/licenses', [MetaController::class, 'licenses']); Route::get('/opensearch.xml', [MetaController::class, 'opensearch']); // Authenticated routes... Route::middleware('auth')->group(function () { // Secure images routing Route::get('/uploads/images/{path}', [UploadControllers\ImageController::class, 'showImage']) ->where('path', '.*$'); // API docs routes Route::get('/api', [ApiDocsController::class, 'redirect']); Route::get('/api/docs', [ApiDocsController::class, 'display']); Route::get('/pages/recently-updated', [EntityControllers\PageController::class, 'showRecentlyUpdated']); // Shelves Route::get('/create-shelf', [EntityControllers\BookshelfController::class, 'create']); Route::get('/shelves/', [EntityControllers\BookshelfController::class, 'index']); Route::post('/shelves/', [EntityControllers\BookshelfController::class, 'store']); Route::get('/shelves/{slug}/edit', [EntityControllers\BookshelfController::class, 'edit']); Route::get('/shelves/{slug}/delete', [EntityControllers\BookshelfController::class, 'showDelete']); Route::get('/shelves/{slug}', [EntityControllers\BookshelfController::class, 'show']); Route::put('/shelves/{slug}', [EntityControllers\BookshelfController::class, 'update']); Route::delete('/shelves/{slug}', [EntityControllers\BookshelfController::class, 'destroy']); Route::get('/shelves/{slug}/permissions', [PermissionsController::class, 'showForShelf']); Route::put('/shelves/{slug}/permissions', [PermissionsController::class, 'updateForShelf']); Route::post('/shelves/{slug}/copy-permissions', [PermissionsController::class, 'copyShelfPermissionsToBooks']); Route::get('/shelves/{slug}/references', [ReferenceController::class, 'shelf']); // Book Creation Route::get('/shelves/{shelfSlug}/create-book', [EntityControllers\BookController::class, 'create']); Route::post('/shelves/{shelfSlug}/create-book', [EntityControllers\BookController::class, 'store']); Route::get('/create-book', [EntityControllers\BookController::class, 'create']); // Books Route::get('/books/', [EntityControllers\BookController::class, 'index']); Route::post('/books/', [EntityControllers\BookController::class, 'store']); Route::get('/books/{slug}/edit', [EntityControllers\BookController::class, 'edit']); Route::put('/books/{slug}', [EntityControllers\BookController::class, 'update']); Route::delete('/books/{id}', [EntityControllers\BookController::class, 'destroy']); Route::get('/books/{slug}/sort-item', [SortingControllers\BookSortController::class, 'showItem']); Route::get('/books/{slug}', [EntityControllers\BookController::class, 'show']); Route::get('/books/{bookSlug}/permissions', [PermissionsController::class, 'showForBook']); Route::put('/books/{bookSlug}/permissions', [PermissionsController::class, 'updateForBook']); Route::get('/books/{slug}/delete', [EntityControllers\BookController::class, 'showDelete']); Route::get('/books/{bookSlug}/copy', [EntityControllers\BookController::class, 'showCopy']); Route::post('/books/{bookSlug}/copy', [EntityControllers\BookController::class, 'copy']); Route::post('/books/{bookSlug}/convert-to-shelf', [EntityControllers\BookController::class, 'convertToShelf']); Route::get('/books/{bookSlug}/sort', [SortingControllers\BookSortController::class, 'show']); Route::put('/books/{bookSlug}/sort', [SortingControllers\BookSortController::class, 'update']); Route::get('/books/{slug}/references', [ReferenceController::class, 'book']); Route::get('/books/{bookSlug}/export/html', [ExportControllers\BookExportController::class, 'html']); Route::get('/books/{bookSlug}/export/pdf', [ExportControllers\BookExportController::class, 'pdf']); Route::get('/books/{bookSlug}/export/markdown', [ExportControllers\BookExportController::class, 'markdown']); Route::get('/books/{bookSlug}/export/zip', [ExportControllers\BookExportController::class, 'zip']); Route::get('/books/{bookSlug}/export/plaintext', [ExportControllers\BookExportController::class, 'plainText']); // Pages Route::get('/books/{bookSlug}/create-page', [EntityControllers\PageController::class, 'create']); Route::post('/books/{bookSlug}/create-guest-page', [EntityControllers\PageController::class, 'createAsGuest']); Route::get('/books/{bookSlug}/draft/{pageId}', [EntityControllers\PageController::class, 'editDraft']); Route::post('/books/{bookSlug}/draft/{pageId}', [EntityControllers\PageController::class, 'store']); Route::get('/books/{bookSlug}/page/{pageSlug}', [EntityControllers\PageController::class, 'show']); Route::get('/books/{bookSlug}/page/{pageSlug}/export/pdf', [ExportControllers\PageExportController::class, 'pdf']); Route::get('/books/{bookSlug}/page/{pageSlug}/export/html', [ExportControllers\PageExportController::class, 'html']); Route::get('/books/{bookSlug}/page/{pageSlug}/export/markdown', [ExportControllers\PageExportController::class, 'markdown']); Route::get('/books/{bookSlug}/page/{pageSlug}/export/plaintext', [ExportControllers\PageExportController::class, 'plainText']); Route::get('/books/{bookSlug}/page/{pageSlug}/export/zip', [ExportControllers\PageExportController::class, 'zip']); Route::get('/books/{bookSlug}/page/{pageSlug}/edit', [EntityControllers\PageController::class, 'edit']); Route::get('/books/{bookSlug}/page/{pageSlug}/move', [EntityControllers\PageController::class, 'showMove']); Route::put('/books/{bookSlug}/page/{pageSlug}/move', [EntityControllers\PageController::class, 'move']); Route::get('/books/{bookSlug}/page/{pageSlug}/copy', [EntityControllers\PageController::class, 'showCopy']); Route::post('/books/{bookSlug}/page/{pageSlug}/copy', [EntityControllers\PageController::class, 'copy']); Route::get('/books/{bookSlug}/page/{pageSlug}/delete', [EntityControllers\PageController::class, 'showDelete']); Route::get('/books/{bookSlug}/draft/{pageId}/delete', [EntityControllers\PageController::class, 'showDeleteDraft']); Route::get('/books/{bookSlug}/page/{pageSlug}/permissions', [PermissionsController::class, 'showForPage']); Route::put('/books/{bookSlug}/page/{pageSlug}/permissions', [PermissionsController::class, 'updateForPage']); Route::get('/books/{bookSlug}/page/{pageSlug}/references', [ReferenceController::class, 'page']); Route::put('/books/{bookSlug}/page/{pageSlug}', [EntityControllers\PageController::class, 'update']); Route::delete('/books/{bookSlug}/page/{pageSlug}', [EntityControllers\PageController::class, 'destroy']); Route::delete('/books/{bookSlug}/draft/{pageId}', [EntityControllers\PageController::class, 'destroyDraft']); // Revisions Route::get('/books/{bookSlug}/page/{pageSlug}/revisions', [EntityControllers\PageRevisionController::class, 'index']); Route::get('/books/{bookSlug}/page/{pageSlug}/revisions/{revId}', [EntityControllers\PageRevisionController::class, 'show']); Route::get('/books/{bookSlug}/page/{pageSlug}/revisions/{revId}/changes', [EntityControllers\PageRevisionController::class, 'changes']); Route::put('/books/{bookSlug}/page/{pageSlug}/revisions/{revId}/restore', [EntityControllers\PageRevisionController::class, 'restore']); Route::delete('/books/{bookSlug}/page/{pageSlug}/revisions/{revId}/delete', [EntityControllers\PageRevisionController::class, 'destroy']); Route::delete('/page-revisions/user-drafts/{pageId}', [EntityControllers\PageRevisionController::class, 'destroyUserDraft']); // Chapters Route::get('/books/{bookSlug}/chapter/{chapterSlug}/create-page', [EntityControllers\PageController::class, 'create']); Route::post('/books/{bookSlug}/chapter/{chapterSlug}/create-guest-page', [EntityControllers\PageController::class, 'createAsGuest']); Route::get('/books/{bookSlug}/create-chapter', [EntityControllers\ChapterController::class, 'create']); Route::post('/books/{bookSlug}/create-chapter', [EntityControllers\ChapterController::class, 'store']); Route::get('/books/{bookSlug}/chapter/{chapterSlug}', [EntityControllers\ChapterController::class, 'show']); Route::put('/books/{bookSlug}/chapter/{chapterSlug}', [EntityControllers\ChapterController::class, 'update']); Route::get('/books/{bookSlug}/chapter/{chapterSlug}/move', [EntityControllers\ChapterController::class, 'showMove']); Route::put('/books/{bookSlug}/chapter/{chapterSlug}/move', [EntityControllers\ChapterController::class, 'move']); Route::get('/books/{bookSlug}/chapter/{chapterSlug}/copy', [EntityControllers\ChapterController::class, 'showCopy']); Route::post('/books/{bookSlug}/chapter/{chapterSlug}/copy', [EntityControllers\ChapterController::class, 'copy']); Route::get('/books/{bookSlug}/chapter/{chapterSlug}/edit', [EntityControllers\ChapterController::class, 'edit']); Route::post('/books/{bookSlug}/chapter/{chapterSlug}/convert-to-book', [EntityControllers\ChapterController::class, 'convertToBook']); Route::get('/books/{bookSlug}/chapter/{chapterSlug}/permissions', [PermissionsController::class, 'showForChapter']); Route::get('/books/{bookSlug}/chapter/{chapterSlug}/export/pdf', [ExportControllers\ChapterExportController::class, 'pdf']); Route::get('/books/{bookSlug}/chapter/{chapterSlug}/export/html', [ExportControllers\ChapterExportController::class, 'html']); Route::get('/books/{bookSlug}/chapter/{chapterSlug}/export/markdown', [ExportControllers\ChapterExportController::class, 'markdown']); Route::get('/books/{bookSlug}/chapter/{chapterSlug}/export/plaintext', [ExportControllers\ChapterExportController::class, 'plainText']); Route::get('/books/{bookSlug}/chapter/{chapterSlug}/export/zip', [ExportControllers\ChapterExportController::class, 'zip']); Route::put('/books/{bookSlug}/chapter/{chapterSlug}/permissions', [PermissionsController::class, 'updateForChapter']); Route::get('/books/{bookSlug}/chapter/{chapterSlug}/references', [ReferenceController::class, 'chapter']); Route::get('/books/{bookSlug}/chapter/{chapterSlug}/delete', [EntityControllers\ChapterController::class, 'showDelete']); Route::delete('/books/{bookSlug}/chapter/{chapterSlug}', [EntityControllers\ChapterController::class, 'destroy']); // User Profile routes Route::get('/user/{slug}', [UserControllers\UserProfileController::class, 'show']); // Image routes Route::get('/images/gallery', [UploadControllers\GalleryImageController::class, 'list']); Route::post('/images/gallery', [UploadControllers\GalleryImageController::class, 'create']); Route::get('/images/drawio', [UploadControllers\DrawioImageController::class, 'list']); Route::get('/images/drawio/base64/{id}', [UploadControllers\DrawioImageController::class, 'getAsBase64']); Route::post('/images/drawio', [UploadControllers\DrawioImageController::class, 'create']); Route::get('/images/edit/{id}', [UploadControllers\ImageController::class, 'edit']); Route::put('/images/{id}/file', [UploadControllers\ImageController::class, 'updateFile']); Route::put('/images/{id}/rebuild-thumbnails', [UploadControllers\ImageController::class, 'rebuildThumbnails']); Route::put('/images/{id}', [UploadControllers\ImageController::class, 'update']); Route::delete('/images/{id}', [UploadControllers\ImageController::class, 'destroy']); // Attachments routes Route::get('/attachments/{id}', [UploadControllers\AttachmentController::class, 'get']); Route::post('/attachments/upload', [UploadControllers\AttachmentController::class, 'upload']); Route::post('/attachments/upload/{id}', [UploadControllers\AttachmentController::class, 'uploadUpdate']); Route::post('/attachments/link', [UploadControllers\AttachmentController::class, 'attachLink']); Route::put('/attachments/{id}', [UploadControllers\AttachmentController::class, 'update']); Route::get('/attachments/edit/{id}', [UploadControllers\AttachmentController::class, 'getUpdateForm']); Route::get('/attachments/get/page/{pageId}', [UploadControllers\AttachmentController::class, 'listForPage']); Route::put('/attachments/sort/page/{pageId}', [UploadControllers\AttachmentController::class, 'sortForPage']); Route::delete('/attachments/{id}', [UploadControllers\AttachmentController::class, 'delete']); // AJAX routes Route::put('/ajax/page/{id}/save-draft', [EntityControllers\PageController::class, 'saveDraft']); Route::get('/ajax/page/{id}', [EntityControllers\PageController::class, 'getPageAjax']); Route::delete('/ajax/page/{id}', [EntityControllers\PageController::class, 'ajaxDestroy']); // Tag routes Route::get('/tags', [ActivityControllers\TagController::class, 'index']); Route::get('/ajax/tags/suggest/names', [ActivityControllers\TagController::class, 'getNameSuggestions']); Route::get('/ajax/tags/suggest/values', [ActivityControllers\TagController::class, 'getValueSuggestions']); // Comments Route::post('/comment/{pageId}', [ActivityControllers\CommentController::class, 'savePageComment']); Route::put('/comment/{id}/archive', [ActivityControllers\CommentController::class, 'archive']); Route::put('/comment/{id}/unarchive', [ActivityControllers\CommentController::class, 'unarchive']); Route::put('/comment/{id}', [ActivityControllers\CommentController::class, 'update']); Route::delete('/comment/{id}', [ActivityControllers\CommentController::class, 'destroy']); // Links Route::get('/link/{id}', [EntityControllers\PageController::class, 'redirectFromLink']); // Search Route::get('/search', [SearchController::class, 'search']); Route::get('/search/book/{bookId}', [SearchController::class, 'searchBook']); Route::get('/search/chapter/{bookId}', [SearchController::class, 'searchChapter']); Route::get('/search/entity/siblings', [SearchController::class, 'searchSiblings']); Route::get('/search/entity-selector', [SearchController::class, 'searchForSelector']); Route::get('/search/entity-selector-templates', [SearchController::class, 'templatesForSelector']); Route::get('/search/suggest', [SearchController::class, 'searchSuggestions']); // User Search Route::get('/search/users/select', [UserControllers\UserSearchController::class, 'forSelect']); Route::get('/search/users/mention', [UserControllers\UserSearchController::class, 'forMentions']); // Template System Route::get('/templates', [EntityControllers\PageTemplateController::class, 'list']); Route::get('/templates/{templateId}', [EntityControllers\PageTemplateController::class, 'get']); // Favourites Route::get('/favourites', [ActivityControllers\FavouriteController::class, 'index']); Route::post('/favourites/add', [ActivityControllers\FavouriteController::class, 'add']); Route::post('/favourites/remove', [ActivityControllers\FavouriteController::class, 'remove']); // Watching Route::put('/watching/update', [ActivityControllers\WatchController::class, 'update']); // Importing Route::get('/import', [ExportControllers\ImportController::class, 'start']); Route::post('/import', [ExportControllers\ImportController::class, 'upload']); Route::get('/import/{id}', [ExportControllers\ImportController::class, 'show']); Route::post('/import/{id}', [ExportControllers\ImportController::class, 'run']); Route::delete('/import/{id}', [ExportControllers\ImportController::class, 'delete']); // Other Pages Route::get('/', [HomeController::class, 'index']); Route::get('/home', [HomeController::class, 'index']); // Permissions Route::get('/permissions/form-row/{entityType}/{roleId}', [PermissionsController::class, 'formRowForRole']); // Maintenance Route::get('/settings/maintenance', [SettingControllers\MaintenanceController::class, 'index']); Route::delete('/settings/maintenance/cleanup-images', [SettingControllers\MaintenanceController::class, 'cleanupImages']); Route::post('/settings/maintenance/send-test-email', [SettingControllers\MaintenanceController::class, 'sendTestEmail']); Route::post('/settings/maintenance/regenerate-references', [SettingControllers\MaintenanceController::class, 'regenerateReferences']); // Recycle Bin Route::get('/settings/recycle-bin', [EntityControllers\RecycleBinController::class, 'index']); Route::post('/settings/recycle-bin/empty', [EntityControllers\RecycleBinController::class, 'empty']); Route::get('/settings/recycle-bin/{id}/destroy', [EntityControllers\RecycleBinController::class, 'showDestroy']); Route::delete('/settings/recycle-bin/{id}', [EntityControllers\RecycleBinController::class, 'destroy']); Route::get('/settings/recycle-bin/{id}/restore', [EntityControllers\RecycleBinController::class, 'showRestore']); Route::post('/settings/recycle-bin/{id}/restore', [EntityControllers\RecycleBinController::class, 'restore']); // Audit Log Route::get('/settings/audit', [ActivityControllers\AuditLogController::class, 'index']); // Users Route::get('/settings/users', [UserControllers\UserController::class, 'index']); Route::get('/settings/users/create', [UserControllers\UserController::class, 'create']); Route::get('/settings/users/{id}/delete', [UserControllers\UserController::class, 'delete']); Route::post('/settings/users/create', [UserControllers\UserController::class, 'store']); Route::get('/settings/users/{id}', [UserControllers\UserController::class, 'edit']); Route::put('/settings/users/{id}', [UserControllers\UserController::class, 'update']); Route::delete('/settings/users/{id}', [UserControllers\UserController::class, 'destroy']); // User Account Route::get('/my-account', [UserControllers\UserAccountController::class, 'redirect']); Route::get('/my-account/profile', [UserControllers\UserAccountController::class, 'showProfile']); Route::put('/my-account/profile', [UserControllers\UserAccountController::class, 'updateProfile']); Route::get('/my-account/shortcuts', [UserControllers\UserAccountController::class, 'showShortcuts']); Route::put('/my-account/shortcuts', [UserControllers\UserAccountController::class, 'updateShortcuts']); Route::get('/my-account/notifications', [UserControllers\UserAccountController::class, 'showNotifications']); Route::put('/my-account/notifications', [UserControllers\UserAccountController::class, 'updateNotifications']); Route::get('/my-account/auth', [UserControllers\UserAccountController::class, 'showAuth']); Route::put('/my-account/auth/password', [UserControllers\UserAccountController::class, 'updatePassword']); Route::get('/my-account/delete', [UserControllers\UserAccountController::class, 'delete']); Route::delete('/my-account', [UserControllers\UserAccountController::class, 'destroy']); // User Preference Endpoints Route::patch('/preferences/change-view/{type}', [UserControllers\UserPreferencesController::class, 'changeView']); Route::patch('/preferences/change-sort/{type}', [UserControllers\UserPreferencesController::class, 'changeSort']); Route::patch('/preferences/change-expansion/{type}', [UserControllers\UserPreferencesController::class, 'changeExpansion']); Route::patch('/preferences/toggle-dark-mode', [UserControllers\UserPreferencesController::class, 'toggleDarkMode']); Route::patch('/preferences/update-code-language-favourite', [UserControllers\UserPreferencesController::class, 'updateCodeLanguageFavourite']); // User API Tokens Route::get('/api-tokens/{userId}/create', [UserApiTokenController::class, 'create']); Route::post('/api-tokens/{userId}/create', [UserApiTokenController::class, 'store']); Route::get('/api-tokens/{userId}/{tokenId}', [UserApiTokenController::class, 'edit']); Route::put('/api-tokens/{userId}/{tokenId}', [UserApiTokenController::class, 'update']); Route::get('/api-tokens/{userId}/{tokenId}/delete', [UserApiTokenController::class, 'delete']); Route::delete('/api-tokens/{userId}/{tokenId}', [UserApiTokenController::class, 'destroy']); // Roles Route::get('/settings/roles', [UserControllers\RoleController::class, 'index']); Route::get('/settings/roles/new', [UserControllers\RoleController::class, 'create']); Route::post('/settings/roles/new', [UserControllers\RoleController::class, 'store']); Route::get('/settings/roles/delete/{id}', [UserControllers\RoleController::class, 'showDelete']); Route::delete('/settings/roles/delete/{id}', [UserControllers\RoleController::class, 'delete']); Route::get('/settings/roles/{id}', [UserControllers\RoleController::class, 'edit']); Route::put('/settings/roles/{id}', [UserControllers\RoleController::class, 'update']); // Webhooks Route::get('/settings/webhooks', [ActivityControllers\WebhookController::class, 'index']); Route::get('/settings/webhooks/create', [ActivityControllers\WebhookController::class, 'create']); Route::post('/settings/webhooks/create', [ActivityControllers\WebhookController::class, 'store']); Route::get('/settings/webhooks/{id}', [ActivityControllers\WebhookController::class, 'edit']); Route::put('/settings/webhooks/{id}', [ActivityControllers\WebhookController::class, 'update']); Route::get('/settings/webhooks/{id}/delete', [ActivityControllers\WebhookController::class, 'delete']); Route::delete('/settings/webhooks/{id}', [ActivityControllers\WebhookController::class, 'destroy']); // Sort Rules Route::get('/settings/sorting/rules/new', [SortingControllers\SortRuleController::class, 'create']); Route::post('/settings/sorting/rules', [SortingControllers\SortRuleController::class, 'store']); Route::get('/settings/sorting/rules/{id}', [SortingControllers\SortRuleController::class, 'edit']); Route::put('/settings/sorting/rules/{id}', [SortingControllers\SortRuleController::class, 'update']); Route::delete('/settings/sorting/rules/{id}', [SortingControllers\SortRuleController::class, 'destroy']); // Settings Route::get('/settings', [SettingControllers\SettingController::class, 'index'])->name('settings'); Route::get('/settings/{category}', [SettingControllers\SettingController::class, 'category'])->name('settings.category'); Route::post('/settings/{category}', [SettingControllers\SettingController::class, 'update']); }); // MFA routes Route::middleware('mfa-setup')->group(function () { Route::get('/mfa/setup', [AccessControllers\MfaController::class, 'setup']); Route::get('/mfa/totp/generate', [AccessControllers\MfaTotpController::class, 'generate']); Route::post('/mfa/totp/confirm', [AccessControllers\MfaTotpController::class, 'confirm']); Route::get('/mfa/backup_codes/generate', [AccessControllers\MfaBackupCodesController::class, 'generate']); Route::post('/mfa/backup_codes/confirm', [AccessControllers\MfaBackupCodesController::class, 'confirm']); }); Route::middleware('guest')->group(function () { Route::get('/mfa/verify', [AccessControllers\MfaController::class, 'verify']); Route::post('/mfa/totp/verify', [AccessControllers\MfaTotpController::class, 'verify']); Route::post('/mfa/backup_codes/verify', [AccessControllers\MfaBackupCodesController::class, 'verify']); }); Route::delete('/mfa/{method}/remove', [AccessControllers\MfaController::class, 'remove'])->middleware('auth'); // Social auth routes Route::get('/login/service/{socialDriver}', [AccessControllers\SocialController::class, 'login']); Route::get('/login/service/{socialDriver}/callback', [AccessControllers\SocialController::class, 'callback']); Route::post('/login/service/{socialDriver}/detach', [AccessControllers\SocialController::class, 'detach'])->middleware('auth'); Route::get('/register/service/{socialDriver}', [AccessControllers\SocialController::class, 'register']); // Login/Logout routes Route::get('/login', [AccessControllers\LoginController::class, 'getLogin']); Route::post('/login', [AccessControllers\LoginController::class, 'login']); Route::post('/logout', [AccessControllers\LoginController::class, 'logout']); Route::get('/register', [AccessControllers\RegisterController::class, 'getRegister']); Route::get('/register/confirm', [AccessControllers\ConfirmEmailController::class, 'show']); Route::get('/register/confirm/awaiting', [AccessControllers\ConfirmEmailController::class, 'showAwaiting']); Route::post('/register/confirm/resend', [AccessControllers\ConfirmEmailController::class, 'resend']); Route::get('/register/confirm/{token}', [AccessControllers\ConfirmEmailController::class, 'showAcceptForm']); Route::post('/register/confirm/accept', [AccessControllers\ConfirmEmailController::class, 'confirm'])->middleware('throttle:public'); Route::post('/register', [AccessControllers\RegisterController::class, 'postRegister'])->middleware('throttle:public'); // SAML routes Route::post('/saml2/login', [AccessControllers\Saml2Controller::class, 'login']); Route::post('/saml2/logout', [AccessControllers\Saml2Controller::class, 'logout']); Route::get('/saml2/metadata', [AccessControllers\Saml2Controller::class, 'metadata']); Route::get('/saml2/sls', [AccessControllers\Saml2Controller::class, 'sls']); Route::post('/saml2/acs', [AccessControllers\Saml2Controller::class, 'startAcs'])->withoutMiddleware([ StartSession::class, ShareErrorsFromSession::class, VerifyCsrfToken::class, ]); Route::get('/saml2/acs', [AccessControllers\Saml2Controller::class, 'processAcs']); // OIDC routes Route::post('/oidc/login', [AccessControllers\OidcController::class, 'login']); Route::get('/oidc/callback', [AccessControllers\OidcController::class, 'callback']); Route::post('/oidc/logout', [AccessControllers\OidcController::class, 'logout']); // User invitation routes Route::get('/register/invite/{token}', [AccessControllers\UserInviteController::class, 'showSetPassword'])->middleware('throttle:public'); Route::post('/register/invite/{token}', [AccessControllers\UserInviteController::class, 'setPassword'])->middleware('throttle:public'); // Password reset link request routes Route::get('/password/email', [AccessControllers\ForgotPasswordController::class, 'showLinkRequestForm']); Route::post('/password/email', [AccessControllers\ForgotPasswordController::class, 'sendResetLinkEmail'])->middleware('throttle:public'); // Password reset routes Route::get('/password/reset/{token}', [AccessControllers\ResetPasswordController::class, 'showResetForm']); Route::post('/password/reset', [AccessControllers\ResetPasswordController::class, 'reset'])->middleware('throttle:public'); // Help & Info routes Route::view('/help/tinymce', 'help.tinymce'); Route::view('/help/wysiwyg', 'help.wysiwyg'); // Theme Routes Route::get('/theme/{theme}/{path}', [ThemeController::class, 'publicFile']) ->where('path', '.*$'); Route::fallback([MetaController::class, 'notFound'])->name('fallback');
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/routes/api.php
routes/api.php
<?php /** * Routes for the BookStack API. * Routes have a URI prefix of /api/. * Controllers all end with "ApiController" */ use BookStack\Activity\Controllers as ActivityControllers; use BookStack\Api\ApiDocsController; use BookStack\App\SystemApiController; use BookStack\Entities\Controllers as EntityControllers; use BookStack\Exports\Controllers as ExportControllers; use BookStack\Permissions\ContentPermissionApiController; use BookStack\Search\SearchApiController; use BookStack\Uploads\Controllers\AttachmentApiController; use BookStack\Uploads\Controllers\ImageGalleryApiController; use BookStack\Users\Controllers\RoleApiController; use BookStack\Users\Controllers\UserApiController; use Illuminate\Support\Facades\Route; // Main Entity Routes Route::get('pages', [EntityControllers\PageApiController::class, 'list']); Route::post('pages', [EntityControllers\PageApiController::class, 'create']); Route::get('pages/{id}', [EntityControllers\PageApiController::class, 'read']); Route::put('pages/{id}', [EntityControllers\PageApiController::class, 'update']); Route::delete('pages/{id}', [EntityControllers\PageApiController::class, 'delete']); Route::get('pages/{id}/export/html', [ExportControllers\PageExportApiController::class, 'exportHtml']); Route::get('pages/{id}/export/pdf', [ExportControllers\PageExportApiController::class, 'exportPdf']); Route::get('pages/{id}/export/plaintext', [ExportControllers\PageExportApiController::class, 'exportPlainText']); Route::get('pages/{id}/export/markdown', [ExportControllers\PageExportApiController::class, 'exportMarkdown']); Route::get('pages/{id}/export/zip', [ExportControllers\PageExportApiController::class, 'exportZip']); Route::get('chapters', [EntityControllers\ChapterApiController::class, 'list']); Route::post('chapters', [EntityControllers\ChapterApiController::class, 'create']); Route::get('chapters/{id}', [EntityControllers\ChapterApiController::class, 'read']); Route::put('chapters/{id}', [EntityControllers\ChapterApiController::class, 'update']); Route::delete('chapters/{id}', [EntityControllers\ChapterApiController::class, 'delete']); Route::get('chapters/{id}/export/html', [ExportControllers\ChapterExportApiController::class, 'exportHtml']); Route::get('chapters/{id}/export/pdf', [ExportControllers\ChapterExportApiController::class, 'exportPdf']); Route::get('chapters/{id}/export/plaintext', [ExportControllers\ChapterExportApiController::class, 'exportPlainText']); Route::get('chapters/{id}/export/markdown', [ExportControllers\ChapterExportApiController::class, 'exportMarkdown']); Route::get('chapters/{id}/export/zip', [ExportControllers\ChapterExportApiController::class, 'exportZip']); Route::get('books', [EntityControllers\BookApiController::class, 'list']); Route::post('books', [EntityControllers\BookApiController::class, 'create']); Route::get('books/{id}', [EntityControllers\BookApiController::class, 'read']); Route::put('books/{id}', [EntityControllers\BookApiController::class, 'update']); Route::delete('books/{id}', [EntityControllers\BookApiController::class, 'delete']); Route::get('books/{id}/export/html', [ExportControllers\BookExportApiController::class, 'exportHtml']); Route::get('books/{id}/export/pdf', [ExportControllers\BookExportApiController::class, 'exportPdf']); Route::get('books/{id}/export/plaintext', [ExportControllers\BookExportApiController::class, 'exportPlainText']); Route::get('books/{id}/export/markdown', [ExportControllers\BookExportApiController::class, 'exportMarkdown']); Route::get('books/{id}/export/zip', [ExportControllers\BookExportApiController::class, 'exportZip']); Route::get('shelves', [EntityControllers\BookshelfApiController::class, 'list']); Route::post('shelves', [EntityControllers\BookshelfApiController::class, 'create']); Route::get('shelves/{id}', [EntityControllers\BookshelfApiController::class, 'read']); Route::put('shelves/{id}', [EntityControllers\BookshelfApiController::class, 'update']); Route::delete('shelves/{id}', [EntityControllers\BookshelfApiController::class, 'delete']); // Additional Model Routes, in alphabetical order Route::get('attachments', [AttachmentApiController::class, 'list']); Route::post('attachments', [AttachmentApiController::class, 'create']); Route::get('attachments/{id}', [AttachmentApiController::class, 'read']); Route::put('attachments/{id}', [AttachmentApiController::class, 'update']); Route::delete('attachments/{id}', [AttachmentApiController::class, 'delete']); Route::get('audit-log', [ActivityControllers\AuditLogApiController::class, 'list']); Route::get('comments', [ActivityControllers\CommentApiController::class, 'list']); Route::post('comments', [ActivityControllers\CommentApiController::class, 'create']); Route::get('comments/{id}', [ActivityControllers\CommentApiController::class, 'read']); Route::put('comments/{id}', [ActivityControllers\CommentApiController::class, 'update']); Route::delete('comments/{id}', [ActivityControllers\CommentApiController::class, 'delete']); Route::get('content-permissions/{contentType}/{contentId}', [ContentPermissionApiController::class, 'read']); Route::put('content-permissions/{contentType}/{contentId}', [ContentPermissionApiController::class, 'update']); Route::get('docs.json', [ApiDocsController::class, 'json']); Route::get('image-gallery', [ImageGalleryApiController::class, 'list']); Route::post('image-gallery', [ImageGalleryApiController::class, 'create']); Route::get('image-gallery/url/data', [ImageGalleryApiController::class, 'readDataForUrl']); Route::get('image-gallery/{id}', [ImageGalleryApiController::class, 'read']); Route::get('image-gallery/{id}/data', [ImageGalleryApiController::class, 'readData']); Route::put('image-gallery/{id}', [ImageGalleryApiController::class, 'update']); Route::delete('image-gallery/{id}', [ImageGalleryApiController::class, 'delete']); Route::get('imports', [ExportControllers\ImportApiController::class, 'list']); Route::post('imports', [ExportControllers\ImportApiController::class, 'create']); Route::get('imports/{id}', [ExportControllers\ImportApiController::class, 'read']); Route::post('imports/{id}', [ExportControllers\ImportApiController::class, 'run']); Route::delete('imports/{id}', [ExportControllers\ImportApiController::class, 'delete']); Route::get('recycle-bin', [EntityControllers\RecycleBinApiController::class, 'list']); Route::put('recycle-bin/{deletionId}', [EntityControllers\RecycleBinApiController::class, 'restore']); Route::delete('recycle-bin/{deletionId}', [EntityControllers\RecycleBinApiController::class, 'destroy']); Route::get('roles', [RoleApiController::class, 'list']); Route::post('roles', [RoleApiController::class, 'create']); Route::get('roles/{id}', [RoleApiController::class, 'read']); Route::put('roles/{id}', [RoleApiController::class, 'update']); Route::delete('roles/{id}', [RoleApiController::class, 'delete']); Route::get('search', [SearchApiController::class, 'all']); Route::get('system', [SystemApiController::class, 'read']); Route::get('users', [UserApiController::class, 'list']); Route::post('users', [UserApiController::class, 'create']); Route::get('users/{id}', [UserApiController::class, 'read']); Route::put('users/{id}', [UserApiController::class, 'update']); Route::delete('users/{id}', [UserApiController::class, 'delete']);
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/public/index.php
public/index.php
<?php use BookStack\Http\Request; use Illuminate\Contracts\Http\Kernel; define('LARAVEL_START', microtime(true)); // Determine if the application is in maintenance mode... if (file_exists(__DIR__ . '/../storage/framework/maintenance.php')) { require __DIR__ . '/../storage/framework/maintenance.php'; } // Register the Composer autoloader... require __DIR__ . '/../vendor/autoload.php'; // Run the application $app = require_once __DIR__ . '/../bootstrap/app.php'; $app->alias('request', Request::class); $kernel = $app->make(Kernel::class); $response = tap($kernel->handle( $request = Request::capture() ))->send(); $kernel->terminate($request, $response);
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Users/Models/RoleFactory.php
database/factories/Users/Models/RoleFactory.php
<?php namespace Database\Factories\Users\Models; use Illuminate\Database\Eloquent\Factories\Factory; class RoleFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ protected $model = \BookStack\Users\Models\Role::class; /** * Define the model's default state. * * @return array */ public function definition() { return [ 'display_name' => $this->faker->sentence(3), 'description' => $this->faker->sentence(10), 'external_auth_id' => '', ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Users/Models/UserFactory.php
database/factories/Users/Models/UserFactory.php
<?php namespace Database\Factories\Users\Models; use BookStack\Users\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; class UserFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ protected $model = User::class; /** * Define the model's default state. * * @return array */ public function definition() { $name = $this->faker->name(); return [ 'name' => $name, 'email' => $this->faker->email(), 'slug' => Str::slug($name . '-' . Str::random(5)), 'password' => Str::random(10), 'remember_token' => Str::random(10), 'email_confirmed' => 1, ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Activity/Models/ActivityFactory.php
database/factories/Activity/Models/ActivityFactory.php
<?php namespace Database\Factories\Activity\Models; use BookStack\Activity\ActivityType; use BookStack\Users\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\BookStack\Activity\Models\Activity> */ class ActivityFactory extends Factory { protected $model = \BookStack\Activity\Models\Activity::class; /** * Define the model's default state. * * @return array<string, mixed> */ public function definition(): array { $activities = ActivityType::all(); $activity = $activities[array_rand($activities)]; return [ 'type' => $activity, 'detail' => 'Activity detail for ' . $activity, 'user_id' => User::factory(), 'ip' => $this->faker->ipv4(), 'loggable_id' => null, 'loggable_type' => null, ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Activity/Models/WebhookFactory.php
database/factories/Activity/Models/WebhookFactory.php
<?php namespace Database\Factories\Activity\Models; use BookStack\Activity\Models\Webhook; use Illuminate\Database\Eloquent\Factories\Factory; class WebhookFactory extends Factory { protected $model = Webhook::class; /** * Define the model's default state. * * @return array */ public function definition() { return [ 'name' => 'My webhook for ' . $this->faker->country(), 'endpoint' => $this->faker->url(), 'active' => true, 'timeout' => 3, ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Activity/Models/TagFactory.php
database/factories/Activity/Models/TagFactory.php
<?php namespace Database\Factories\Activity\Models; use Illuminate\Database\Eloquent\Factories\Factory; class TagFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ protected $model = \BookStack\Activity\Models\Tag::class; /** * Define the model's default state. * * @return array */ public function definition() { return [ 'name' => $this->faker->city(), 'value' => $this->faker->sentence(3), ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Activity/Models/FavouriteFactory.php
database/factories/Activity/Models/FavouriteFactory.php
<?php namespace Database\Factories\Activity\Models; use BookStack\Entities\Models\Book; use BookStack\Users\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\BookStack\Activity\Models\Favourite> */ class FavouriteFactory extends Factory { protected $model = \BookStack\Activity\Models\Favourite::class; /** * Define the model's default state. * * @return array<string, mixed> */ public function definition(): array { $book = Book::query()->first(); return [ 'user_id' => User::factory(), 'favouritable_id' => $book->id, 'favouritable_type' => 'book', ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Activity/Models/CommentFactory.php
database/factories/Activity/Models/CommentFactory.php
<?php namespace Database\Factories\Activity\Models; use BookStack\Users\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; class CommentFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ protected $model = \BookStack\Activity\Models\Comment::class; /** * A static counter to provide a unique local_id for each comment. */ protected static int $nextLocalId = 1000; /** * Define the model's default state. * * @return array */ public function definition() { $text = $this->faker->paragraph(1); $html = '<p>' . $text . '</p>'; $nextLocalId = static::$nextLocalId++; $user = User::query()->first(); return [ 'html' => $html, 'parent_id' => null, 'local_id' => $nextLocalId, 'content_ref' => '', 'archived' => false, 'created_by' => $user ?? User::factory(), 'updated_by' => $user ?? User::factory(), ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Activity/Models/WebhookTrackedEventFactory.php
database/factories/Activity/Models/WebhookTrackedEventFactory.php
<?php namespace Database\Factories\Activity\Models; use BookStack\Activity\ActivityType; use BookStack\Activity\Models\Webhook; use Illuminate\Database\Eloquent\Factories\Factory; class WebhookTrackedEventFactory extends Factory { /** * Define the model's default state. * * @return array */ public function definition() { return [ 'webhook_id' => Webhook::factory(), 'event' => ActivityType::all()[array_rand(ActivityType::all())], ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Activity/Models/WatchFactory.php
database/factories/Activity/Models/WatchFactory.php
<?php namespace Database\Factories\Activity\Models; use BookStack\Activity\WatchLevels; use BookStack\Entities\Models\Book; use BookStack\Users\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\BookStack\Activity\Models\Watch> */ class WatchFactory extends Factory { protected $model = \BookStack\Activity\Models\Watch::class; /** * Define the model's default state. * * @return array<string, mixed> */ public function definition(): array { $book = Book::factory()->create(); return [ 'user_id' => User::factory(), 'watchable_id' => $book->id, 'watchable_type' => 'book', 'level' => WatchLevels::NEW, ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Uploads/ImageFactory.php
database/factories/Uploads/ImageFactory.php
<?php namespace Database\Factories\Uploads; use Illuminate\Database\Eloquent\Factories\Factory; class ImageFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ protected $model = \BookStack\Uploads\Image::class; /** * Define the model's default state. * * @return array */ public function definition() { return [ 'name' => $this->faker->slug() . '.jpg', 'url' => $this->faker->url(), 'path' => $this->faker->url(), 'type' => 'gallery', 'uploaded_to' => 0, ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Uploads/AttachmentFactory.php
database/factories/Uploads/AttachmentFactory.php
<?php namespace Database\Factories\Uploads; use BookStack\Entities\Models\Page; use BookStack\Users\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\BookStack\Uploads\Attachment> */ class AttachmentFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ protected $model = \BookStack\Uploads\Attachment::class; /** * Define the model's default state. * * @return array<string, mixed> */ public function definition() { return [ 'name' => $this->faker->words(2, true), 'path' => $this->faker->url(), 'extension' => '', 'external' => true, 'uploaded_to' => Page::factory(), 'created_by' => User::factory(), 'updated_by' => User::factory(), 'order' => 0, ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Entities/Models/SlugHistoryFactory.php
database/factories/Entities/Models/SlugHistoryFactory.php
<?php namespace Database\Factories\Entities\Models; use BookStack\Entities\Models\Book; use Illuminate\Database\Eloquent\Factories\Factory; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\BookStack\Entities\Models\SlugHistory> */ class SlugHistoryFactory extends Factory { protected $model = \BookStack\Entities\Models\SlugHistory::class; /** * Define the model's default state. * * @return array<string, mixed> */ public function definition(): array { return [ 'sluggable_id' => Book::factory(), 'sluggable_type' => 'book', 'slug' => $this->faker->slug(), 'parent_slug' => null, ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Entities/Models/BookshelfFactory.php
database/factories/Entities/Models/BookshelfFactory.php
<?php namespace Database\Factories\Entities\Models; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; class BookshelfFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ protected $model = \BookStack\Entities\Models\Bookshelf::class; /** * Define the model's default state. * * @return array */ public function definition() { $description = $this->faker->paragraph(); return [ 'name' => $this->faker->sentence, 'slug' => Str::random(10), 'description' => $description, 'description_html' => '<p>' . e($description) . '</p>' ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Entities/Models/ChapterFactory.php
database/factories/Entities/Models/ChapterFactory.php
<?php namespace Database\Factories\Entities\Models; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; class ChapterFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ protected $model = \BookStack\Entities\Models\Chapter::class; /** * Define the model's default state. * * @return array */ public function definition() { $description = $this->faker->paragraph(); return [ 'name' => $this->faker->sentence(), 'slug' => Str::random(10), 'description' => $description, 'description_html' => '<p>' . e($description) . '</p>', 'priority' => 5, ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Entities/Models/DeletionFactory.php
database/factories/Entities/Models/DeletionFactory.php
<?php namespace Database\Factories\Entities\Models; use BookStack\Entities\Models\Page; use BookStack\Users\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\BookStack\Entities\Models\Deletion> */ class DeletionFactory extends Factory { protected $model = \BookStack\Entities\Models\Deletion::class; /** * Define the model's default state. * * @return array<string, mixed> */ public function definition(): array { return [ 'deleted_by' => User::factory(), 'deletable_id' => Page::factory(), 'deletable_type' => 'page', ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Entities/Models/PageFactory.php
database/factories/Entities/Models/PageFactory.php
<?php namespace Database\Factories\Entities\Models; use BookStack\Entities\Tools\PageEditorType; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; class PageFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ protected $model = \BookStack\Entities\Models\Page::class; /** * Define the model's default state. */ public function definition(): array { $html = '<p>' . implode('</p>', $this->faker->paragraphs(5)) . '</p>'; return [ 'name' => $this->faker->sentence(), 'slug' => Str::random(10), 'html' => $html, 'text' => strip_tags($html), 'revision_count' => 1, 'editor' => 'wysiwyg', 'priority' => 1, ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Entities/Models/BookFactory.php
database/factories/Entities/Models/BookFactory.php
<?php namespace Database\Factories\Entities\Models; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; class BookFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ protected $model = \BookStack\Entities\Models\Book::class; /** * Define the model's default state. * * @return array */ public function definition() { $description = $this->faker->paragraph(); return [ 'name' => $this->faker->sentence(), 'slug' => Str::random(10), 'description' => $description, 'description_html' => '<p>' . e($description) . '</p>', 'sort_rule_id' => null, 'default_template_id' => null, ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Entities/Models/PageRevisionFactory.php
database/factories/Entities/Models/PageRevisionFactory.php
<?php namespace Database\Factories\Entities\Models; use BookStack\Entities\Models\Page; use BookStack\Users\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; class PageRevisionFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ protected $model = \BookStack\Entities\Models\PageRevision::class; /** * Define the model's default state. */ public function definition(): array { $html = '<p>' . implode('</p>', $this->faker->paragraphs(5)) . '</p>'; $page = Page::query()->first(); return [ 'page_id' => $page->id, 'name' => $this->faker->sentence(), 'html' => $html, 'text' => strip_tags($html), 'created_by' => User::factory(), 'slug' => $page->slug, 'book_slug' => $page->book->slug, 'type' => 'version', 'markdown' => strip_tags($html), 'summary' => $this->faker->sentence(), 'revision_number' => rand(1, 4000), ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Access/SocialAccountFactory.php
database/factories/Access/SocialAccountFactory.php
<?php namespace Database\Factories\Access; use BookStack\Users\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\BookStack\Access\SocialAccount> */ class SocialAccountFactory extends Factory { protected $model = \BookStack\Access\SocialAccount::class; /** * Define the model's default state. * * @return array<string, mixed> */ public function definition(): array { return [ 'user_id' => User::factory(), 'driver' => 'github', 'driver_id' => '123456', 'avatar' => '', ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Access/Mfa/MfaValueFactory.php
database/factories/Access/Mfa/MfaValueFactory.php
<?php namespace Database\Factories\Access\Mfa; use BookStack\Users\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\BookStack\Access\Mfa\MfaValue> */ class MfaValueFactory extends Factory { protected $model = \BookStack\Access\Mfa\MfaValue::class; /** * Define the model's default state. * * @return array<string, mixed> */ public function definition(): array { return [ 'user_id' => User::factory(), 'method' => 'totp', 'value' => '123456', ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Api/ApiTokenFactory.php
database/factories/Api/ApiTokenFactory.php
<?php namespace Database\Factories\Api; use BookStack\Api\ApiToken; use BookStack\Users\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Carbon; use Illuminate\Support\Str; class ApiTokenFactory extends Factory { protected $model = ApiToken::class; public function definition(): array { return [ 'token_id' => Str::random(10), 'secret' => Str::random(12), 'name' => $this->faker->name(), 'expires_at' => Carbon::now()->addYear(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now(), 'user_id' => User::factory(), ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Exports/ImportFactory.php
database/factories/Exports/ImportFactory.php
<?php namespace Database\Factories\Exports; use BookStack\Users\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; class ImportFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ protected $model = \BookStack\Exports\Import::class; /** * Define the model's default state. */ public function definition(): array { return [ 'path' => 'uploads/files/imports/' . Str::random(10) . '.zip', 'name' => $this->faker->words(3, true), 'type' => 'book', 'size' => rand(1, 1001), 'metadata' => '{"name": "My book"}', 'created_at' => User::factory(), ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/factories/Sorting/SortRuleFactory.php
database/factories/Sorting/SortRuleFactory.php
<?php namespace Database\Factories\Sorting; use BookStack\Sorting\SortRule; use BookStack\Sorting\SortRuleOperation; use Illuminate\Database\Eloquent\Factories\Factory; class SortRuleFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ protected $model = SortRule::class; /** * Define the model's default state. */ public function definition(): array { $cases = SortRuleOperation::cases(); $op = $cases[array_rand($cases)]; return [ 'name' => $op->name . ' Sort', 'sequence' => $op->value, ]; } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2024_02_04_141358_add_views_updated_index.php
database/migrations/2024_02_04_141358_add_views_updated_index.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('views', function (Blueprint $table) { $table->index(['updated_at'], 'views_updated_at_index'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('views', function (Blueprint $table) { $table->dropIndex('views_updated_at_index'); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2023_07_25_124945_add_receive_notifications_role_permissions.php
database/migrations/2023_07_25_124945_add_receive_notifications_role_permissions.php
<?php use Carbon\Carbon; use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\DB; return new class extends Migration { /** * Run the migrations. */ public function up(): void { // Create new receive-notifications permission and assign to admin role $permissionId = DB::table('role_permissions')->insertGetId([ 'name' => 'receive-notifications', 'display_name' => 'Receive & Manage Notifications', 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString(), ]); $adminRoleId = DB::table('roles')->where('system_name', '=', 'admin')->first()->id; DB::table('permission_role')->insert([ 'role_id' => $adminRoleId, 'permission_id' => $permissionId, ]); } /** * Reverse the migrations. */ public function down(): void { $permission = DB::table('role_permissions') ->where('name', '=', 'receive-notifications') ->first(); if ($permission) { DB::table('permission_role')->where([ 'permission_id' => $permission->id, ])->delete(); } DB::table('role_permissions') ->where('name', '=', 'receive-notifications') ->delete(); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2021_09_26_044614_add_activities_ip_column.php
database/migrations/2021_09_26_044614_add_activities_ip_column.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('activities', function (Blueprint $table) { $table->string('ip', 45)->after('user_id'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('activities', function (Blueprint $table) { $table->dropColumn('ip'); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2015_09_05_164707_add_email_confirmation_table.php
database/migrations/2015_09_05_164707_add_email_confirmation_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('users', function (Blueprint $table) { $table->boolean('email_confirmed')->default(true); }); Schema::create('email_confirmations', function (Blueprint $table) { $table->increments('id'); $table->integer('user_id')->index(); $table->string('token')->index(); $table->nullableTimestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('users', function (Blueprint $table) { $table->dropColumn('email_confirmed'); }); Schema::drop('email_confirmations'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2021_01_30_225441_add_settings_type_column.php
database/migrations/2021_01_30_225441_add_settings_type_column.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('settings', function (Blueprint $table) { $table->string('type', 50)->default('string'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('settings', function (Blueprint $table) { $table->dropColumn('type'); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2020_09_27_210528_create_deletions_table.php
database/migrations/2020_09_27_210528_create_deletions_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('deletions', function (Blueprint $table) { $table->increments('id'); $table->integer('deleted_by'); $table->string('deletable_type', 100); $table->integer('deletable_id'); $table->timestamps(); $table->index('deleted_by'); $table->index('deletable_type'); $table->index('deletable_id'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('deletions'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2015_08_09_093534_create_page_revisions_table.php
database/migrations/2015_08_09_093534_create_page_revisions_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('page_revisions', function (Blueprint $table) { $table->increments('id'); $table->integer('page_id')->indexed(); $table->string('name'); $table->longText('html'); $table->longText('text'); $table->integer('created_by'); $table->nullableTimestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::drop('page_revisions'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2025_10_22_134507_update_comments_relation_field_names.php
database/migrations/2025_10_22_134507_update_comments_relation_field_names.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('comments', function (Blueprint $table) { $table->renameColumn('entity_id', 'commentable_id'); $table->renameColumn('entity_type', 'commentable_type'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('comments', function (Blueprint $table) { $table->renameColumn('commentable_id', 'entity_id'); $table->renameColumn('commentable_type', 'entity_type'); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2015_08_31_175240_add_search_indexes.php
database/migrations/2015_08_31_175240_add_search_indexes.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up() { // This was removed for v0.24 since these indexes are removed anyway // and will cause issues for db engines that don't support such indexes. // $prefix = DB::getTablePrefix(); // DB::statement("ALTER TABLE {$prefix}pages ADD FULLTEXT search(name, text)"); // DB::statement("ALTER TABLE {$prefix}books ADD FULLTEXT search(name, description)"); // DB::statement("ALTER TABLE {$prefix}chapters ADD FULLTEXT search(name, description)"); } /** * Reverse the migrations. */ public function down(): void { if (Schema::hasIndex('pages', 'search')) { Schema::table('pages', function (Blueprint $table) { $table->dropIndex('search'); }); } if (Schema::hasIndex('books', 'search')) { Schema::table('books', function (Blueprint $table) { $table->dropIndex('search'); }); } if (Schema::hasIndex('chapters', 'search')) { Schema::table('chapters', function (Blueprint $table) { $table->dropIndex('search'); }); } } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2015_07_13_172121_create_images_table.php
database/migrations/2015_07_13_172121_create_images_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('images', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('url'); $table->nullableTimestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::drop('images'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2020_08_04_131052_remove_role_name_field.php
database/migrations/2020_08_04_131052_remove_role_name_field.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('roles', function (Blueprint $table) { $table->dropColumn('name'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('roles', function (Blueprint $table) { $table->string('name')->index(); }); DB::table('roles')->update([ 'name' => DB::raw("lower(replace(`display_name`, ' ', '-'))"), ]); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2017_01_21_163556_create_cache_table.php
database/migrations/2017_01_21_163556_create_cache_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('cache', function (Blueprint $table) { $table->string('key')->unique(); $table->text('value'); $table->integer('expiration'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('cache'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2021_03_08_215138_add_user_slug.php
database/migrations/2021_03_08_215138_add_user_slug.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Str; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('users', function (Blueprint $table) { $table->string('slug', 180); }); $slugMap = []; DB::table('users')->cursor()->each(function ($user) use (&$slugMap) { $userSlug = Str::slug($user->name); while (isset($slugMap[$userSlug])) { $userSlug = Str::slug($user->name . Str::random(4)); } $slugMap[$userSlug] = true; DB::table('users') ->where('id', $user->id) ->update(['slug' => $userSlug]); }); Schema::table('users', function (Blueprint $table) { $table->unique('slug'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('users', function (Blueprint $table) { $table->dropColumn('slug'); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2024_01_01_104542_add_default_template_to_chapters.php
database/migrations/2024_01_01_104542_add_default_template_to_chapters.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class AddDefaultTemplateToChapters extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('chapters', function (Blueprint $table) { $table->integer('default_template_id')->nullable()->default(null); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('chapters', function (Blueprint $table) { $table->dropColumn('default_template_id'); }); } }
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2016_07_07_181521_add_summary_to_page_revisions.php
database/migrations/2016_07_07_181521_add_summary_to_page_revisions.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('page_revisions', function ($table) { $table->string('summary')->nullable(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('page_revisions', function ($table) { $table->dropColumn('summary'); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2025_09_15_132850_create_entities_table.php
database/migrations/2025_09_15_132850_create_entities_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('entities', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('type', 10)->index(); $table->string('name'); $table->string('slug')->index(); $table->unsignedBigInteger('book_id')->nullable()->index(); $table->unsignedBigInteger('chapter_id')->nullable()->index(); $table->unsignedInteger('priority')->nullable(); $table->timestamp('created_at')->nullable(); $table->timestamp('updated_at')->nullable()->index(); $table->timestamp('deleted_at')->nullable()->index(); $table->unsignedInteger('created_by')->nullable(); $table->unsignedInteger('updated_by')->nullable(); $table->unsignedInteger('owned_by')->nullable()->index(); $table->primary(['id', 'type'], 'entities_pk'); }); Schema::create('entity_container_data', function (Blueprint $table) { $table->unsignedBigInteger('entity_id'); $table->string('entity_type', 10); $table->text('description'); $table->text('description_html'); $table->unsignedBigInteger('default_template_id')->nullable(); $table->unsignedInteger('image_id')->nullable(); $table->unsignedInteger('sort_rule_id')->nullable(); $table->primary(['entity_id', 'entity_type'], 'entity_container_data_pk'); }); Schema::create('entity_page_data', function (Blueprint $table) { $table->unsignedBigInteger('page_id')->primary(); $table->boolean('draft')->index(); $table->boolean('template')->index(); $table->unsignedInteger('revision_count'); $table->string('editor', 50); $table->longText('html'); $table->longText('text'); $table->longText('markdown'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('entities'); Schema::dropIfExists('entity_container_data'); Schema::dropIfExists('entity_page_data'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2023_02_23_200227_add_updated_at_index_to_pages.php
database/migrations/2023_02_23_200227_add_updated_at_index_to_pages.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('pages', function (Blueprint $table) { $table->index('updated_at', 'pages_updated_at_index'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('pages', function (Blueprint $table) { $table->dropIndex('pages_updated_at_index'); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2015_07_12_114933_create_books_table.php
database/migrations/2015_07_12_114933_create_books_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('books', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('slug')->indexed(); $table->text('description'); $table->nullableTimestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::drop('books'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2015_07_27_172342_create_chapters_table.php
database/migrations/2015_07_27_172342_create_chapters_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('chapters', function (Blueprint $table) { $table->increments('id'); $table->integer('book_id'); $table->string('slug')->indexed(); $table->text('name'); $table->text('description'); $table->integer('priority'); $table->nullableTimestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::drop('chapters'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2019_12_29_120917_add_api_auth.php
database/migrations/2019_12_29_120917_add_api_auth.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { // Add API tokens table Schema::create('api_tokens', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('token_id')->unique(); $table->string('secret'); $table->integer('user_id')->unsigned()->index(); $table->date('expires_at')->index(); $table->nullableTimestamps(); }); // Add access-api permission $adminRoleId = DB::table('roles')->where('system_name', '=', 'admin')->first()->id; $permissionId = DB::table('role_permissions')->insertGetId([ 'name' => 'access-api', 'display_name' => 'Access system API', 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString(), ]); DB::table('permission_role')->insert([ 'role_id' => $adminRoleId, 'permission_id' => $permissionId, ]); } /** * Reverse the migrations. */ public function down(): void { // Remove API tokens table Schema::dropIfExists('api_tokens'); // Remove access-api permission $apiAccessPermission = DB::table('role_permissions') ->where('name', '=', 'access-api')->first(); DB::table('permission_role')->where('permission_id', '=', $apiAccessPermission->id)->delete(); DB::table('role_permissions')->where('name', '=', 'access-api')->delete(); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2022_04_25_140741_update_polymorphic_types.php
database/migrations/2022_04_25_140741_update_polymorphic_types.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\DB; return new class extends Migration { /** * Mapping of old polymorphic types to new simpler values. */ protected array $changeMap = [ 'BookStack\\Bookshelf' => 'bookshelf', 'BookStack\\Book' => 'book', 'BookStack\\Chapter' => 'chapter', 'BookStack\\Page' => 'page', ]; /** * Mapping of tables and columns that contain polymorphic types. */ protected array $columnsByTable = [ 'activities' => 'entity_type', 'comments' => 'entity_type', 'deletions' => 'deletable_type', 'entity_permissions' => 'restrictable_type', 'favourites' => 'favouritable_type', 'joint_permissions' => 'entity_type', 'search_terms' => 'entity_type', 'tags' => 'entity_type', 'views' => 'viewable_type', ]; /** * Run the migrations. */ public function up(): void { foreach ($this->columnsByTable as $table => $column) { foreach ($this->changeMap as $oldVal => $newVal) { DB::table($table) ->where([$column => $oldVal]) ->update([$column => $newVal]); } } } /** * Reverse the migrations. */ public function down(): void { foreach ($this->columnsByTable as $table => $column) { foreach ($this->changeMap as $oldVal => $newVal) { DB::table($table) ->where([$column => $newVal]) ->update([$column => $oldVal]); } } } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2023_12_17_140913_add_description_html_to_entities.php
database/migrations/2023_12_17_140913_add_description_html_to_entities.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { $addColumn = fn(Blueprint $table) => $table->text('description_html'); Schema::table('books', $addColumn); Schema::table('chapters', $addColumn); Schema::table('bookshelves', $addColumn); } /** * Reverse the migrations. */ public function down(): void { $removeColumn = fn(Blueprint $table) => $table->removeColumn('description_html'); Schema::table('books', $removeColumn); Schema::table('chapters', $removeColumn); Schema::table('bookshelves', $removeColumn); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2025_09_15_134813_drop_old_entity_tables.php
database/migrations/2025_09_15_134813_drop_old_entity_tables.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Query\JoinClause; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::dropIfExists('pages'); Schema::dropIfExists('chapters'); Schema::dropIfExists('books'); Schema::dropIfExists('bookshelves'); } /** * Reverse the migrations. */ public function down(): void { Schema::create('pages', function (Blueprint $table) { $table->unsignedInteger('id', true)->primary(); $table->integer('book_id')->index(); $table->integer('chapter_id')->index(); $table->string('name'); $table->string('slug')->index(); $table->longText('html'); $table->longText('text'); $table->integer('priority')->index(); $table->timestamp('created_at')->nullable(); $table->timestamp('updated_at')->nullable()->index(); $table->integer('created_by')->index(); $table->integer('updated_by')->index(); $table->boolean('draft')->default(0)->index(); $table->longText('markdown'); $table->integer('revision_count'); $table->boolean('template')->default(0)->index(); $table->timestamp('deleted_at')->nullable(); $table->unsignedInteger('owned_by')->index(); $table->string('editor', 50)->default(''); }); Schema::create('chapters', function (Blueprint $table) { $table->unsignedInteger('id', true)->primary(); $table->integer('book_id')->index(); $table->string('slug')->index(); $table->text('name'); $table->text('description'); $table->integer('priority')->index(); $table->timestamp('created_at')->nullable(); $table->timestamp('updated_at')->nullable(); $table->integer('created_by')->index(); $table->integer('updated_by')->index(); $table->timestamp('deleted_at')->nullable(); $table->unsignedInteger('owned_by')->index(); $table->text('description_html'); $table->integer('default_template_id')->nullable(); }); Schema::create('books', function (Blueprint $table) { $table->unsignedInteger('id', true)->primary(); $table->string('name'); $table->string('slug')->index(); $table->text('description'); $table->timestamp('created_at')->nullable(); $table->timestamp('updated_at')->nullable(); $table->integer('created_by')->index(); $table->integer('updated_by')->index(); $table->integer('image_id')->nullable(); $table->timestamp('deleted_at')->nullable(); $table->unsignedInteger('owned_by')->index(); $table->integer('default_template_id')->nullable(); $table->text('description_html'); $table->unsignedInteger('sort_rule_id')->nullable(); }); Schema::create('bookshelves', function (Blueprint $table) { $table->unsignedInteger('id', true)->primary(); $table->string('name', 180); $table->string('slug', 180)->index(); $table->text('description'); $table->integer('created_by')->index(); $table->integer('updated_by')->index(); $table->integer('image_id')->nullable(); $table->timestamp('created_at')->nullable(); $table->timestamp('updated_at')->nullable(); $table->timestamp('deleted_at')->nullable(); $table->unsignedInteger('owned_by')->index(); $table->text('description_html'); }); DB::beginTransaction(); // Revert nulls back to zeros DB::table('entities')->whereNull('created_by')->update(['created_by' => 0]); DB::table('entities')->whereNull('updated_by')->update(['updated_by' => 0]); DB::table('entities')->whereNull('owned_by')->update(['owned_by' => 0]); DB::table('entities')->whereNull('chapter_id')->update(['chapter_id' => 0]); // Restore data back into pages table $pageFields = [ 'id', 'book_id', 'chapter_id', 'name', 'slug', 'html', 'text', 'priority', 'created_at', 'updated_at', 'created_by', 'updated_by', 'draft', 'markdown', 'revision_count', 'template', 'deleted_at', 'owned_by', 'editor' ]; $pageQuery = DB::table('entities')->select($pageFields) ->leftJoin('entity_page_data', 'entities.id', '=', 'entity_page_data.page_id') ->where('type', '=', 'page'); DB::table('pages')->insertUsing($pageFields, $pageQuery); // Restore data back into chapters table $containerJoinClause = function (JoinClause $join) { return $join->on('entities.id', '=', 'entity_container_data.entity_id') ->on('entities.type', '=', 'entity_container_data.entity_type'); }; $chapterFields = [ 'id', 'book_id', 'slug', 'name', 'description', 'priority', 'created_at', 'updated_at', 'created_by', 'updated_by', 'deleted_at', 'owned_by', 'description_html', 'default_template_id' ]; $chapterQuery = DB::table('entities')->select($chapterFields) ->leftJoin('entity_container_data', $containerJoinClause) ->where('type', '=', 'chapter'); DB::table('chapters')->insertUsing($chapterFields, $chapterQuery); // Restore data back into books table $bookFields = [ 'id', 'name', 'slug', 'description', 'created_at', 'updated_at', 'created_by', 'updated_by', 'image_id', 'deleted_at', 'owned_by', 'default_template_id', 'description_html', 'sort_rule_id' ]; $bookQuery = DB::table('entities')->select($bookFields) ->leftJoin('entity_container_data', $containerJoinClause) ->where('type', '=', 'book'); DB::table('books')->insertUsing($bookFields, $bookQuery); // Restore data back into bookshelves table $shelfFields = [ 'id', 'name', 'slug', 'description', 'created_by', 'updated_by', 'image_id', 'created_at', 'updated_at', 'deleted_at', 'owned_by', 'description_html', ]; $shelfQuery = DB::table('entities')->select($shelfFields) ->leftJoin('entity_container_data', $containerJoinClause) ->where('type', '=', 'bookshelf'); DB::table('bookshelves')->insertUsing($shelfFields, $shelfQuery); DB::commit(); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2017_08_29_102650_add_cover_image_display.php
database/migrations/2017_08_29_102650_add_cover_image_display.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('books', function (Blueprint $table) { $table->integer('image_id')->nullable()->default(null); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('books', function (Blueprint $table) { $table->dropColumn('image_id'); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2015_08_08_200447_add_users_to_entities.php
database/migrations/2015_08_08_200447_add_users_to_entities.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('pages', function (Blueprint $table) { $table->integer('created_by'); $table->integer('updated_by'); }); Schema::table('chapters', function (Blueprint $table) { $table->integer('created_by'); $table->integer('updated_by'); }); Schema::table('images', function (Blueprint $table) { $table->integer('created_by'); $table->integer('updated_by'); }); Schema::table('books', function (Blueprint $table) { $table->integer('created_by'); $table->integer('updated_by'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('pages', function (Blueprint $table) { $table->dropColumn('created_by'); $table->dropColumn('updated_by'); }); Schema::table('chapters', function (Blueprint $table) { $table->dropColumn('created_by'); $table->dropColumn('updated_by'); }); Schema::table('images', function (Blueprint $table) { $table->dropColumn('created_by'); $table->dropColumn('updated_by'); }); Schema::table('books', function (Blueprint $table) { $table->dropColumn('created_by'); $table->dropColumn('updated_by'); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2025_12_15_140219_create_mention_history_table.php
database/migrations/2025_12_15_140219_create_mention_history_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('mention_history', function (Blueprint $table) { $table->increments('id'); $table->string('mentionable_type', 50)->index(); $table->unsignedBigInteger('mentionable_id')->index(); $table->unsignedInteger('from_user_id'); $table->unsignedInteger('to_user_id'); $table->timestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('mention_history'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2017_07_02_152834_update_db_encoding_to_ut8mb4.php
database/migrations/2017_07_02_152834_update_db_encoding_to_ut8mb4.php
<?php use Illuminate\Database\Migrations\Migration; return new class extends Migration { /** * Run the migrations. */ public function up() { // Migration removed due to issues during live migration. // Instead you can run the command `artisan bookstack:db-utf8mb4` // which will generate out the SQL request to upgrade your DB to utf8mb4. } /** * Reverse the migrations. */ public function down() { // } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2025_12_19_103417_add_views_viewable_type_index.php
database/migrations/2025_12_19_103417_add_views_viewable_type_index.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('views', function (Blueprint $table) { $table->index('viewable_type', 'views_viewable_type_index'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('views', function (Blueprint $table) { $table->dropIndex('views_viewable_type_index'); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2017_08_01_130541_create_comments_table.php
database/migrations/2017_08_01_130541_create_comments_table.php
<?php use Carbon\Carbon; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('comments', function (Blueprint $table) { $table->increments('id')->unsigned(); $table->integer('entity_id')->unsigned(); $table->string('entity_type'); $table->longText('text')->nullable(); $table->longText('html')->nullable(); $table->integer('parent_id')->unsigned()->nullable(); $table->integer('local_id')->unsigned()->nullable(); $table->integer('created_by')->unsigned(); $table->integer('updated_by')->unsigned()->nullable(); $table->timestamps(); $table->index(['entity_id', 'entity_type']); $table->index(['local_id']); // Assign new comment permissions to admin role $adminRoleId = DB::table('roles')->where('system_name', '=', 'admin')->first()->id; // Create & attach new entity permissions $ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own']; $entity = 'Comment'; foreach ($ops as $op) { $permissionId = DB::table('role_permissions')->insertGetId([ 'name' => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)), 'display_name' => $op . ' ' . $entity . 's', 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString(), ]); DB::table('permission_role')->insert([ 'role_id' => $adminRoleId, 'permission_id' => $permissionId, ]); } }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('comments'); // Delete comment role permissions $ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own']; $entity = 'Comment'; foreach ($ops as $op) { $permName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)); DB::table('role_permissions')->where('name', '=', $permName)->delete(); } } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2025_01_29_180933_create_sort_rules_table.php
database/migrations/2025_01_29_180933_create_sort_rules_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('sort_rules', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->text('sequence'); $table->timestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('sort_rules'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2023_07_31_104430_create_watches_table.php
database/migrations/2023_07_31_104430_create_watches_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('watches', function (Blueprint $table) { $table->increments('id'); $table->integer('user_id')->index(); $table->integer('watchable_id'); $table->string('watchable_type', 100); $table->tinyInteger('level', false, true)->index(); $table->timestamps(); $table->index(['watchable_id', 'watchable_type'], 'watchable_index'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('watches'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2014_10_12_000000_create_users_table.php
database/migrations/2014_10_12_000000_create_users_table.php
<?php use Carbon\Carbon; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('email')->unique(); $table->string('password', 60); $table->rememberToken(); $table->nullableTimestamps(); }); // Create the initial admin user DB::table('users')->insert([ 'name' => 'Admin', 'email' => 'admin@admin.com', 'password' => bcrypt('password'), 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString(), ]); } /** * Reverse the migrations. */ public function down(): void { Schema::drop('users'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2022_01_03_154041_add_webhooks_timeout_error_columns.php
database/migrations/2022_01_03_154041_add_webhooks_timeout_error_columns.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('webhooks', function (Blueprint $table) { $table->unsignedInteger('timeout')->default(3); $table->text('last_error')->default(''); $table->timestamp('last_called_at')->nullable(); $table->timestamp('last_errored_at')->nullable(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('webhooks', function (Blueprint $table) { $table->dropColumn('timeout'); $table->dropColumn('last_error'); $table->dropColumn('last_called_at'); $table->dropColumn('last_errored_at'); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2023_08_21_174248_increase_cache_size.php
database/migrations/2023_08_21_174248_increase_cache_size.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('cache', function (Blueprint $table) { $table->mediumText('value')->change(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('cache', function (Blueprint $table) { $table->text('value')->change(); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2015_11_21_145609_create_views_table.php
database/migrations/2015_11_21_145609_create_views_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('views', function (Blueprint $table) { $table->increments('id'); $table->integer('user_id'); $table->integer('viewable_id'); $table->string('viewable_type'); $table->integer('views'); $table->nullableTimestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::drop('views'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2018_08_04_115700_create_bookshelves_table.php
database/migrations/2018_08_04_115700_create_bookshelves_table.php
<?php use Carbon\Carbon; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { // Convert the existing entity tables to InnoDB. // Wrapped in try-catch just in the event a different database system is used // which does not support InnoDB but does support all required features // like foreign key references. try { $prefix = DB::getTablePrefix(); DB::statement("ALTER TABLE {$prefix}pages ENGINE = InnoDB;"); DB::statement("ALTER TABLE {$prefix}chapters ENGINE = InnoDB;"); DB::statement("ALTER TABLE {$prefix}books ENGINE = InnoDB;"); } catch (Exception $exception) { } // Here we have table drops before the creations due to upgrade issues // people were having due to the bookshelves_books table creation failing. if (Schema::hasTable('bookshelves_books')) { Schema::drop('bookshelves_books'); } if (Schema::hasTable('bookshelves')) { Schema::drop('bookshelves'); } Schema::create('bookshelves', function (Blueprint $table) { $table->increments('id'); $table->string('name', 180); $table->string('slug', 180); $table->text('description'); $table->integer('created_by')->nullable()->default(null); $table->integer('updated_by')->nullable()->default(null); $table->boolean('restricted')->default(false); $table->integer('image_id')->nullable()->default(null); $table->timestamps(); $table->index('slug'); $table->index('created_by'); $table->index('updated_by'); $table->index('restricted'); }); Schema::create('bookshelves_books', function (Blueprint $table) { $table->integer('bookshelf_id')->unsigned(); $table->integer('book_id')->unsigned(); $table->integer('order')->unsigned(); $table->primary(['bookshelf_id', 'book_id']); $table->foreign('bookshelf_id')->references('id')->on('bookshelves') ->onUpdate('cascade')->onDelete('cascade'); $table->foreign('book_id')->references('id')->on('books') ->onUpdate('cascade')->onDelete('cascade'); }); // Delete old bookshelf permissions // Needed to to issues upon upgrade. DB::table('role_permissions')->where('name', 'like', 'bookshelf-%')->delete(); // Copy existing role permissions from Books $ops = ['View All', 'View Own', 'Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own']; foreach ($ops as $op) { $dbOpName = strtolower(str_replace(' ', '-', $op)); $roleIdsWithBookPermission = DB::table('role_permissions') ->leftJoin('permission_role', 'role_permissions.id', '=', 'permission_role.permission_id') ->leftJoin('roles', 'roles.id', '=', 'permission_role.role_id') ->where('role_permissions.name', '=', 'book-' . $dbOpName)->get(['roles.id'])->pluck('id'); $permId = DB::table('role_permissions')->insertGetId([ 'name' => 'bookshelf-' . $dbOpName, 'display_name' => $op . ' ' . 'BookShelves', 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString(), ]); $rowsToInsert = $roleIdsWithBookPermission->filter(function ($roleId) { return !is_null($roleId); })->map(function ($roleId) use ($permId) { return [ 'role_id' => $roleId, 'permission_id' => $permId, ]; })->toArray(); // Assign view permission to all current roles DB::table('permission_role')->insert($rowsToInsert); } } /** * Reverse the migrations. */ public function down(): void { // Drop created permissions $ops = ['bookshelf-create-all', 'bookshelf-create-own', 'bookshelf-delete-all', 'bookshelf-delete-own', 'bookshelf-update-all', 'bookshelf-update-own', 'bookshelf-view-all', 'bookshelf-view-own']; $permissionIds = DB::table('role_permissions')->whereIn('name', $ops) ->get(['id'])->pluck('id')->toArray(); DB::table('permission_role')->whereIn('permission_id', $permissionIds)->delete(); DB::table('role_permissions')->whereIn('id', $permissionIds)->delete(); // Drop shelves table Schema::dropIfExists('bookshelves_books'); Schema::dropIfExists('bookshelves'); // Drop related polymorphic items DB::table('activities')->where('entity_type', '=', 'BookStack\Entities\Models\Bookshelf')->delete(); DB::table('views')->where('viewable_type', '=', 'BookStack\Entities\Models\Bookshelf')->delete(); DB::table('entity_permissions')->where('restrictable_type', '=', 'BookStack\Entities\Models\Bookshelf')->delete(); DB::table('tags')->where('entity_type', '=', 'BookStack\Entities\Models\Bookshelf')->delete(); DB::table('search_terms')->where('entity_type', '=', 'BookStack\Entities\Models\Bookshelf')->delete(); DB::table('comments')->where('entity_type', '=', 'BookStack\Entities\Models\Bookshelf')->delete(); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2016_03_13_082138_add_page_drafts.php
database/migrations/2016_03_13_082138_add_page_drafts.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('pages', function (Blueprint $table) { $table->boolean('draft')->default(false); $table->index('draft'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('pages', function (Blueprint $table) { $table->dropColumn('draft'); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2016_03_09_203143_add_page_revision_types.php
database/migrations/2016_03_09_203143_add_page_revision_types.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('page_revisions', function (Blueprint $table) { $table->string('type')->default('version'); $table->index('type'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('page_revisions', function (Blueprint $table) { $table->dropColumn('type'); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2024_09_29_140340_ensure_editor_value_set.php
database/migrations/2024_09_29_140340_ensure_editor_value_set.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\DB; return new class extends Migration { /** * Run the migrations. */ public function up(): void { // Ensure we have an "editor" value set for pages // Get default $default = DB::table('settings') ->where('setting_key', '=', 'app-editor') ->first() ->value ?? 'wysiwyg'; $default = ($default === 'markdown') ? 'markdown' : 'wysiwyg'; // We set it to 'markdown' for pages currently with markdown content DB::table('pages') ->where('editor', '=', '') ->where('markdown', '!=', '') ->update(['editor' => 'markdown']); // We set it to 'wysiwyg' where we have HTML but no markdown DB::table('pages') ->where('editor', '=', '') ->where('markdown', '=', '') ->where('html', '!=', '') ->update(['editor' => 'wysiwyg']); // Otherwise, where still empty, set to the current default DB::table('pages') ->where('editor', '=', '') ->update(['editor' => $default]); } /** * Reverse the migrations. */ public function down(): void { // Can't reverse due to not knowing what would have been empty before } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2015_09_04_165821_create_social_accounts_table.php
database/migrations/2015_09_04_165821_create_social_accounts_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('social_accounts', function (Blueprint $table) { $table->increments('id'); $table->integer('user_id')->index(); $table->string('driver')->index(); $table->string('driver_id'); $table->string('avatar'); $table->nullableTimestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::drop('social_accounts'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2016_04_09_100730_add_view_permissions_to_roles.php
database/migrations/2016_04_09_100730_add_view_permissions_to_roles.php
<?php use Carbon\Carbon; use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\DB; return new class extends Migration { /** * Run the migrations. */ public function up(): void { $currentRoles = DB::table('roles')->get(); // Create new view permission $entities = ['Book', 'Page', 'Chapter']; $ops = ['View All', 'View Own']; foreach ($entities as $entity) { foreach ($ops as $op) { $permId = DB::table('permissions')->insertGetId([ 'name' => strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)), 'display_name' => $op . ' ' . $entity . 's', 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString(), ]); // Assign view permission to all current roles foreach ($currentRoles as $role) { DB::table('permission_role')->insert([ 'role_id' => $role->id, 'permission_id' => $permId, ]); } } } } /** * Reverse the migrations. */ public function down(): void { // Delete the new view permission $entities = ['Book', 'Page', 'Chapter']; $ops = ['View All', 'View Own']; foreach ($entities as $entity) { foreach ($ops as $op) { $permissionName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)); $permission = DB::table('permissions')->where('name', '=', $permissionName)->first(); DB::table('permission_role')->where('permission_id', '=', $permission->id)->delete(); DB::table('permissions')->where('name', '=', $permissionName)->delete(); } } } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2015_08_30_125859_create_settings_table.php
database/migrations/2015_08_30_125859_create_settings_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('settings', function (Blueprint $table) { $table->string('setting_key')->primary()->indexed(); $table->text('value'); $table->nullableTimestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::drop('settings'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2014_10_12_100000_create_password_resets_table.php
database/migrations/2014_10_12_100000_create_password_resets_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('password_resets', function (Blueprint $table) { $table->string('email')->index(); $table->string('token')->index(); $table->timestamp('created_at'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::drop('password_resets'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2015_12_07_195238_add_image_upload_types.php
database/migrations/2015_12_07_195238_add_image_upload_types.php
<?php use BookStack\Uploads\Image; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('images', function (Blueprint $table) { $table->string('path', 400); $table->string('type')->index(); }); Image::all()->each(function ($image) { $image->path = $image->url; $image->type = 'gallery'; $image->save(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('images', function (Blueprint $table) { $table->dropColumn('type'); $table->dropColumn('path'); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2016_01_11_210908_add_external_auth_to_users.php
database/migrations/2016_01_11_210908_add_external_auth_to_users.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('users', function (Blueprint $table) { $table->string('external_auth_id')->index(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('users', function (Blueprint $table) { $table->dropColumn('external_auth_id'); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2025_11_23_161812_create_slug_history_table.php
database/migrations/2025_11_23_161812_create_slug_history_table.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { // Create the table for storing slug history Schema::create('slug_history', function (Blueprint $table) { $table->increments('id'); $table->string('sluggable_type', 10)->index(); $table->unsignedBigInteger('sluggable_id')->index(); $table->string('slug')->index(); $table->string('parent_slug')->nullable()->index(); $table->timestamps(); }); // Migrate in slugs from page revisions $revisionSlugQuery = DB::table('page_revisions') ->select([ DB::raw('\'page\' as sluggable_type'), 'page_id as sluggable_id', 'slug', 'book_slug as parent_slug', DB::raw('min(created_at) as created_at'), DB::raw('min(updated_at) as updated_at'), ]) ->where('type', '=', 'version') ->groupBy(['sluggable_id', 'slug', 'parent_slug']); DB::table('slug_history')->insertUsing( ['sluggable_type', 'sluggable_id', 'slug', 'parent_slug', 'created_at', 'updated_at'], $revisionSlugQuery, ); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('slug_history'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2023_01_24_104625_refactor_joint_permissions_storage.php
database/migrations/2023_01_24_104625_refactor_joint_permissions_storage.php
<?php use BookStack\Permissions\JointPermissionBuilder; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { // Truncate before schema changes to avoid performance issues // since we'll need to rebuild anyway. DB::table('joint_permissions')->truncate(); if (Schema::hasColumn('joint_permissions', 'owned_by')) { Schema::table('joint_permissions', function (Blueprint $table) { $table->dropColumn(['has_permission', 'has_permission_own', 'owned_by']); $table->unsignedTinyInteger('status')->index(); $table->unsignedInteger('owner_id')->nullable()->index(); }); } } /** * Reverse the migrations. */ public function down(): void { DB::table('joint_permissions')->truncate(); Schema::table('joint_permissions', function (Blueprint $table) { $table->dropColumn(['status', 'owner_id']); $table->boolean('has_permission')->index(); $table->boolean('has_permission_own')->index(); $table->unsignedInteger('owned_by')->index(); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2020_09_27_210059_add_entity_soft_deletes.php
database/migrations/2020_09_27_210059_add_entity_soft_deletes.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('bookshelves', function (Blueprint $table) { $table->softDeletes(); }); Schema::table('books', function (Blueprint $table) { $table->softDeletes(); }); Schema::table('chapters', function (Blueprint $table) { $table->softDeletes(); }); Schema::table('pages', function (Blueprint $table) { $table->softDeletes(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('bookshelves', function (Blueprint $table) { $table->dropSoftDeletes(); }); Schema::table('books', function (Blueprint $table) { $table->dropSoftDeletes(); }); Schema::table('chapters', function (Blueprint $table) { $table->dropSoftDeletes(); }); Schema::table('pages', function (Blueprint $table) { $table->dropSoftDeletes(); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2016_04_20_192649_create_joint_permissions_table.php
database/migrations/2016_04_20_192649_create_joint_permissions_table.php
<?php use Carbon\Carbon; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Str; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('joint_permissions', function (Blueprint $table) { $table->increments('id'); $table->integer('role_id'); $table->string('entity_type'); $table->integer('entity_id'); $table->string('action'); $table->boolean('has_permission')->default(false); $table->boolean('has_permission_own')->default(false); $table->integer('created_by'); // Create indexes $table->index(['entity_id', 'entity_type']); $table->index('has_permission'); $table->index('has_permission_own'); $table->index('role_id'); $table->index('action'); $table->index('created_by'); }); Schema::table('roles', function (Blueprint $table) { $table->string('system_name'); $table->boolean('hidden')->default(false); $table->index('hidden'); $table->index('system_name'); }); Schema::rename('permissions', 'role_permissions'); Schema::rename('restrictions', 'entity_permissions'); // Create the new public role $publicRoleData = [ 'name' => 'public', 'display_name' => 'Public', 'description' => 'The role given to public visitors if allowed', 'system_name' => 'public', 'hidden' => true, 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString(), ]; // Ensure unique name while (DB::table('roles')->where('name', '=', $publicRoleData['display_name'])->count() > 0) { $publicRoleData['display_name'] = $publicRoleData['display_name'] . Str::random(2); } $publicRoleId = DB::table('roles')->insertGetId($publicRoleData); // Add new view permissions to public role $entities = ['Book', 'Page', 'Chapter']; $ops = ['View All', 'View Own']; foreach ($entities as $entity) { foreach ($ops as $op) { $name = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op)); $permission = DB::table('role_permissions')->where('name', '=', $name)->first(); // Assign view permission to public DB::table('permission_role')->insert([ 'permission_id' => $permission->id, 'role_id' => $publicRoleId, ]); } } // Update admin role with system name DB::table('roles')->where('name', '=', 'admin')->update(['system_name' => 'admin']); } /** * Reverse the migrations. */ public function down(): void { Schema::drop('joint_permissions'); Schema::rename('role_permissions', 'permissions'); Schema::rename('entity_permissions', 'restrictions'); // Delete the public role DB::table('roles')->where('system_name', '=', 'public')->delete(); Schema::table('roles', function (Blueprint $table) { $table->dropColumn('system_name'); $table->dropColumn('hidden'); }); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2015_08_29_105422_add_roles_and_permissions.php
database/migrations/2015_08_29_105422_add_roles_and_permissions.php
<?php /** * Much of this code has been taken from entrust, * a role & permission management solution for Laravel. * * Full attribution of the database Schema shown below goes to the entrust project. * * @license MIT * @url https://github.com/Zizaco/entrust */ use Carbon\Carbon; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { // Create table for storing roles Schema::create('roles', function (Blueprint $table) { $table->increments('id'); $table->string('name')->unique(); $table->string('display_name')->nullable(); $table->string('description')->nullable(); $table->nullableTimestamps(); }); // Create table for associating roles to users (Many-to-Many) Schema::create('role_user', function (Blueprint $table) { $table->integer('user_id')->unsigned(); $table->integer('role_id')->unsigned(); $table->foreign('user_id')->references('id')->on('users') ->onUpdate('cascade')->onDelete('cascade'); $table->foreign('role_id')->references('id')->on('roles') ->onUpdate('cascade')->onDelete('cascade'); $table->primary(['user_id', 'role_id']); }); // Create table for storing permissions Schema::create('permissions', function (Blueprint $table) { $table->increments('id'); $table->string('name')->unique(); $table->string('display_name')->nullable(); $table->string('description')->nullable(); $table->nullableTimestamps(); }); // Create table for associating permissions to roles (Many-to-Many) Schema::create('permission_role', function (Blueprint $table) { $table->integer('permission_id')->unsigned(); $table->integer('role_id')->unsigned(); $table->foreign('permission_id')->references('id')->on('permissions') ->onUpdate('cascade')->onDelete('cascade'); $table->foreign('role_id')->references('id')->on('roles') ->onUpdate('cascade')->onDelete('cascade'); $table->primary(['permission_id', 'role_id']); }); // Create default roles $adminId = DB::table('roles')->insertGetId([ 'name' => 'admin', 'display_name' => 'Admin', 'description' => 'Administrator of the whole application', 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString(), ]); $editorId = DB::table('roles')->insertGetId([ 'name' => 'editor', 'display_name' => 'Editor', 'description' => 'User can edit Books, Chapters & Pages', 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString(), ]); $viewerId = DB::table('roles')->insertGetId([ 'name' => 'viewer', 'display_name' => 'Viewer', 'description' => 'User can view books & their content behind authentication', 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString(), ]); // Create default CRUD permissions and allocate to admins and editors $entities = ['Book', 'Page', 'Chapter', 'Image']; $ops = ['Create', 'Update', 'Delete']; foreach ($entities as $entity) { foreach ($ops as $op) { $newPermId = DB::table('permissions')->insertGetId([ 'name' => strtolower($entity) . '-' . strtolower($op), 'display_name' => $op . ' ' . $entity . 's', 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString(), ]); DB::table('permission_role')->insert([ ['permission_id' => $newPermId, 'role_id' => $adminId], ['permission_id' => $newPermId, 'role_id' => $editorId], ]); } } // Create admin permissions $entities = ['Settings', 'User']; $ops = ['Create', 'Update', 'Delete']; foreach ($entities as $entity) { foreach ($ops as $op) { $newPermId = DB::table('permissions')->insertGetId([ 'name' => strtolower($entity) . '-' . strtolower($op), 'display_name' => $op . ' ' . $entity, 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString(), ]); DB::table('permission_role')->insert([ 'permission_id' => $newPermId, 'role_id' => $adminId, ]); } } // Set all current users as admins // (At this point only the initially create user should be an admin) $users = DB::table('users')->get()->all(); foreach ($users as $user) { DB::table('role_user')->insert([ 'role_id' => $adminId, 'user_id' => $user->id, ]); } } /** * Reverse the migrations. */ public function down(): void { Schema::drop('permission_role'); Schema::drop('permissions'); Schema::drop('role_user'); Schema::drop('roles'); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false
BookStackApp/BookStack
https://github.com/BookStackApp/BookStack/blob/e6b754fad029d6c35e139b907d04e6510775997b/database/migrations/2022_10_08_104202_drop_entity_restricted_field.php
database/migrations/2022_10_08_104202_drop_entity_restricted_field.php
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Query\Builder; use Illuminate\Database\Query\JoinClause; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { // Remove entity-permissions on non-restricted entities $deleteInactiveEntityPermissions = function (string $table, string $morphClass) { $permissionIds = DB::table('entity_permissions')->select('entity_permissions.id as id') ->join($table, function (JoinClause $join) use ($table, $morphClass) { return $join->where($table . '.restricted', '=', 0) ->on($table . '.id', '=', 'entity_permissions.entity_id'); })->where('entity_type', '=', $morphClass) ->pluck('id'); DB::table('entity_permissions')->whereIn('id', $permissionIds)->delete(); }; $deleteInactiveEntityPermissions('pages', 'page'); $deleteInactiveEntityPermissions('chapters', 'chapter'); $deleteInactiveEntityPermissions('books', 'book'); $deleteInactiveEntityPermissions('bookshelves', 'bookshelf'); // Migrate restricted=1 entries to new entity_permissions (role_id=0) entries $defaultEntityPermissionGenQuery = function (Builder $query, string $table, string $morphClass) { return $query->select(['id as entity_id']) ->selectRaw('? as entity_type', [$morphClass]) ->selectRaw('? as `role_id`', [0]) ->selectRaw('? as `view`', [0]) ->selectRaw('? as `create`', [0]) ->selectRaw('? as `update`', [0]) ->selectRaw('? as `delete`', [0]) ->from($table) ->where('restricted', '=', 1); }; $query = $defaultEntityPermissionGenQuery(DB::query(), 'pages', 'page') ->union(fn(Builder $query) => $defaultEntityPermissionGenQuery($query, 'books', 'book')) ->union(fn(Builder $query) => $defaultEntityPermissionGenQuery($query, 'chapters', 'chapter')) ->union(fn(Builder $query) => $defaultEntityPermissionGenQuery($query, 'bookshelves', 'bookshelf')); DB::table('entity_permissions')->insertUsing(['entity_id', 'entity_type', 'role_id', 'view', 'create', 'update', 'delete'], $query); // Drop restricted columns $dropRestrictedColumn = fn(Blueprint $table) => $table->dropColumn('restricted'); Schema::table('pages', $dropRestrictedColumn); Schema::table('chapters', $dropRestrictedColumn); Schema::table('books', $dropRestrictedColumn); Schema::table('bookshelves', $dropRestrictedColumn); } /** * Reverse the migrations. */ public function down(): void { // Create restricted columns $createRestrictedColumn = fn(Blueprint $table) => $table->boolean('restricted')->index()->default(0); Schema::table('pages', $createRestrictedColumn); Schema::table('chapters', $createRestrictedColumn); Schema::table('books', $createRestrictedColumn); Schema::table('bookshelves', $createRestrictedColumn); // Set restrictions for entities that have a default entity permission assigned // Note: Possible loss of data where default entity permissions have been configured $restrictEntities = function (string $table, string $morphClass) { $toRestrictIds = DB::table('entity_permissions') ->where('role_id', '=', 0) ->where('entity_type', '=', $morphClass) ->pluck('entity_id'); DB::table($table)->whereIn('id', $toRestrictIds)->update(['restricted' => true]); }; $restrictEntities('pages', 'page'); $restrictEntities('chapters', 'chapter'); $restrictEntities('books', 'book'); $restrictEntities('bookshelves', 'bookshelf'); // Delete default entity permissions DB::table('entity_permissions')->where('role_id', '=', 0)->delete(); } };
php
MIT
e6b754fad029d6c35e139b907d04e6510775997b
2026-01-04T15:02:34.418809Z
false