From 492e2f173e13e63bd3914ebee11c300ce9c9757b Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Mon, 23 Jan 2017 22:27:11 +0000 Subject: [PATCH] Fixed error causing permissions to be deleted on book sort Closes #282 --- app/Http/Controllers/BookController.php | 2 +- app/Services/PermissionService.php | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/BookController.php b/app/Http/Controllers/BookController.php index 57ac486d5..408192ff9 100644 --- a/app/Http/Controllers/BookController.php +++ b/app/Http/Controllers/BookController.php @@ -208,7 +208,7 @@ class BookController extends Controller } // Update permissions on changed models - $this->entityRepo->buildJointPermissions($updatedModels); + if (count($updatedModels) === 0) $this->entityRepo->buildJointPermissions($updatedModels); return redirect($book->getUrl()); } diff --git a/app/Services/PermissionService.php b/app/Services/PermissionService.php index 39a2c38be..72a810b6b 100644 --- a/app/Services/PermissionService.php +++ b/app/Services/PermissionService.php @@ -243,13 +243,14 @@ class PermissionService */ protected function deleteManyJointPermissionsForEntities($entities) { + if (count($entities) === 0) return; $query = $this->jointPermission->newQuery(); - foreach ($entities as $entity) { - $query->orWhere(function($query) use ($entity) { - $query->where('entity_id', '=', $entity->id) - ->where('entity_type', '=', $entity->getMorphClass()); - }); - } + foreach ($entities as $entity) { + $query->orWhere(function($query) use ($entity) { + $query->where('entity_id', '=', $entity->id) + ->where('entity_type', '=', $entity->getMorphClass()); + }); + } $query->delete(); }