/** * 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; }
/** * Returns the roles assigned to the given user group * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read a user group * * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup * * @return \eZ\Publish\API\Repository\Values\User\UserGroupRoleAssignment[] */ public function getRoleAssignmentsForUserGroup(UserGroup $userGroup) { if (false === $this->repository->hasAccess('role', '*')) { throw new UnauthorizedExceptionStub('What error code should be used?'); } return $this->getRoleAssignmentsForContent($userGroup); }
/** * Empties trash. * * All locations contained in the trash will be removed. Content objects will be removed * if all locations of the content are gone. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to empty the trash */ public function emptyTrash() { if (false === $this->repository->hasAccess('content', 'remove')) { throw new UnauthorizedExceptionStub('What error code should be used?'); } $this->trashItems = array(); }
/** * Removes a relation of type COMMON from a draft. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination * * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent */ public function deleteRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent) { if (false === $this->repository->hasAccess('content', 'edit')) { throw new UnauthorizedExceptionStub('What error code should be used?'); } if (VersionInfo::STATUS_DRAFT !== $sourceVersion->status) { throw new BadStateExceptionStub('What error code should be used?'); } $relationNotFound = true; $relationNoCommon = true; foreach ($this->relation as $i => $relation) { if ($relation->getDestinationContentInfo() !== $destinationContent) { continue; } if ($relation->getSourceContentInfo() !== $sourceVersion->getContentInfo()) { continue; } $relationNotFound = false; if ($relation->type !== Relation::COMMON) { continue; } $relationNoCommon = false; unset($this->relation[$i]); break; } if ($relationNotFound || $relationNoCommon) { throw new InvalidArgumentExceptionStub('What error code should be used?'); } }
/** * Deletes a language from content repository * * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException * if language can not be deleted * because it is still assigned to some content / type / (...). * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If user does not have access to content translations * * @param \eZ\Publish\API\Repository\Values\Content\Language $language */ public function deleteLanguage(Language $language) { if (true !== $this->repository->hasAccess('content', 'translations')) { throw new UnauthorizedExceptionStub('What error code should be used?'); } if (count($this->contentService->loadContentInfoByLanguageCode($language->languageCode))) { throw new InvalidArgumentExceptionStub('What error code should be used?'); } unset($this->languages[$language->id], $this->codes[$language->languageCode]); }
/** * Sets the object-state of a state group to $state for the given content. * * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the object state does not belong to the given group * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to change the object state * * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup $objectStateGroup * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectState $objectState * */ public function setContentState(ContentInfo $contentInfo, ObjectStateGroup $objectStateGroup, ObjectState $objectState) { if (false === $this->repository->hasAccess('class', '*')) { throw new Exceptions\UnauthorizedExceptionStub('What error code should be used?'); } if ($objectState->getObjectStateGroup() != $objectStateGroup) { throw new Exceptions\InvalidArgumentExceptionStub('@todo: What error code should be used?'); } $this->objectStateMap[$contentInfo->id][$objectStateGroup->id] = $objectState->id; }
/** * Creates a new url wildcard * * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the $sourceUrl pattern already exists * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create url wildcards * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if the number of "*" patterns in $sourceUrl and * the numbers in {\d} placeholders in $destinationUrl does not match. * * @param string $sourceUrl * @param string $destinationUrl * @param boolean $forward * * @return \eZ\Publish\API\Repository\Values\Content\UrlWildcard */ public function create($sourceUrl, $destinationUrl, $forward = false) { if (false === $this->repository->hasAccess('content', 'edit')) { throw new UnauthorizedExceptionStub('What error code should be used?'); } foreach ($this->wildcards as $wildcard) { if ($wildcard->sourceUrl === $sourceUrl) { throw new InvalidArgumentExceptionStub('What error code should be used?'); } } preg_match_all('(\\*)', $sourceUrl, $patterns); preg_match_all('(\\{(\\d+)\\})', $destinationUrl, $placeholders); $patterns = array_map('intval', $patterns[0]); $placeholders = array_map('intval', $placeholders[1]); if (count($placeholders) > 0 && max($placeholders) > count($patterns)) { throw new ContentValidationExceptionStub('What error code should be used?'); } $wildcard = new URLWildcard(array('id' => ++$this->id, 'sourceUrl' => $sourceUrl, 'destinationUrl' => $destinationUrl, 'forward' => $forward)); return $this->wildcards[$wildcard->id] = $wildcard; }
/** * Deletes $section from content repository * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified section is not found * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to delete a section * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if section can not be deleted * because it is still assigned to some contents. * * @param \eZ\Publish\API\Repository\Values\Content\Section $section */ public function deleteSection(Section $section) { if (false === isset($this->sections[$section->id])) { throw new NotFoundExceptionStub('What error code should be used?'); } if (isset($this->assignedContents[$section->id])) { throw new BadStateExceptionStub('What error code should be used?'); } if (true !== $this->repository->hasAccess('section', 'edit')) { throw new UnauthorizedExceptionStub('What error code should be used?'); } unset($this->sections[$section->id], $this->identifiers[$section->identifier]); }
/** * Unassign a content type from a group. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to link a content type * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the content type is not assigned this the given group. * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If $contentTypeGroup is the last group assigned to the content type * * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup $contentTypeGroup */ public function unassignContentTypeGroup(ContentType $contentType, ContentTypeGroup $contentTypeGroup) { if (false === $this->repository->hasAccess('class', '*')) { throw new UnauthorizedExceptionStub('What error code should be used?'); } $typeData = $this->getTypeAsArray($this->types[$contentType->id]); $unassigned = false; foreach ($typeData['contentTypeGroups'] as $index => $assignedGroup) { if ($assignedGroup->id == $contentTypeGroup->id) { unset($typeData['contentTypeGroups'][$index]); $unassigned = true; } } if (!$unassigned) { throw new Exceptions\InvalidArgumentExceptionStub(); } if (empty($typeData['contentTypeGroups'])) { throw new Exceptions\BadStateExceptionStub(); } $this->types[$contentType->id] = new ContentTypeStub($typeData); }