eZ\Publish\Core\REST\Server\Controller\Role::updatePolicy PHP Method

updatePolicy() public method

Updates a policy.
public updatePolicy ( $roleId, $policyId, Request $request ) : eZ\Publish\API\Repository\Values\User\Policy
$roleId int ID of a role or a role draft
$policyId int ID of a policy
$request Symfony\Component\HttpFoundation\Request
return eZ\Publish\API\Repository\Values\User\Policy
    public function updatePolicy($roleId, $policyId, Request $request)
    {
        $updateStruct = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type')), $request->getContent()));
        try {
            // First try to treat $roleId as a role draft ID.
            $role = $this->roleService->loadRoleDraft($roleId);
            foreach ($role->getPolicies() as $policy) {
                if ($policy->id == $policyId) {
                    try {
                        return $this->roleService->updatePolicy($policy, $updateStruct);
                    } catch (LimitationValidationException $e) {
                        throw new BadRequestException($e->getMessage());
                    }
                }
            }
        } catch (NotFoundException $e) {
            // Then try to treat $roleId as a role ID.
            $role = $this->roleService->loadRole($roleId);
            foreach ($role->getPolicies() as $policy) {
                if ($policy->id == $policyId) {
                    try {
                        return $this->roleService->updatePolicy($policy, $updateStruct);
                    } catch (LimitationValidationException $e) {
                        throw new BadRequestException($e->getMessage());
                    }
                }
            }
        }
        throw new Exceptions\NotFoundException("Policy not found: '{$request->getPathInfo()}'.");
    }