From 818c02ed44627b3339601943b4c003ef33b45f59 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Mon, 24 Sep 2018 16:30:08 +0100 Subject: [PATCH] Added null role check to migrate path Also added check for existing bookshelf role_permissions in the event the user got that for. Also related to #1027 --- .../2018_08_04_115700_create_bookshelves_table.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/database/migrations/2018_08_04_115700_create_bookshelves_table.php b/database/migrations/2018_08_04_115700_create_bookshelves_table.php index 497730879..e4dca8c0b 100644 --- a/database/migrations/2018_08_04_115700_create_bookshelves_table.php +++ b/database/migrations/2018_08_04_115700_create_bookshelves_table.php @@ -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