| @@ 304-323 (lines=20) @@ | ||
| 301 | * |
|
| 302 | * @param \eZ\Publish\API\Repository\Values\Content\Language $language |
|
| 303 | */ |
|
| 304 | public function deleteLanguage(Language $language) |
|
| 305 | { |
|
| 306 | if ($this->repository->hasAccess('content', 'translations') !== true) { |
|
| 307 | throw new UnauthorizedException('content', 'translations'); |
|
| 308 | } |
|
| 309 | ||
| 310 | $loadedLanguage = $this->loadLanguageById($language->id); |
|
| 311 | ||
| 312 | $this->repository->beginTransaction(); |
|
| 313 | try { |
|
| 314 | $this->languageHandler->delete($loadedLanguage->id); |
|
| 315 | $this->repository->commit(); |
|
| 316 | } catch (LogicException $e) { |
|
| 317 | $this->repository->rollback(); |
|
| 318 | throw new InvalidArgumentException('language', $e->getMessage(), $e); |
|
| 319 | } catch (Exception $e) { |
|
| 320 | $this->repository->rollback(); |
|
| 321 | throw $e; |
|
| 322 | } |
|
| 323 | } |
|
| 324 | ||
| 325 | /** |
|
| 326 | * Returns a configured default language code. |
|
| @@ 950-981 (lines=32) @@ | ||
| 947 | * |
|
| 948 | * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft |
|
| 949 | */ |
|
| 950 | public function createContentTypeDraft(APIContentType $contentType) |
|
| 951 | { |
|
| 952 | if ($this->repository->hasAccess('class', 'create') !== true) { |
|
| 953 | throw new UnauthorizedException('ContentType', 'create'); |
|
| 954 | } |
|
| 955 | ||
| 956 | try { |
|
| 957 | $this->contentTypeHandler->load( |
|
| 958 | $contentType->id, |
|
| 959 | SPIContentType::STATUS_DRAFT |
|
| 960 | ); |
|
| 961 | ||
| 962 | throw new BadStateException( |
|
| 963 | '$contentType', |
|
| 964 | 'Draft of the ContentType already exists' |
|
| 965 | ); |
|
| 966 | } catch (APINotFoundException $e) { |
|
| 967 | $this->repository->beginTransaction(); |
|
| 968 | try { |
|
| 969 | $spiContentType = $this->contentTypeHandler->createDraft( |
|
| 970 | $this->repository->getCurrentUserReference()->getUserId(), |
|
| 971 | $contentType->id |
|
| 972 | ); |
|
| 973 | $this->repository->commit(); |
|
| 974 | } catch (Exception $e) { |
|
| 975 | $this->repository->rollback(); |
|
| 976 | throw $e; |
|
| 977 | } |
|
| 978 | } |
|
| 979 | ||
| 980 | return $this->contentTypeDomainMapper->buildContentTypeDraftDomainObject($spiContentType); |
|
| 981 | } |
|
| 982 | ||
| 983 | /** |
|
| 984 | * Update a Content Type object. |
|
| @@ 166-192 (lines=27) @@ | ||
| 163 | * |
|
| 164 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
|
| 165 | */ |
|
| 166 | public function createRoleDraft(APIRole $role) |
|
| 167 | { |
|
| 168 | if ($this->repository->hasAccess('role', 'create') !== true) { |
|
| 169 | throw new UnauthorizedException('role', 'create'); |
|
| 170 | } |
|
| 171 | ||
| 172 | try { |
|
| 173 | $this->userHandler->loadRole($role->id, Role::STATUS_DRAFT); |
|
| 174 | ||
| 175 | // Throw exception, so platformui et al can do conflict management. Follow-up: EZP-24719 |
|
| 176 | throw new InvalidArgumentException( |
|
| 177 | '$role', |
|
| 178 | "Cannot create a draft for role '{$role->identifier}' because another draft exists" |
|
| 179 | ); |
|
| 180 | } catch (APINotFoundException $e) { |
|
| 181 | $this->repository->beginTransaction(); |
|
| 182 | try { |
|
| 183 | $spiRole = $this->userHandler->createRoleDraft($role->id); |
|
| 184 | $this->repository->commit(); |
|
| 185 | } catch (Exception $e) { |
|
| 186 | $this->repository->rollback(); |
|
| 187 | throw $e; |
|
| 188 | } |
|
| 189 | } |
|
| 190 | ||
| 191 | return $this->roleDomainMapper->buildDomainRoleDraftObject($spiRole); |
|
| 192 | } |
|
| 193 | ||
| 194 | /** |
|
| 195 | * Loads a RoleDraft for the given id. |
|