]> BookStack Code Mirror - bookstack/blob - database/migrations/2016_09_29_101449_remove_hidden_roles.php
New translations editor.php (Welsh)
[bookstack] / database / migrations / 2016_09_29_101449_remove_hidden_roles.php
1 <?php
2
3 use Illuminate\Database\Migrations\Migration;
4 use Illuminate\Database\Schema\Blueprint;
5 use Illuminate\Support\Facades\Schema;
6
7 class RemoveHiddenRoles extends Migration
8 {
9     /**
10      * Run the migrations.
11      *
12      * @return void
13      */
14     public function up()
15     {
16         // Remove the hidden property from roles
17         Schema::table('roles', function (Blueprint $table) {
18             $table->dropColumn('hidden');
19         });
20
21         // Add column to mark system users
22         Schema::table('users', function (Blueprint $table) {
23             $table->string('system_name')->nullable()->index();
24         });
25
26         // Insert our new public system user.
27         $publicUserId = DB::table('users')->insertGetId([
28             'email'           => '[email protected]',
29             'name'            => 'Guest',
30             'system_name'     => 'public',
31             'email_confirmed' => true,
32             'created_at'      => \Carbon\Carbon::now(),
33             'updated_at'      => \Carbon\Carbon::now(),
34         ]);
35
36         // Get the public role
37         $publicRole = DB::table('roles')->where('system_name', '=', 'public')->first();
38
39         // Connect the new public user to the public role
40         DB::table('role_user')->insert([
41             'user_id' => $publicUserId,
42             'role_id' => $publicRole->id,
43         ]);
44     }
45
46     /**
47      * Reverse the migrations.
48      *
49      * @return void
50      */
51     public function down()
52     {
53         Schema::table('roles', function (Blueprint $table) {
54             $table->boolean('hidden')->default(false);
55             $table->index('hidden');
56         });
57
58         DB::table('users')->where('system_name', '=', 'public')->delete();
59
60         Schema::table('users', function (Blueprint $table) {
61             $table->dropColumn('system_name');
62         });
63
64         DB::table('roles')->where('system_name', '=', 'public')->update(['hidden' => true]);
65     }
66 }