Code Duplication    Length = 17-17 lines in 7 locations

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

@@ 822-838 (lines=17) @@
819
     *
820
     * @param \eZ\Publish\API\Repository\Values\User\Role $role
821
     */
822
    public function deleteRole(APIRole $role)
823
    {
824
        if ($this->repository->hasAccess('role', 'delete') !== true) {
825
            throw new UnauthorizedException('role', 'delete');
826
        }
827
828
        $loadedRole = $this->loadRole($role->id);
829
830
        $this->repository->beginTransaction();
831
        try {
832
            $this->userHandler->deleteRole($loadedRole->id);
833
            $this->repository->commit();
834
        } catch (Exception $e) {
835
            $this->repository->rollback();
836
            throw $e;
837
        }
838
    }
839
840
    /**
841
     * Loads all policies from roles which are assigned to a user or to user groups to which the user belongs.
@@ 1050-1066 (lines=17) @@
1047
     *
1048
     * @param \eZ\Publish\API\Repository\Values\User\RoleAssignment $roleAssignment
1049
     */
1050
    public function removeRoleAssignment(RoleAssignment $roleAssignment)
1051
    {
1052
        if ($this->repository->canUser('role', 'assign', $roleAssignment) !== true) {
1053
            throw new UnauthorizedException('role', 'assign');
1054
        }
1055
1056
        $spiRoleAssignment = $this->userHandler->loadRoleAssignment($roleAssignment->id);
1057
1058
        $this->repository->beginTransaction();
1059
        try {
1060
            $this->userHandler->removeRoleAssignment($spiRoleAssignment->id);
1061
            $this->repository->commit();
1062
        } catch (Exception $e) {
1063
            $this->repository->rollback();
1064
            throw $e;
1065
        }
1066
    }
1067
1068
    /**
1069
     * Loads a role assignment for the given id.

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

@@ 140-156 (lines=17) @@
137
     *
138
     * @param \eZ\Publish\API\Repository\Values\Content\UrlWildcard $urlWildcard the url wildcard to remove
139
     */
140
    public function remove(URLWildcard $urlWildcard)
141
    {
142
        if (!$this->repository->canUser('content', 'urltranslator', $urlWildcard)) {
143
            throw new UnauthorizedException('content', 'urltranslator');
144
        }
145
146
        $this->repository->beginTransaction();
147
        try {
148
            $this->urlWildcardHandler->remove(
149
                $urlWildcard->id
150
            );
151
            $this->repository->commit();
152
        } catch (Exception $e) {
153
            $this->repository->rollback();
154
            throw $e;
155
        }
156
    }
157
158
    /**
159
     * Loads a url wild card.

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

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

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

@@ 611-627 (lines=17) @@
608
     *
609
     * @return \eZ\Publish\API\Repository\Values\Content\Location $location, with updated hidden value
610
     */
611
    public function hideLocation(APILocation $location)
612
    {
613
        if (!$this->repository->canUser('content', 'hide', $location->getContentInfo(), $location)) {
614
            throw new UnauthorizedException('content', 'hide');
615
        }
616
617
        $this->repository->beginTransaction();
618
        try {
619
            $this->persistenceHandler->locationHandler()->hide($location->id);
620
            $this->repository->commit();
621
        } catch (Exception $e) {
622
            $this->repository->rollback();
623
            throw $e;
624
        }
625
626
        return $this->loadLocation($location->id);
627
    }
628
629
    /**
630
     * Unhides the $location.
@@ 641-657 (lines=17) @@
638
     *
639
     * @return \eZ\Publish\API\Repository\Values\Content\Location $location, with updated hidden value
640
     */
641
    public function unhideLocation(APILocation $location)
642
    {
643
        if (!$this->repository->canUser('content', 'hide', $location->getContentInfo(), $location)) {
644
            throw new UnauthorizedException('content', 'hide');
645
        }
646
647
        $this->repository->beginTransaction();
648
        try {
649
            $this->persistenceHandler->locationHandler()->unHide($location->id);
650
            $this->repository->commit();
651
        } catch (Exception $e) {
652
            $this->repository->rollback();
653
            throw $e;
654
        }
655
656
        return $this->loadLocation($location->id);
657
    }
658
659
    /**
660
     * Moves the subtree to $newParentLocation.