eZ\Publish\Core\REST\Server\Controller\Role::deletePolicy PHP 메소드

deletePolicy() 공개 메소드

Delete a policy from role.
public deletePolicy ( $roleId, $policyId, Request $request ) : eZ\Publish\Core\REST\Server\Values\NoContent
$roleId int ID of a role or a role draft
$policyId int ID of a policy
$request Symfony\Component\HttpFoundation\Request
리턴 eZ\Publish\Core\REST\Server\Values\NoContent
    public function deletePolicy($roleId, $policyId, Request $request)
    {
        try {
            // First try to treat $roleId as a role draft ID.
            $roleDraft = $this->roleService->loadRoleDraft($roleId);
            $policy = null;
            foreach ($roleDraft->getPolicies() as $rolePolicy) {
                if ($rolePolicy->id == $policyId) {
                    $policy = $rolePolicy;
                    break;
                }
            }
            if ($policy !== null) {
                $this->roleService->removePolicyByRoleDraft($roleDraft, $policy);
                return new Values\NoContent();
            }
        } catch (NotFoundException $e) {
            // Then try to treat $roleId as a role ID.
            $role = $this->roleService->loadRole($roleId);
            $policy = null;
            foreach ($role->getPolicies() as $rolePolicy) {
                if ($rolePolicy->id == $policyId) {
                    $policy = $rolePolicy;
                    break;
                }
            }
            if ($policy !== null) {
                $this->roleService->deletePolicy($policy);
                return new Values\NoContent();
            }
        }
        throw new Exceptions\NotFoundException("Policy not found: '{$request->getPathInfo()}'.");
    }