本文整理汇总了PHP中eZ\Publish\API\Repository\Repository::beginTransaction方法的典型用法代码示例。如果您正苦于以下问题:PHP Repository::beginTransaction方法的具体用法?PHP Repository::beginTransaction怎么用?PHP Repository::beginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZ\Publish\API\Repository\Repository
的用法示例。
在下文中一共展示了Repository::beginTransaction方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: unAssignUserFromUserGroup
/**
* Removes a user group from the user
*
* @param \eZ\Publish\API\Repository\Values\User\User $user
* @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup
*
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove the user group from the user
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the user is not in the given user group
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If $userGroup is the last assigned user group
*/
public function unAssignUserFromUserGroup(APIUser $user, APIUserGroup $userGroup)
{
$loadedUser = $this->loadUser($user->id);
$loadedGroup = $this->loadUserGroup($userGroup->id);
$locationService = $this->repository->getLocationService();
$userLocations = $locationService->loadLocations($loadedUser->getVersionInfo()->getContentInfo());
if (empty($userLocations)) {
throw new BadStateException("user", "user has no locations, cannot unassign from group");
}
if ($loadedGroup->getVersionInfo()->getContentInfo()->mainLocationId === null) {
throw new BadStateException("userGroup", "user group has no main location or no locations, cannot unassign");
}
foreach ($userLocations as $userLocation) {
if ($userLocation->parentLocationId == $loadedGroup->getVersionInfo()->getContentInfo()->mainLocationId) {
// Throw this specific BadState when we know argument is valid
if (count($userLocations) === 1) {
throw new BadStateException("user", "user only has one user group, cannot unassign from last group");
}
$this->repository->beginTransaction();
try {
$locationService->deleteLocation($userLocation);
$this->repository->commit();
return;
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}
}
throw new InvalidArgumentException("userGroup", "user is not in the given user group");
}
示例2: publishContentTypeDraft
/**
* Publish the content type and update content objects.
*
* This method updates content objects, depending on the changed field definitions.
*
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If the content type has no draft
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the content type has no field definitions
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish a content type
*
* @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft $contentTypeDraft
*/
public function publishContentTypeDraft(APIContentTypeDraft $contentTypeDraft)
{
if ($this->repository->hasAccess('class', 'update') !== true) {
throw new UnauthorizedException('ContentType', 'update');
}
try {
$loadedContentTypeDraft = $this->loadContentTypeDraft($contentTypeDraft->id);
} catch (APINotFoundException $e) {
throw new BadStateException("\$contentTypeDraft", "The content type does not have a draft.", $e);
}
if (count($loadedContentTypeDraft->getFieldDefinitions()) === 0) {
throw new InvalidArgumentException("\$contentTypeDraft", "The content type draft should have at least one field definition.");
}
$this->repository->beginTransaction();
try {
if (empty($loadedContentTypeDraft->nameSchema)) {
$fieldDefinitions = $loadedContentTypeDraft->getFieldDefinitions();
$this->contentTypeHandler->update($contentTypeDraft->id, $contentTypeDraft->status, $this->buildSPIContentTypeUpdateStruct($loadedContentTypeDraft, new ContentTypeUpdateStruct(array("nameSchema" => "<" . $fieldDefinitions[0]->identifier . ">"))));
}
$this->contentTypeHandler->publish($loadedContentTypeDraft->id);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}
示例3: unassignRoleFromUser
/**
* removes a role from the given user.
*
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a role
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the role is not assigned to the user
*
* @param \eZ\Publish\API\Repository\Values\User\Role $role
* @param \eZ\Publish\API\Repository\Values\User\User $user
*/
public function unassignRoleFromUser(APIRole $role, User $user)
{
if ($this->repository->canUser('role', 'assign', $user, $role) !== true) {
throw new UnauthorizedException('role', 'assign');
}
$spiRoleAssignments = $this->userHandler->loadRoleAssignmentsByGroupId($user->id);
$isAssigned = false;
foreach ($spiRoleAssignments as $spiRoleAssignment) {
if ($spiRoleAssignment->roleId === $role->id) {
$isAssigned = true;
break;
}
}
if (!$isAssigned) {
throw new InvalidArgumentException("\$user", "Role is not assigned to the given User");
}
$this->repository->beginTransaction();
try {
$this->userHandler->unAssignRole($user->id, $role->id);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}
示例4: beginTransaction
/**
* Begin transaction
*
* Begins an transaction, make sure you'll call commit or rollback when done,
* otherwise work will be lost.
*/
public function beginTransaction()
{
$return = $this->repository->beginTransaction();
if ($this->signalDispatcher instanceof TransactionHandler) {
$this->signalDispatcher->beginTransaction();
}
return $return;
}
示例5: remove
/**
* removes an url wildcard.
*
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove url wildcards
*
* @param \eZ\Publish\API\Repository\Values\Content\UrlWildcard $urlWildcard the url wildcard to remove
*/
public function remove(URLWildcard $urlWildcard)
{
if ($this->repository->hasAccess('content', 'urltranslator') !== true) {
throw new UnauthorizedException('content', 'urltranslator');
}
$this->repository->beginTransaction();
try {
$this->urlWildcardHandler->remove($urlWildcard->id);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}
示例6: removeRoleAssignment
/**
* Removes the given role assignment.
*
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a role assignment
*
* @param \eZ\Publish\API\Repository\Values\User\RoleAssignment $roleAssignment
*/
public function removeRoleAssignment(RoleAssignment $roleAssignment)
{
if ($this->repository->canUser('role', 'assign', $roleAssignment) !== true) {
throw new UnauthorizedException('role', 'assign');
}
$spiRoleAssignment = $this->userHandler->loadRoleAssignment($roleAssignment->id);
$this->repository->beginTransaction();
try {
$this->userHandler->removeRoleAssignment($spiRoleAssignment->id);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}
示例7: deleteTrashItem
/**
* Deletes a trash item.
*
* The corresponding content object will be removed
*
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to delete this trash item
*
* @param \eZ\Publish\API\Repository\Values\Content\TrashItem $trashItem
*/
public function deleteTrashItem(APITrashItem $trashItem)
{
if ($this->repository->hasAccess('content', 'cleantrash') !== true) {
throw new UnauthorizedException('content', 'cleantrash');
}
if (!is_numeric($trashItem->id)) {
throw new InvalidArgumentValue("id", $trashItem->id, "TrashItem");
}
$this->repository->beginTransaction();
try {
$this->persistenceHandler->trashHandler()->deleteTrashItem($trashItem->id);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}
示例8: removeAliases
/**
* Removes urls aliases.
*
* This method does not remove autogenerated aliases for locations.
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if alias list contains
* autogenerated alias
*
* @param \eZ\Publish\API\Repository\Values\Content\URLAlias[] $aliasList
*/
public function removeAliases(array $aliasList)
{
$spiUrlAliasList = array();
foreach ($aliasList as $alias) {
if (!$alias->isCustom) {
throw new InvalidArgumentException('$aliasList', 'Alias list contains autogenerated alias');
}
$spiUrlAliasList[] = $this->buildSPIUrlAlias($alias);
}
$this->repository->beginTransaction();
try {
$this->urlAliasHandler->removeURLAliases($spiUrlAliasList);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}
示例9: deleteLanguage
/**
* 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 ($this->repository->hasAccess('content', 'translations') !== true) {
throw new UnauthorizedException('content', 'translations');
}
$loadedLanguage = $this->loadLanguageById($language->id);
$this->repository->beginTransaction();
try {
$this->languageHandler->delete($loadedLanguage->id);
$this->repository->commit();
} catch (LogicException $e) {
$this->repository->rollback();
throw new InvalidArgumentException("language", $e->getMessage(), $e);
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}
示例10: deleteSection
/**
* 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 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)
{
$loadedSection = $this->loadSection($section->id);
if ($this->repository->canUser('section', 'edit', $loadedSection) !== true) {
throw new UnauthorizedException('section', 'edit', array('name' => $loadedSection->name));
}
if ($this->countAssignedContents($loadedSection) > 0) {
throw new BadStateException("section", 'section is still assigned to content');
}
$this->repository->beginTransaction();
try {
$this->sectionHandler->delete($loadedSection->id);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}
示例11: setContentState
/**
* 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, APIObjectStateGroup $objectStateGroup, APIObjectState $objectState)
{
if ($this->repository->canUser('state', 'assign', $contentInfo, $objectState) !== true) {
throw new UnauthorizedException('state', 'assign', array('contentId' => $contentInfo->id));
}
$loadedObjectState = $this->loadObjectState($objectState->id);
if ($loadedObjectState->getObjectStateGroup()->id != $objectStateGroup->id) {
throw new InvalidArgumentException('objectState', 'Object state does not belong to the given group');
}
$this->repository->beginTransaction();
try {
$this->objectStateHandler->setContentState($contentInfo->id, $objectStateGroup->id, $loadedObjectState->id);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}
示例12: deleteTag
/**
* Deletes $tag and all its descendants and synonyms.
*
* If $tag is a synonym, only the synonym is deleted
*
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to delete this tag
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified tag is not found
*
* @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag
*/
public function deleteTag(Tag $tag)
{
if ($tag->mainTagId > 0) {
if ($this->hasAccess('tags', 'deletesynonym') !== true) {
throw new UnauthorizedException('tags', 'deletesynonym');
}
} else {
if ($this->hasAccess('tags', 'delete') !== true) {
throw new UnauthorizedException('tags', 'delete');
}
}
$this->repository->beginTransaction();
try {
$this->tagsHandler->deleteTag($tag->id);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}
示例13: deleteSection
/**
* 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 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,
* or because it is still being used in policy limitations.
*
* @param \eZ\Publish\API\Repository\Values\Content\Section $section
*/
public function deleteSection(Section $section)
{
$loadedSection = $this->loadSection($section->id);
if ($this->repository->canUser('section', 'edit', $loadedSection) !== true) {
throw new UnauthorizedException('section', 'edit', array('sectionId' => $loadedSection->id));
}
if ($this->sectionHandler->assignmentsCount($loadedSection->id) > 0) {
throw new BadStateException('section', 'section is still assigned to content');
}
if ($this->sectionHandler->policiesCount($loadedSection->id) > 0) {
throw new BadStateException('section', 'section is still being used in policy limitations');
}
$this->repository->beginTransaction();
try {
$this->sectionHandler->delete($loadedSection->id);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}