Code Duplication    Length = 17-18 lines in 5 locations

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

@@ 237-253 (lines=17) @@
234
     *
235
     * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup $objectStateGroup
236
     */
237
    public function deleteObjectStateGroup(APIObjectStateGroup $objectStateGroup)
238
    {
239
        if ($this->repository->hasAccess('state', 'administrate') !== true) {
240
            throw new UnauthorizedException('state', 'administrate');
241
        }
242
243
        $loadedObjectStateGroup = $this->loadObjectStateGroup($objectStateGroup->id);
244
245
        $this->repository->beginTransaction();
246
        try {
247
            $this->objectStateHandler->deleteGroup($loadedObjectStateGroup->id);
248
            $this->repository->commit();
249
        } catch (Exception $e) {
250
            $this->repository->rollback();
251
            throw $e;
252
        }
253
    }
254
255
    /**
256
     * Creates a new object state in the given group.
@@ 433-449 (lines=17) @@
430
     *
431
     * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectState $objectState
432
     */
433
    public function deleteObjectState(APIObjectState $objectState)
434
    {
435
        if ($this->repository->hasAccess('state', 'administrate') !== true) {
436
            throw new UnauthorizedException('state', 'administrate');
437
        }
438
439
        $loadedObjectState = $this->loadObjectState($objectState->id);
440
441
        $this->repository->beginTransaction();
442
        try {
443
            $this->objectStateHandler->delete($loadedObjectState->id);
444
            $this->repository->commit();
445
        } catch (Exception $e) {
446
            $this->repository->rollback();
447
            throw $e;
448
        }
449
    }
450
451
    /**
452
     * Sets the object-state of a state group to $state for the given content.

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

@@ 879-895 (lines=17) @@
876
     *
877
     * @param \eZ\Publish\API\Repository\Values\User\Role $role
878
     */
879
    public function deleteRole(APIRole $role)
880
    {
881
        if ($this->repository->hasAccess('role', 'delete') !== true) {
882
            throw new UnauthorizedException('role', 'delete');
883
        }
884
885
        $loadedRole = $this->loadRole($role->id);
886
887
        $this->repository->beginTransaction();
888
        try {
889
            $this->userHandler->deleteRole($loadedRole->id);
890
            $this->repository->commit();
891
        } catch (Exception $e) {
892
            $this->repository->rollback();
893
            throw $e;
894
        }
895
    }
896
897
    /**
898
     * Loads all policies from roles which are assigned to a user or to user groups to which the user belongs.
@@ 1107-1123 (lines=17) @@
1104
     *
1105
     * @param \eZ\Publish\API\Repository\Values\User\RoleAssignment $roleAssignment
1106
     */
1107
    public function removeRoleAssignment(RoleAssignment $roleAssignment)
1108
    {
1109
        if ($this->repository->canUser('role', 'assign', $roleAssignment) !== true) {
1110
            throw new UnauthorizedException('role', 'assign');
1111
        }
1112
1113
        $spiRoleAssignment = $this->userHandler->loadRoleAssignment($roleAssignment->id);
1114
1115
        $this->repository->beginTransaction();
1116
        try {
1117
            $this->userHandler->removeRoleAssignment($spiRoleAssignment->id);
1118
            $this->repository->commit();
1119
        } catch (Exception $e) {
1120
            $this->repository->rollback();
1121
            throw $e;
1122
        }
1123
    }
1124
1125
    /**
1126
     * Loads a role assignment for the given id.

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

@@ 1152-1169 (lines=18) @@
1149
     *
1150
     * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType
1151
     */
1152
    public function deleteContentType(APIContentType $contentType)
1153
    {
1154
        if ($this->repository->hasAccess('class', 'delete') !== true) {
1155
            throw new UnauthorizedException('ContentType', 'delete');
1156
        }
1157
1158
        $this->repository->beginTransaction();
1159
        try {
1160
            $this->contentTypeHandler->delete(
1161
                $contentType->id,
1162
                $contentType->status
1163
            );
1164
            $this->repository->commit();
1165
        } catch (Exception $e) {
1166
            $this->repository->rollback();
1167
            throw $e;
1168
        }
1169
    }
1170
1171
    /**
1172
     * Copy Type incl fields and groupIds to a new Type object.