Code Duplication    Length = 20-34 lines in 3 locations

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

@@ 1263-1296 (lines=34) @@
1260
     *
1261
     * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft
1262
     */
1263
    public function createContentTypeDraft(APIContentType $contentType)
1264
    {
1265
        if ($this->repository->hasAccess('class', 'create') !== true) {
1266
            throw new UnauthorizedException('ContentType', 'create');
1267
        }
1268
1269
        try {
1270
            $this->contentTypeHandler->load(
1271
                $contentType->id,
1272
                SPIContentType::STATUS_DRAFT
1273
            );
1274
1275
            throw new BadStateException(
1276
                '$contentType',
1277
                'Draft of the ContentType already exists'
1278
            );
1279
        } catch (APINotFoundException $e) {
1280
            $this->repository->beginTransaction();
1281
            try {
1282
                $spiContentType = $this->contentTypeHandler->createDraft(
1283
                    $this->repository->getCurrentUserReference()->getUserId(),
1284
                    $contentType->id
1285
                );
1286
                $this->repository->commit();
1287
            } catch (Exception $e) {
1288
                $this->repository->rollback();
1289
                throw $e;
1290
            }
1291
        }
1292
1293
        return $this->buildContentTypeDraftDomainObject(
1294
            $spiContentType
1295
        );
1296
    }
1297
1298
    /**
1299
     * Update a Content Type object.

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

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

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

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