1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2024-11-23 11:22:33 +01:00

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
This commit is contained in:
Dan Brown 2018-09-24 16:30:08 +01:00
parent 9abdab3991
commit 818c02ed44
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9

View 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