| @@ 978-1009 (lines=32) @@ | ||
| 975 | * |
|
| 976 | * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft |
|
| 977 | */ |
|
| 978 | public function createContentTypeDraft(APIContentType $contentType) |
|
| 979 | { |
|
| 980 | if (!$this->permissionResolver->canUser('class', 'create', $contentType)) { |
|
| 981 | throw new UnauthorizedException('ContentType', 'create'); |
|
| 982 | } |
|
| 983 | ||
| 984 | try { |
|
| 985 | $this->contentTypeHandler->load( |
|
| 986 | $contentType->id, |
|
| 987 | SPIContentType::STATUS_DRAFT |
|
| 988 | ); |
|
| 989 | ||
| 990 | throw new BadStateException( |
|
| 991 | '$contentType', |
|
| 992 | 'Draft of the ContentType already exists' |
|
| 993 | ); |
|
| 994 | } catch (APINotFoundException $e) { |
|
| 995 | $this->repository->beginTransaction(); |
|
| 996 | try { |
|
| 997 | $spiContentType = $this->contentTypeHandler->createDraft( |
|
| 998 | $this->permissionResolver->getCurrentUserReference()->getUserId(), |
|
| 999 | $contentType->id |
|
| 1000 | ); |
|
| 1001 | $this->repository->commit(); |
|
| 1002 | } catch (Exception $e) { |
|
| 1003 | $this->repository->rollback(); |
|
| 1004 | throw $e; |
|
| 1005 | } |
|
| 1006 | } |
|
| 1007 | ||
| 1008 | return $this->contentTypeDomainMapper->buildContentTypeDraftDomainObject($spiContentType); |
|
| 1009 | } |
|
| 1010 | ||
| 1011 | /** |
|
| 1012 | * Update a Content Type object. |
|
| @@ 289-314 (lines=26) @@ | ||
| 286 | * |
|
| 287 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup $contentTypeGroup |
|
| 288 | */ |
|
| 289 | public function deleteContentTypeGroup(APIContentTypeGroup $contentTypeGroup) |
|
| 290 | { |
|
| 291 | if (!$this->permissionResolver->canUser('class', 'delete', $contentTypeGroup)) { |
|
| 292 | throw new UnauthorizedException('ContentType', 'delete'); |
|
| 293 | } |
|
| 294 | ||
| 295 | $loadedContentTypeGroup = $this->loadContentTypeGroup($contentTypeGroup->id); |
|
| 296 | ||
| 297 | $this->repository->beginTransaction(); |
|
| 298 | try { |
|
| 299 | $this->contentTypeHandler->deleteGroup( |
|
| 300 | $loadedContentTypeGroup->id |
|
| 301 | ); |
|
| 302 | $this->repository->commit(); |
|
| 303 | } catch (APIBadStateException $e) { |
|
| 304 | $this->repository->rollback(); |
|
| 305 | throw new InvalidArgumentException( |
|
| 306 | '$contentTypeGroup', |
|
| 307 | 'Content type group has content type instances', |
|
| 308 | $e |
|
| 309 | ); |
|
| 310 | } catch (Exception $e) { |
|
| 311 | $this->repository->rollback(); |
|
| 312 | throw $e; |
|
| 313 | } |
|
| 314 | } |
|
| 315 | ||
| 316 | /** |
|
| 317 | * Validates input ContentType create struct. |
|
| @@ 156-182 (lines=27) @@ | ||
| 153 | * |
|
| 154 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
|
| 155 | */ |
|
| 156 | public function createRoleDraft(APIRole $role) |
|
| 157 | { |
|
| 158 | if (!$this->permissionResolver->canUser('role', 'create', $role)) { |
|
| 159 | throw new UnauthorizedException('role', 'create'); |
|
| 160 | } |
|
| 161 | ||
| 162 | try { |
|
| 163 | $this->userHandler->loadRole($role->id, Role::STATUS_DRAFT); |
|
| 164 | ||
| 165 | // Throw exception, so platformui et al can do conflict management. Follow-up: EZP-24719 |
|
| 166 | throw new InvalidArgumentException( |
|
| 167 | '$role', |
|
| 168 | "Cannot create a draft for role '{$role->identifier}' because another draft exists" |
|
| 169 | ); |
|
| 170 | } catch (APINotFoundException $e) { |
|
| 171 | $this->repository->beginTransaction(); |
|
| 172 | try { |
|
| 173 | $spiRole = $this->userHandler->createRoleDraft($role->id); |
|
| 174 | $this->repository->commit(); |
|
| 175 | } catch (Exception $e) { |
|
| 176 | $this->repository->rollback(); |
|
| 177 | throw $e; |
|
| 178 | } |
|
| 179 | } |
|
| 180 | ||
| 181 | return $this->roleDomainMapper->buildDomainRoleDraftObject($spiRole); |
|
| 182 | } |
|
| 183 | ||
| 184 | /** |
|
| 185 | * Loads a RoleDraft for the given id. |
|