eZ\Publish\Core\Repository\UserService::moveUserGroup PHP Method

moveUserGroup() public method

Moves the user group to another parent.
public moveUserGroup ( eZ\Publish\API\Repository\Values\User\UserGroup $userGroup, eZ\Publish\API\Repository\Values\User\UserGroup $newParent )
$userGroup eZ\Publish\API\Repository\Values\User\UserGroup
$newParent eZ\Publish\API\Repository\Values\User\UserGroup
    public function moveUserGroup(APIUserGroup $userGroup, APIUserGroup $newParent)
    {
        $loadedUserGroup = $this->loadUserGroup($userGroup->id);
        $loadedNewParent = $this->loadUserGroup($newParent->id);
        $locationService = $this->repository->getLocationService();
        if ($loadedUserGroup->getVersionInfo()->getContentInfo()->mainLocationId === null) {
            throw new BadStateException('userGroup', 'existing user group is not stored and/or does not have any location yet');
        }
        if ($loadedNewParent->getVersionInfo()->getContentInfo()->mainLocationId === null) {
            throw new BadStateException('newParent', 'new user group is not stored and/or does not have any location yet');
        }
        $userGroupMainLocation = $locationService->loadLocation($loadedUserGroup->getVersionInfo()->getContentInfo()->mainLocationId);
        $newParentMainLocation = $locationService->loadLocation($loadedNewParent->getVersionInfo()->getContentInfo()->mainLocationId);
        $this->repository->beginTransaction();
        try {
            $locationService->moveSubtree($userGroupMainLocation, $newParentMainLocation);
            $this->repository->commit();
        } catch (Exception $e) {
            $this->repository->rollback();
            throw $e;
        }
    }