| @@ 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. |
|
| @@ 194-220 (lines=27) @@ | ||
| 191 | * |
|
| 192 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
|
| 193 | */ |
|
| 194 | public function createRoleDraft(APIRole $role) |
|
| 195 | { |
|
| 196 | if ($this->repository->hasAccess('role', 'create') !== true) { |
|
| 197 | throw new UnauthorizedException('role', 'create'); |
|
| 198 | } |
|
| 199 | ||
| 200 | try { |
|
| 201 | $this->userHandler->loadRole($role->id, Role::STATUS_DRAFT); |
|
| 202 | ||
| 203 | // Throw exception, so platformui et al can do conflict management. Follow-up: EZP-24719 |
|
| 204 | throw new InvalidArgumentException( |
|
| 205 | '$role', |
|
| 206 | "Cannot create a draft for role '{$role->identifier}' because another draft exists" |
|
| 207 | ); |
|
| 208 | } catch (APINotFoundException $e) { |
|
| 209 | $this->repository->beginTransaction(); |
|
| 210 | try { |
|
| 211 | $spiRole = $this->userHandler->createRoleDraft($role->id); |
|
| 212 | $this->repository->commit(); |
|
| 213 | } catch (Exception $e) { |
|
| 214 | $this->repository->rollback(); |
|
| 215 | throw $e; |
|
| 216 | } |
|
| 217 | } |
|
| 218 | ||
| 219 | return $this->roleDomainMapper->buildDomainRoleDraftObject($spiRole); |
|
| 220 | } |
|
| 221 | ||
| 222 | /** |
|
| 223 | * Loads a RoleDraft for the given id. |
|