Code Duplication    Length = 17-21 lines in 5 locations

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

@@ 1630-1650 (lines=21) @@
1627
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1628
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
1629
     */
1630
    public function removeContentTypeTranslation(APIContentTypeDraft $contentTypeDraft, string $languageCode): APIContentTypeDraft
1631
    {
1632
        if (!$this->repository->canUser('class', 'update', $contentTypeDraft)) {
1633
            throw new UnauthorizedException('ContentType', 'update');
1634
        }
1635
1636
        $this->repository->beginTransaction();
1637
        try {
1638
            $contentType = $this->contentTypeHandler->removeContentTypeTranslation(
1639
                $contentTypeDraft->id,
1640
                $languageCode
1641
            );
1642
1643
            $this->repository->commit();
1644
        } catch (Exception $e) {
1645
            $this->repository->rollback();
1646
            throw $e;
1647
        }
1648
1649
        return $this->contentTypeDomainMapper->buildContentTypeDraftDomainObject($contentType);
1650
    }
1651
1652
    public function deleteUserDrafts(int $userId): void
1653
    {

eZ/Publish/Core/Repository/ObjectStateService.php 2 locations

@@ 228-244 (lines=17) @@
225
     *
226
     * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup $objectStateGroup
227
     */
228
    public function deleteObjectStateGroup(APIObjectStateGroup $objectStateGroup)
229
    {
230
        if (!$this->repository->canUser('state', 'administrate', $objectStateGroup)) {
231
            throw new UnauthorizedException('state', 'administrate');
232
        }
233
234
        $loadedObjectStateGroup = $this->loadObjectStateGroup($objectStateGroup->id);
235
236
        $this->repository->beginTransaction();
237
        try {
238
            $this->objectStateHandler->deleteGroup($loadedObjectStateGroup->id);
239
            $this->repository->commit();
240
        } catch (Exception $e) {
241
            $this->repository->rollback();
242
            throw $e;
243
        }
244
    }
245
246
    /**
247
     * Creates a new object state in the given group.
@@ 418-434 (lines=17) @@
415
     *
416
     * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectState $objectState
417
     */
418
    public function deleteObjectState(APIObjectState $objectState)
419
    {
420
        if (!$this->repository->canUser('state', 'administrate', $objectState)) {
421
            throw new UnauthorizedException('state', 'administrate');
422
        }
423
424
        $loadedObjectState = $this->loadObjectState($objectState->id);
425
426
        $this->repository->beginTransaction();
427
        try {
428
            $this->objectStateHandler->delete($loadedObjectState->id);
429
            $this->repository->commit();
430
        } catch (Exception $e) {
431
            $this->repository->rollback();
432
            throw $e;
433
        }
434
    }
435
436
    /**
437
     * Sets the object-state of a state group to $state for the given content.

eZ/Publish/Core/Repository/RoleService.php 2 locations

@@ 815-831 (lines=17) @@
812
     *
813
     * @param \eZ\Publish\API\Repository\Values\User\Role $role
814
     */
815
    public function deleteRole(APIRole $role)
816
    {
817
        if (!$this->permissionResolver->canUser('role', 'delete', $role)) {
818
            throw new UnauthorizedException('role', 'delete');
819
        }
820
821
        $loadedRole = $this->loadRole($role->id);
822
823
        $this->repository->beginTransaction();
824
        try {
825
            $this->userHandler->deleteRole($loadedRole->id);
826
            $this->repository->commit();
827
        } catch (Exception $e) {
828
            $this->repository->rollback();
829
            throw $e;
830
        }
831
    }
832
833
    /**
834
     * Loads all policies from roles which are assigned to a user or to user groups to which the user belongs.
@@ 1043-1059 (lines=17) @@
1040
     *
1041
     * @param \eZ\Publish\API\Repository\Values\User\RoleAssignment $roleAssignment
1042
     */
1043
    public function removeRoleAssignment(RoleAssignment $roleAssignment)
1044
    {
1045
        if ($this->permissionResolver->canUser('role', 'assign', $roleAssignment) !== true) {
1046
            throw new UnauthorizedException('role', 'assign');
1047
        }
1048
1049
        $spiRoleAssignment = $this->userHandler->loadRoleAssignment($roleAssignment->id);
1050
1051
        $this->repository->beginTransaction();
1052
        try {
1053
            $this->userHandler->removeRoleAssignment($spiRoleAssignment->id);
1054
            $this->repository->commit();
1055
        } catch (Exception $e) {
1056
            $this->repository->rollback();
1057
            throw $e;
1058
        }
1059
    }
1060
1061
    /**
1062
     * Loads a role assignment for the given id.