public function delete($scopeId) { $scope = $this->scopeTable->get($scopeId); if (!empty($scope)) { // check whether the scope is used by an app or user $appScopes = $this->appScopeTable->getCount(new Condition(['scopeId', '=', $scope['id']])); if ($appScopes > 0) { throw new StatusCode\ConflictException('Scope is assigned to an app. Remove the scope from the app in order to delete the scope'); } $userScopes = $this->userScopeTable->getCount(new Condition(['scopeId', '=', $scope['id']])); if ($userScopes > 0) { throw new StatusCode\ConflictException('Scope is assgined to an user. Remove the scope from the user in order to delete the scope'); } // check whether this is a system scope if (in_array($scope['id'], [1, 2, 3])) { throw new StatusCode\BadRequestException('It is not possible to change this scope'); } try { $this->scopeTable->beginTransaction(); // delete all routes assigned to the scope $this->scopeRouteTable->deleteAllFromScope($scope['id']); $this->scopeTable->delete(array('id' => $scope['id'])); $this->scopeTable->commit(); } catch (\Exception $e) { $this->scopeTable->rollBack(); throw $e; } } else { throw new StatusCode\NotFoundException('Could not find scope'); } }