Code Duplication    Length = 20-27 lines in 2 locations

eZ/Publish/Core/Repository/LanguageService.php 1 location

@@ 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.

eZ/Publish/Core/Repository/RoleService.php 1 location

@@ 221-247 (lines=27) @@
218
     *
219
     * @return \eZ\Publish\API\Repository\Values\User\RoleDraft
220
     */
221
    public function createRoleDraft(APIRole $role)
222
    {
223
        if ($this->repository->hasAccess('role', 'create') !== true) {
224
            throw new UnauthorizedException('role', 'create');
225
        }
226
227
        try {
228
            $this->userHandler->loadRole($role->id, Role::STATUS_DRAFT);
229
230
            // Throw exception, so platformui et al can do conflict management. Follow-up: EZP-24719
231
            throw new InvalidArgumentException(
232
                '$role',
233
                "Cannot create a draft for role '{$role->identifier}' because another draft exists"
234
            );
235
        } catch (APINotFoundException $e) {
236
            $this->repository->beginTransaction();
237
            try {
238
                $spiRole = $this->userHandler->createRoleDraft($role->id);
239
                $this->repository->commit();
240
            } catch (Exception $e) {
241
                $this->repository->rollback();
242
                throw $e;
243
            }
244
        }
245
246
        return $this->roleDomainMapper->buildDomainRoleDraftObject($spiRole);
247
    }
248
249
    /**
250
     * Loads a RoleDraft for the given id.