]> BookStack Code Mirror - bookstack/commitdiff
Added null role check to migrate path
authorDan Brown <redacted>
Mon, 24 Sep 2018 15:30:08 +0000 (16:30 +0100)
committerDan Brown <redacted>
Mon, 24 Sep 2018 15:30:08 +0000 (16:30 +0100)
Also added check for existing bookshelf role_permissions
in the event the user got that for.
Also related to #1027

database/migrations/2018_08_04_115700_create_bookshelves_table.php

index 497730879b8d3536ca8b3ef1648a9a9af192d279..e4dca8c0b00a41460c6080aad2e60803ac6b5f63 100644 (file)
@@ -65,6 +65,10 @@ class CreateBookshelvesTable extends Migration
                 ->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) {
@@ -81,7 +85,9 @@ class CreateBookshelvesTable extends Migration
                 'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
             ]);
 
-            $rowsToInsert = $roleIdsWithBookPermission->map(function($roleId) use ($permId) {
+            $rowsToInsert = $roleIdsWithBookPermission->filter(function($roleId) {
+                return !is_null($roleId);
+            })->map(function($roleId) use ($permId) {
                 return [
                     'role_id' => $roleId,
                     'permission_id' => $permId