| @@ 306-325 (lines=20) @@ | ||
| 303 | * |
|
| 304 | * @param \eZ\Publish\API\Repository\Values\Content\Language $language |
|
| 305 | */ |
|
| 306 | public function deleteLanguage(Language $language) |
|
| 307 | { |
|
| 308 | if ($this->repository->hasAccess('content', 'translations') !== true) { |
|
| 309 | throw new UnauthorizedException('content', 'translations'); |
|
| 310 | } |
|
| 311 | ||
| 312 | $loadedLanguage = $this->loadLanguageById($language->id); |
|
| 313 | ||
| 314 | $this->repository->beginTransaction(); |
|
| 315 | try { |
|
| 316 | $this->languageHandler->delete($loadedLanguage->id); |
|
| 317 | $this->repository->commit(); |
|
| 318 | } catch (LogicException $e) { |
|
| 319 | $this->repository->rollback(); |
|
| 320 | throw new InvalidArgumentException('language', $e->getMessage(), $e); |
|
| 321 | } catch (Exception $e) { |
|
| 322 | $this->repository->rollback(); |
|
| 323 | throw $e; |
|
| 324 | } |
|
| 325 | } |
|
| 326 | ||
| 327 | /** |
|
| 328 | * Returns a configured default language code. |
|
| @@ 195-221 (lines=27) @@ | ||
| 192 | * |
|
| 193 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft |
|
| 194 | */ |
|
| 195 | public function createRoleDraft(APIRole $role) |
|
| 196 | { |
|
| 197 | if ($this->repository->hasAccess('role', 'create') !== true) { |
|
| 198 | throw new UnauthorizedException('role', 'create'); |
|
| 199 | } |
|
| 200 | ||
| 201 | try { |
|
| 202 | $this->userHandler->loadRole($role->id, Role::STATUS_DRAFT); |
|
| 203 | ||
| 204 | // Throw exception, so platformui et al can do conflict management. Follow-up: EZP-24719 |
|
| 205 | throw new InvalidArgumentException( |
|
| 206 | '$role', |
|
| 207 | "Cannot create a draft for role '{$role->identifier}' because another draft exists" |
|
| 208 | ); |
|
| 209 | } catch (APINotFoundException $e) { |
|
| 210 | $this->repository->beginTransaction(); |
|
| 211 | try { |
|
| 212 | $spiRole = $this->userHandler->createRoleDraft($role->id); |
|
| 213 | $this->repository->commit(); |
|
| 214 | } catch (Exception $e) { |
|
| 215 | $this->repository->rollback(); |
|
| 216 | throw $e; |
|
| 217 | } |
|
| 218 | } |
|
| 219 | ||
| 220 | return $this->roleDomainMapper->buildDomainRoleDraftObject($spiRole); |
|
| 221 | } |
|
| 222 | ||
| 223 | /** |
|
| 224 | * Loads a RoleDraft for the given id. |
|