]> BookStack Code Mirror - bookstack/blob - database/migrations/2019_07_07_112515_add_template_support.php
ae26985ed8d5e111ca9e027c657f7e1f75fdc47a
[bookstack] / database / migrations / 2019_07_07_112515_add_template_support.php
1 <?php
2
3 use Carbon\Carbon;
4 use Illuminate\Database\Migrations\Migration;
5 use Illuminate\Database\Schema\Blueprint;
6 use Illuminate\Support\Facades\Schema;
7
8 class AddTemplateSupport extends Migration
9 {
10     /**
11      * Run the migrations.
12      *
13      * @return void
14      */
15     public function up()
16     {
17         Schema::table('pages', function (Blueprint $table) {
18             $table->boolean('template')->default(false);
19             $table->index('template');
20         });
21
22         // Create new templates-manage permission and assign to admin role
23         $adminRoleId = DB::table('roles')->where('system_name', '=', 'admin')->first()->id;
24         $permissionId = DB::table('role_permissions')->insertGetId([
25             'name'         => 'templates-manage',
26             'display_name' => 'Manage Page Templates',
27             'created_at'   => Carbon::now()->toDateTimeString(),
28             'updated_at'   => Carbon::now()->toDateTimeString(),
29         ]);
30         DB::table('permission_role')->insert([
31             'role_id'       => $adminRoleId,
32             'permission_id' => $permissionId,
33         ]);
34     }
35
36     /**
37      * Reverse the migrations.
38      *
39      * @return void
40      */
41     public function down()
42     {
43         Schema::table('pages', function (Blueprint $table) {
44             $table->dropColumn('template');
45         });
46
47         // Remove templates-manage permission
48         $templatesManagePermission = DB::table('role_permissions')
49             ->where('name', '=', 'templates-manage')->first();
50
51         DB::table('permission_role')->where('permission_id', '=', $templatesManagePermission->id)->delete();
52         DB::table('role_permissions')->where('name', '=', 'templates-manage')->delete();
53     }
54 }