/**
  * Returns list of role assignments for specific role and content.
  *
  * @param \eZ\Publish\API\Repository\Values\User\Role $role
  * @param int $contentId
  *
  * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment[]
  */
 private function getRoleAssignmentsForRoleAndContent(Role $role, $contentId)
 {
     $contentService = $this->repository->getContentService();
     $contentTypeService = $this->repository->getContentTypeService();
     $userService = $this->repository->getUserService();
     $contentType = $contentTypeService->loadContentType($contentService->loadContent($contentId)->contentTypeId);
     if ($contentType->identifier != 'user_group' && $contentType->identifier != 'user') {
         throw new \ErrorException("Implementation error, unknown contentType '{$contentType->identifier}'.");
     }
     $roleAssignments = array();
     foreach ($this->roleLimitations as $limit) {
         if ($limit['roleId'] == $role->id && $limit['contentId'] == $contentId) {
             $limitIdentifier = $limit['identifier'];
             if (!isset($roleAssignments[$limitIdentifier])) {
                 if ('user_group' === $contentType->identifier) {
                     $roleAssignments[$limitIdentifier] = new UserGroupRoleAssignmentStub(array('role' => $role, 'userGroup' => $userService->loadUserGroup($contentId), 'limitation' => $this->getOptionalRoleLimitation($role->id, $contentId, $limitIdentifier)));
                 } else {
                     if ('user' === $contentType->identifier) {
                         $roleAssignments[$limitIdentifier] = new UserRoleAssignmentStub(array('role' => $role, 'user' => $userService->loadUser($contentId), 'limitation' => $this->getOptionalRoleLimitation($role->id, $contentId, $limitIdentifier)));
                     }
                 }
             }
         }
     }
     if (empty($roleAssignments)) {
         if ('user_group' === $contentType->identifier) {
             $roleAssignments[] = new UserGroupRoleAssignmentStub(array('role' => $role, 'userGroup' => $userService->loadUserGroup($contentId), 'limitation' => null));
         } else {
             if ('user' === $contentType->identifier) {
                 $roleAssignments[] = new UserRoleAssignmentStub(array('role' => $role, 'user' => $userService->loadUser($contentId), 'limitation' => null));
             }
         }
     }
     return array_values($roleAssignments);
 }
 /**
  * Deletes $location and all its descendants.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to delete this location or a descendant
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  */
 public function deleteLocation(Location $location)
 {
     if (false === $this->repository->canUser('content', 'remove', $location)) {
         throw new UnauthorizedExceptionStub('What error code should be used?');
     }
     $this->repository->getUrlAliasService()->removeAliasesForLocation($location);
     $contentService = $this->repository->getContentService();
     unset($this->locations[$location->id]);
     if (!$this->hasLocation($location->contentInfo)) {
         $contentService->deleteContent($location->contentInfo);
     }
     foreach ($this->loadLocationChildren($location)->locations as $child) {
         $this->deleteLocation($child);
     }
 }
 /**
  * Auto-generates aliases for the given $location
  *
  * Old aliases will automatically be moved to history mode.
  *
  * ATTENTION: This method is not part of the Public API but is only used
  * internally in this implementation.
  *
  * @access private
  *
  * @internal
  *
  * @param Location $location
  *
  * @return void
  */
 public function createAliasesForLocation(Location $location)
 {
     $contentService = $this->repository->getContentService();
     $content = $contentService->loadContent($location->getContentInfo()->id);
     if ($content->getVersionInfo()->status !== VersionInfo::STATUS_PUBLISHED) {
         // Skip not yet published content
         return;
     }
     $versionInfo = $content->getVersionInfo();
     $contentInfo = $versionInfo->getContentInfo();
     $this->obsoleteOldAliases($location);
     foreach ($versionInfo->getNames() as $languageCode => $name) {
         $this->createInternalUrlAlias($location, $this->createUrlAliasPath($location, $name, $languageCode), $languageCode, $contentInfo->mainLanguageCode === $languageCode && $contentInfo->alwaysAvailable);
     }
 }
 /**
  * Updates a user
  *
  * 4.x: If the versionUpdateStruct is set in the user update structure, this method internally creates a content draft, updates ts with the provided data
  * and publishes the draft. If a draft is explicitly required, the user group can be updated via the content service methods.
  *
  * @param \eZ\Publish\API\Repository\Values\User\User $user
  * @param \eZ\Publish\API\Repository\Values\User\UserUpdateStruct $userUpdateStruct
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update the user
  * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userUpdateStruct is not valid
  * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set empty
  *
  * @return \eZ\Publish\API\Repository\Values\User\User
  */
 public function updateUser(User $user, UserUpdateStruct $userUpdateStruct)
 {
     if (false === $this->repository->canUser('content', 'edit', $user)) {
         throw new UnauthorizedExceptionStub('What error code should be used?');
     }
     $contentService = $this->repository->getContentService();
     $content = $contentService->loadContentByContentInfo($user->contentInfo);
     $contentUpdate = $userUpdateStruct->contentUpdateStruct;
     if ($contentUpdate === null) {
         $contentUpdate = $contentService->newContentUpdateStruct();
         foreach ($content->getFields() as $field) {
             $contentUpdate->setField($field->fieldDefIdentifier, $field->value, $field->languageCode);
         }
         $contentUpdate->setField('user_account', $user);
     }
     $contentDraft = $contentService->createContentDraft($user->contentInfo);
     $contentDraft = $contentService->updateContent($contentDraft->getVersionInfo(), $contentUpdate);
     $content = $contentService->publishVersion($contentDraft->getVersionInfo());
     if ($userUpdateStruct->contentMetadataUpdateStruct) {
         $content = $contentService->updateContentMetadata($content->contentInfo, $userUpdateStruct->contentMetadataUpdateStruct);
     }
     $this->users[$user->id] = new UserStub(array('login' => $user->login, 'email' => $userUpdateStruct->email ?: $user->email, 'enabled' => is_null($userUpdateStruct->enabled) ? $user->enabled : $userUpdateStruct->enabled, 'maxLogin' => is_null($userUpdateStruct->maxLogin) ? $user->maxLogin : $userUpdateStruct->maxLogin, 'hashAlgorithm' => $user->hashAlgorithm, 'passwordHash' => $userUpdateStruct->password ? $this->createHash($user->login, $userUpdateStruct->password, $user->hashAlgorithm) : $user->passwordHash, 'content' => $content));
     return $this->users[$user->id];
 }