Fixed error causing permissions to be deleted on book sort

Closes #282
This commit is contained in:
Dan Brown 2017-01-23 22:27:11 +00:00
parent 380f0f2042
commit 492e2f173e
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 8 additions and 7 deletions

View File

@ -208,7 +208,7 @@ class BookController extends Controller
} }
// Update permissions on changed models // Update permissions on changed models
$this->entityRepo->buildJointPermissions($updatedModels); if (count($updatedModels) === 0) $this->entityRepo->buildJointPermissions($updatedModels);
return redirect($book->getUrl()); return redirect($book->getUrl());
} }

View File

@ -243,13 +243,14 @@ class PermissionService
*/ */
protected function deleteManyJointPermissionsForEntities($entities) protected function deleteManyJointPermissionsForEntities($entities)
{ {
if (count($entities) === 0) return;
$query = $this->jointPermission->newQuery(); $query = $this->jointPermission->newQuery();
foreach ($entities as $entity) { foreach ($entities as $entity) {
$query->orWhere(function($query) use ($entity) { $query->orWhere(function($query) use ($entity) {
$query->where('entity_id', '=', $entity->id) $query->where('entity_id', '=', $entity->id)
->where('entity_type', '=', $entity->getMorphClass()); ->where('entity_type', '=', $entity->getMorphClass());
}); });
} }
$query->delete(); $query->delete();
} }