/**
  * Create a new user. The created user is published by this method
  *
  * @param \eZ\Publish\API\Repository\Values\User\UserCreateStruct $userCreateStruct the data used for creating the user
  * @param array $parentGroups the groups of type {@link \eZ\Publish\API\Repository\Values\User\UserGroup} which are assigned to the user after creation
  *
  * @return \eZ\Publish\API\Repository\Values\User\User
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to move the user group
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a user group was not found
  * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userCreateStruct is not valid
  * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a user with provided login already exists
  */
 public function createUser(UserCreateStruct $userCreateStruct, array $parentGroups)
 {
     if (false === $this->repository->hasAccess('content', 'create')) {
         throw new UnauthorizedExceptionStub('What error code should be used?');
     }
     foreach ($this->users as $user) {
         if ($user->login == $userCreateStruct->login) {
             throw new InvalidArgumentExceptionStub('What error code should be used?');
         }
     }
     $contentService = $this->repository->getContentService();
     $locationService = $this->repository->getLocationService();
     $locationCreateStruts = array();
     foreach ($parentGroups as $parentGroup) {
         if (false === $this->repository->canUser('content', 'edit', $parentGroup)) {
             throw new UnauthorizedExceptionStub('What error code should be used?');
         }
         $locationCreateStruts[] = $locationService->newLocationCreateStruct($parentGroup->contentInfo->mainLocationId);
     }
     // Seems the is a back reference in the content object
     $userCreateStruct->setField('user_account', new UserStub());
     $draft = $contentService->createContent($userCreateStruct, $locationCreateStruts);
     $content = $contentService->publishVersion($draft->getVersionInfo());
     $user = new UserStub(array('login' => $userCreateStruct->login, 'email' => $userCreateStruct->email, 'passwordHash' => $this->createHash($userCreateStruct->login, $userCreateStruct->password, 2), 'hashAlgorithm' => 2, 'enabled' => $userCreateStruct->enabled, 'content' => $content));
     $this->users[$user->id] = $user;
     foreach ($parentGroups as $parentGroup) {
         $this->assignUserToUserGroup($user, $parentGroup);
     }
     return $user;
 }
 /**
  * Copies the content to a new location. If no version is given,
  * all versions are copied, otherwise only the given version.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location
  *
  * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
  * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to
  * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Content
  */
 public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, VersionInfo $versionInfo = null)
 {
     if (false === $this->repository->hasAccess('content', 'edit')) {
         throw new UnauthorizedExceptionStub('What error code should be used?');
     }
     ++$this->contentNextId;
     $versionNo = $versionInfo ? $versionInfo->versionNo : null;
     $this->contentInfo[$this->contentNextId] = new ContentInfoStub(array('id' => $this->contentNextId, 'remoteId' => md5(uniqid($contentInfo->remoteId, true)), 'sectionId' => $contentInfo->sectionId, 'alwaysAvailable' => $contentInfo->alwaysAvailable, 'currentVersionNo' => $versionNo ? 1 : $contentInfo->currentVersionNo, 'mainLanguageCode' => $contentInfo->mainLanguageCode, 'modificationDate' => new \DateTime(), 'ownerId' => $contentInfo->ownerId, 'published' => $contentInfo->published, 'publishedDate' => new \DateTime(), 'mainLocationId' => $contentInfo->mainLocationId, 'contentTypeId' => $contentInfo->contentTypeId, 'repository' => $this->repository));
     foreach ($this->versionInfo as $versionInfoStub) {
         if ($versionInfoStub->contentId !== $contentInfo->id) {
             continue;
         }
         if ($versionNo && $versionInfoStub->versionNo !== $versionNo) {
             continue;
         }
         ++$this->versionNextId;
         $this->versionInfo[$this->versionNextId] = new VersionInfoStub(array('id' => $this->versionNextId, 'status' => VersionInfo::STATUS_DRAFT, 'versionNo' => $versionNo ? 1 : $versionInfoStub->versionNo, 'creatorId' => $versionInfoStub->creatorId, 'creationDate' => new \DateTime(), 'modificationDate' => new \DateTime(), 'languageCodes' => $versionInfoStub->languageCodes, 'initialLanguageCode' => $versionInfoStub->initialLanguageCode, 'names' => $versionInfoStub->getNames(), 'contentId' => $this->contentNextId, 'repository' => $this->repository));
     }
     foreach ($this->content as $content) {
         if ($content->id !== $contentInfo->id) {
             continue;
         }
         if ($versionNo && $content->versionNo !== $versionNo) {
             continue;
         }
         $this->content[] = $this->copyContentObject($content, array('id' => $this->contentNextId, 'versionNo' => $versionNo ? 1 : $content->versionNo));
     }
     $locationService = $this->repository->getLocationService();
     $location = $locationService->createLocation($this->contentInfo[$this->contentNextId], $destinationLocationCreateStruct);
     $this->repository->getUrlAliasService()->createAliasesForLocation($location);
     return $this->loadContent($this->contentNextId);
 }
 /**
  * Creates the path for an alias to $location with $name in $languageCode
  *
  * @param Location $location
  * @param mixed $name
  * @param mixed $languageCode
  *
  * @return string
  */
 private function createUrlAliasPath(Location $location, $name, $languageCode)
 {
     $locationService = $this->repository->getLocationService();
     $parentPath = '';
     // 1 is the root location, which simply does not have aliases
     if ($location->parentLocationId !== 1) {
         $parentAliases = $this->listLocationAliases($locationService->loadLocation($location->parentLocationId), false);
         $parentAlias = $this->guessCorrectParent($parentAliases, $languageCode);
         $parentPath = $parentAlias->path;
     }
     return $parentPath . '/' . $this->generateAliasName($name);
 }