public function updateRoleDraft(APIRoleDraft $roleDraft, RoleUpdateStruct $roleUpdateStruct)
    {
        if ($roleUpdateStruct->identifier !== null && !is_string($roleUpdateStruct->identifier)) {
            throw new InvalidArgumentValue('identifier', $roleUpdateStruct->identifier, 'RoleUpdateStruct');
        }

        $loadedRoleDraft = $this->loadRoleDraft($roleDraft->id);

        if ($this->repository->hasAccess('role', 'update') !== true) {
            throw new UnauthorizedException('role', 'update');
        }

        if ($roleUpdateStruct->identifier !== null) {
            try {
                /* Throw exception if:
                 * - A published role with the same identifier exists, AND
                 * - The ID of the published role does not match the original ID of the draft
                */
                $existingSPIRole = $this->userHandler->loadRoleByIdentifier($roleUpdateStruct->identifier);
                $SPIRoleDraft = $this->userHandler->loadRole($loadedRoleDraft->id, Role::STATUS_DRAFT);
                if ($existingSPIRole->id != $SPIRoleDraft->originalId) {
                    throw new InvalidArgumentException(
                        '$roleUpdateStruct',
                        "Role '{$existingSPIRole->id}' with the specified identifier '{$roleUpdateStruct->identifier}' " .
                        'already exists'
                    );
                }
            } catch (APINotFoundException $e) {
                // Do nothing
            }
        }

        $this->repository->beginTransaction();
        try {
            $this->userHandler->updateRole(
                new SPIRoleUpdateStruct(
                    array(
                        'id' => $loadedRoleDraft->id,
                        'identifier' => $roleUpdateStruct->identifier ?: $loadedRoleDraft->identifier,
                    )
                )
            );
            $this->repository->commit();
        } catch (Exception $e) {
            $this->repository->rollback();
            throw $e;
        }

        return $this->loadRoleDraft($loadedRoleDraft->id);
    }
public function updateRoleDraft(APIRoleDraft $roleDraft, RoleUpdateStruct $roleUpdateStruct)
    {
        if ($roleUpdateStruct->identifier !== null && !is_string($roleUpdateStruct->identifier)) {
            throw new InvalidArgumentValue('identifier', $roleUpdateStruct->identifier, 'RoleUpdateStruct');
        }

        $loadedRoleDraft = $this->loadRoleDraft($roleDraft->id);

        if ($this->repository->hasAccess('role', 'update') !== true) {
            throw new UnauthorizedException('role', 'update');
        }

        if ($roleUpdateStruct->identifier !== null) {
            try {
                /* Throw exception if:
                 * - A published role with the same identifier exists, AND
                 * - The ID of the published role does not match the original ID of the draft
                */
                $existingSPIRole = $this->userHandler->loadRoleByIdentifier($roleUpdateStruct->identifier);
                $SPIRoleDraft = $this->userHandler->loadRole($loadedRoleDraft->id, Role::STATUS_DRAFT);
                if ($existingSPIRole->id != $SPIRoleDraft->originalId) {
                    throw new InvalidArgumentException(
                        '$roleUpdateStruct',
                        "Role '{$existingSPIRole->id}' with the specified identifier '{$roleUpdateStruct->identifier}' " .
                        'already exists'
                    );
                }
            } catch (APINotFoundException $e) {
                // Do nothing
            }
        }

        $this->repository->beginTransaction();
        try {
            $this->userHandler->updateRole(
                new SPIRoleUpdateStruct(
                    array(
                        'id' => $loadedRoleDraft->id,
                        'identifier' => $roleUpdateStruct->identifier ?: $loadedRoleDraft->identifier,
                    )
                )
            );
            $this->repository->commit();
        } catch (Exception $e) {
            $this->repository->rollback();
            throw $e;
        }

        return $this->loadRoleDraft($loadedRoleDraft->id);
    }
public function updateRoleDraft ( APIRoleDraft $ roleDraft , RoleUpdateStruct $ roleUpdateStruct ) { if ( $ roleUpdateStruct -> identifier !== null && ! is_string ( $ roleUpdateStruct -> identifier ) ) { throw new InvalidArgumentValue ( 'identifier' , $ roleUpdateStruct -> identifier , 'RoleUpdateStruct' ) ; } $ loadedRoleDraft = $ this -> loadRoleDraft ( $ roleDraft -> id ) ; if ( $ this -> repository -> hasAccess ( 'role' , 'update' ) !== true ) { throw new UnauthorizedException ( 'role' , 'update' ) ; } if ( $ roleUpdateStruct -> identifier !== null ) { try { /* Throw exception if:
                 * - A published role with the same identifier exists, AND
                 * - The ID of the published role does not match the original ID of the draft
                */ $ existingSPIRole = $ this -> userHandler -> loadRoleByIdentifier ( $ roleUpdateStruct -> identifier ) ; $ SPIRoleDraft = $ this -> userHandler -> loadRole ( $ loadedRoleDraft -> id , Role :: STATUS_DRAFT ) ; if ( $ existingSPIRole -> id != $ SPIRoleDraft -> originalId ) { throw new InvalidArgumentException ( '$roleUpdateStruct' , "Role '{$existingSPIRole->id}' with the specified identifier '{$roleUpdateStruct->identifier}' " . 'already exists' ) ; } } catch ( APINotFoundException $ e ) { // Do nothing } } $ this -> repository -> beginTransaction ( ) ; try { $ this -> userHandler -> updateRole ( new SPIRoleUpdateStruct ( array ( 'id' => $ loadedRoleDraft -> id , 'identifier' => $ roleUpdateStruct -> identifier ? : $ loadedRoleDraft -> identifier , ) ) ) ; $ this -> repository -> commit ( ) ; } catch ( Exception $ e ) { $ this -> repository -> rollback ( ) ; throw $ e ; } return $ this -> loadRoleDraft ( $ loadedRoleDraft -> id ) ; }
Updates the properties of a RoleDraft.

@since 6.0

@throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a RoleDraft
@throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the identifier of the RoleDraft already exists

@param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft
@param \eZ\Publish\API\Repository\Values\User\RoleUpdateStruct $roleUpdateStruct

@return \eZ\Publish\API\Repository\Values\User\RoleDraft
Updates the properties of a RoleDraft .