From 8832185b7774be21268073f418d6e47bdb148d2a Mon Sep 17 00:00:00 2001 From: Dawid Parafinski Date: Fri, 25 Oct 2024 13:48:04 +0200 Subject: [PATCH] IBX-8534: Dropped deprecated loadRelations usage --- src/bundle/Resources/config/services.yml | 1 + .../config/value_object_visitors.yml | 6 ++- src/lib/Server/Controller/Content.php | 25 ++++++++----- src/lib/Server/Controller/User.php | 37 +++++++++++-------- .../Output/ValueObjectVisitor/Location.php | 16 ++------ .../ValueObjectVisitor/RestExecutedView.php | 28 ++------------ .../Server/Output/ValueObjectVisitor/User.php | 10 ++--- .../Output/ValueObjectVisitor/UserGroup.php | 13 +++---- 8 files changed, 57 insertions(+), 79 deletions(-) diff --git a/src/bundle/Resources/config/services.yml b/src/bundle/Resources/config/services.yml index 433a8aaf..ef87dcbd 100644 --- a/src/bundle/Resources/config/services.yml +++ b/src/bundle/Resources/config/services.yml @@ -149,6 +149,7 @@ services: - '@ibexa.api.service.section' - '@ibexa.api.repository' - '@Ibexa\Contracts\Core\Repository\PermissionResolver' + - '@Ibexa\Core\Helper\RelationListHelper' tags: [controller.service_arguments] Ibexa\Rest\Server\Controller\URLWildcard: diff --git a/src/bundle/Resources/config/value_object_visitors.yml b/src/bundle/Resources/config/value_object_visitors.yml index 9d7c30a0..29931ade 100644 --- a/src/bundle/Resources/config/value_object_visitors.yml +++ b/src/bundle/Resources/config/value_object_visitors.yml @@ -477,7 +477,7 @@ services: - { name: ibexa.rest.output.value_object.visitor, type: Ibexa\Contracts\Core\Repository\Values\Content\Location } arguments: $locationService: '@ibexa.api.service.location' - $contentService: '@ibexa.api.service.content' + $relationListHelper: '@Ibexa\Core\Helper\RelationListHelper' Ibexa\Rest\Server\Output\ValueObjectVisitor\LocationList: parent: Ibexa\Contracts\Rest\Output\ValueObjectVisitor @@ -502,7 +502,9 @@ services: Ibexa\Rest\Server\Output\ValueObjectVisitor\RestExecutedView: parent: Ibexa\Contracts\Rest\Output\ValueObjectVisitor class: Ibexa\Rest\Server\Output\ValueObjectVisitor\RestExecutedView - arguments: [ '@ibexa.api.service.location', '@ibexa.api.service.content' ] + arguments: + - '@ibexa.api.service.location' + - '@Ibexa\Core\Helper\RelationListHelper' tags: - { name: ibexa.rest.output.value_object.visitor, type: Ibexa\Rest\Server\Values\RestExecutedView } diff --git a/src/lib/Server/Controller/Content.php b/src/lib/Server/Controller/Content.php index d3404325..353e255f 100644 --- a/src/lib/Server/Controller/Content.php +++ b/src/lib/Server/Controller/Content.php @@ -14,6 +14,7 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Relation; use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo; use Ibexa\Contracts\Rest\Exceptions; +use Ibexa\Core\Helper\RelationListHelper; use Ibexa\Rest\Message; use Ibexa\Rest\Server\Controller as RestController; use Ibexa\Rest\Server\Exceptions\BadRequestException; @@ -30,6 +31,10 @@ */ class Content extends RestController { + public function __construct(private readonly RelationListHelper $relationListHelper, private readonly RelationListHelper $relationListHelper) + { + } + /** * Loads a content info by remote ID. * @@ -82,7 +87,7 @@ public function loadContent($contentId, Request $request) $languages = $this->getLanguages($request); $contentVersion = $this->repository->getContentService()->loadContent($contentId, $languages); - $relations = $this->repository->getContentService()->loadRelations($contentVersion->getVersionInfo()); + $relations = $this->relationListHelper->getRelations($contentVersion->getVersionInfo()); } $restContent = new Values\RestContent( @@ -200,7 +205,7 @@ public function loadContentInVersion($contentId, $versionNumber, Request $reques $versionValue = new Values\Version( $content, $contentType, - $this->repository->getContentService()->loadRelations($content->getVersionInfo()), + $this->relationListHelper->getRelations($content->getVersionInfo()), $request->getPathInfo() ); @@ -435,7 +440,7 @@ public function createDraftFromVersion($contentId, $versionNumber) 'version' => new Values\Version( $contentDraft, $contentType, - $this->repository->getContentService()->loadRelations($contentDraft->getVersionInfo()) + $this->relationListHelper->getRelations($contentDraft->getVersionInfo()) ), ] ); @@ -469,7 +474,7 @@ public function createDraftFromCurrentVersion($contentId) 'version' => new Values\Version( $contentDraft, $contentType, - $this->repository->getContentService()->loadRelations($contentDraft->getVersionInfo()) + $this->relationListHelper->getRelations($contentDraft->getVersionInfo()) ), ] ); @@ -536,7 +541,7 @@ public function updateVersion($contentId, $versionNumber, Request $request) return new Values\Version( $content, $contentType, - $this->repository->getContentService()->loadRelations($content->getVersionInfo()), + $this->relationListHelper->getRelations($content->getVersionInfo()), $request->getPathInfo() ); } @@ -605,7 +610,7 @@ public function loadVersionRelations($contentId, $versionNumber, Request $reques $limit = $request->query->has('limit') ? (int)$request->query->get('limit') : -1; $contentInfo = $this->repository->getContentService()->loadContentInfo($contentId); - $relationList = $this->repository->getContentService()->loadRelations( + $relationList = $this->relationListHelper->getRelations( $this->repository->getContentService()->loadVersionInfo($contentInfo, $versionNumber) ); @@ -646,7 +651,7 @@ public function loadVersionRelations($contentId, $versionNumber, Request $reques public function loadVersionRelation($contentId, $versionNumber, $relationId, Request $request) { $contentInfo = $this->repository->getContentService()->loadContentInfo($contentId); - $relationList = $this->repository->getContentService()->loadRelations( + $relationList = $this->relationListHelper->getRelations( $this->repository->getContentService()->loadVersionInfo($contentInfo, $versionNumber) ); @@ -687,7 +692,7 @@ public function removeRelation($contentId, $versionNumber, $relationId, Request $versionNumber ); - $versionRelations = $this->repository->getContentService()->loadRelations($versionInfo); + $versionRelations = $this->relationListHelper->getRelations($versionInfo); foreach ($versionRelations as $relation) { if ($relation->id == $relationId) { if ($relation->type !== Relation::COMMON) { @@ -739,7 +744,7 @@ public function createRelation($contentId, $versionNumber, Request $request) throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } - $existingRelations = $this->repository->getContentService()->loadRelations($versionInfo); + $existingRelations = $this->relationListHelper->getRelations($versionInfo); foreach ($existingRelations as $existingRelation) { if ($existingRelation->getDestinationContentInfo()->id == $destinationContentId) { throw new ForbiddenException('Relation of type COMMON to the selected destination content ID already exists'); @@ -844,7 +849,7 @@ protected function doCreateContent(Request $request, RestContentCreateStruct $co $contentType = $this->repository->getContentTypeService()->loadContentType( $content->getVersionInfo()->getContentInfo()->contentTypeId ); - $relations = $this->repository->getContentService()->loadRelations($contentValue->getVersionInfo()); + $relations = $this->relationListHelper->getRelations($contentValue->getVersionInfo()); } return new Values\CreatedContent( diff --git a/src/lib/Server/Controller/User.php b/src/lib/Server/Controller/User.php index dc7b4b38..ca833857 100644 --- a/src/lib/Server/Controller/User.php +++ b/src/lib/Server/Controller/User.php @@ -25,6 +25,7 @@ use Ibexa\Contracts\Core\Repository\Values\User\UserRoleAssignment; use Ibexa\Contracts\Rest\Exceptions\NotFoundException; use Ibexa\Core\Base\Exceptions\UnauthorizedException; +use Ibexa\Core\Helper\RelationListHelper; use Ibexa\Rest\Message; use Ibexa\Rest\Server\Controller as RestController; use Ibexa\Rest\Server\Exceptions; @@ -62,6 +63,8 @@ final class User extends RestController private PermissionResolver $permissionResolver; + private RelationListHelper $relationListHelper; + public function __construct( UserService $userService, RoleService $roleService, @@ -70,7 +73,8 @@ public function __construct( LocationService $locationService, SectionService $sectionService, Repository $repository, - PermissionResolver $permissionResolver + PermissionResolver $permissionResolver, + RelationListHelper $relationListHelper ) { $this->userService = $userService; $this->roleService = $roleService; @@ -80,6 +84,7 @@ public function __construct( $this->sectionService = $sectionService; $this->repository = $repository; $this->permissionResolver = $permissionResolver; + $this->relationListHelper = $relationListHelper; } /** @@ -121,7 +126,7 @@ public function loadUserGroup(string $groupPath): RestValue $contentType, $userGroupContentInfo, $userGroupLocation, - $this->contentService->loadRelations($userGroup->getVersionInfo()) + $this->relationListHelper->getRelations($userGroup->getVersionInfo()) ), ['locationId' => $userGroupLocation->id] ); @@ -136,7 +141,7 @@ public function loadUser(int $userId): RestValue try { $userMainLocation = $this->locationService->loadLocation($userContentInfo->mainLocationId); - $relations = $this->contentService->loadRelations($user->getVersionInfo()); + $relations = $this->relationListHelper->getRelations($user->getVersionInfo()); } catch (UnauthorizedException $e) { // TODO: Hack for special case to allow current logged in user to load him/here self (but not relations) if ($user->id == $this->permissionResolver->getCurrentUserReference()->getUserId()) { @@ -219,7 +224,7 @@ public function createUserGroup(string $groupPath, Request $request): Values\Cre $contentType, $createdContentInfo, $createdLocation, - $this->contentService->loadRelations($createdUserGroup->getVersionInfo()) + $this->relationListHelper->getRelations($createdUserGroup->getVersionInfo()) ), ] ); @@ -264,7 +269,7 @@ public function createUser(string $groupPath, Request $request): Values\CreatedU $contentType, $createdContentInfo, $createdLocation, - $this->contentService->loadRelations($createdUser->getVersionInfo()) + $this->relationListHelper->getRelations($createdUser->getVersionInfo()) ), ] ); @@ -309,7 +314,7 @@ public function updateUserGroup(string $groupPath, Request $request): Values\Res $contentType, $updatedGroup->getVersionInfo()->getContentInfo(), $userGroupLocation, - $this->contentService->loadRelations($updatedGroup->getVersionInfo()) + $this->relationListHelper->getRelations($updatedGroup->getVersionInfo()) ); } @@ -346,7 +351,7 @@ public function updateUser(int $userId, Request $request): Values\RestUser $contentType, $updatedContentInfo, $mainLocation, - $this->contentService->loadRelations($updatedUser->getVersionInfo()) + $this->relationListHelper->getRelations($updatedUser->getVersionInfo()) ); } @@ -481,7 +486,7 @@ private function buildRestUserObject(RepositoryUser $user): Values\RestUser $this->contentTypeService->loadContentType($user->contentInfo->contentTypeId), $user->contentInfo, $this->locationService->loadLocation($user->contentInfo->mainLocationId), - $this->contentService->loadRelations($user->getVersionInfo()) + $this->relationListHelper->getRelations($user->getVersionInfo()) ); } @@ -503,7 +508,7 @@ public function loadUserGroups(Request $request): RestValue $contentType, $userGroupContentInfo, $userGroupMainLocation, - $this->contentService->loadRelations($userGroup->getVersionInfo()) + $this->relationListHelper->getRelations($userGroup->getVersionInfo()) ), ]; } elseif ($request->query->has('roleId')) { @@ -536,7 +541,7 @@ public function loadUserGroupByRemoteId(Request $request): Values\RestUserGroup $contentType, $contentInfo, $userGroupLocation, - $this->contentService->loadRelations($userGroup->getVersionInfo()) + $this->relationListHelper->getRelations($userGroup->getVersionInfo()) ); } @@ -566,7 +571,7 @@ public function loadUserGroupsAssignedToRole($roleId): array $contentType, $userGroupContentInfo, $userGroupLocation, - $this->contentService->loadRelations($userGroup->getVersionInfo()) + $this->relationListHelper->getRelations($userGroup->getVersionInfo()) ); } } @@ -717,7 +722,7 @@ public function loadSubUserGroups(string $groupPath, Request $request): RestValu $contentType, $subGroupContentInfo, $subGroupLocation, - $this->contentService->loadRelations($subGroup->getVersionInfo()) + $this->relationListHelper->getRelations($subGroup->getVersionInfo()) ); } @@ -763,7 +768,7 @@ public function loadUserGroupsOfUser(int $userId, Request $request): RestValue $contentType, $userGroupContentInfo, $userGroupLocation, - $this->contentService->loadRelations($userGroup->getVersionInfo()) + $this->relationListHelper->getRelations($userGroup->getVersionInfo()) ); } @@ -807,7 +812,7 @@ public function loadUsersFromGroup(string $groupPath, Request $request): RestVal $contentType, $userContentInfo, $userLocation, - $this->contentService->loadRelations($user->getVersionInfo()) + $this->relationListHelper->getRelations($user->getVersionInfo()) ); } @@ -859,7 +864,7 @@ public function unassignUserFromUserGroup(int $userId, string $groupPath): Value $contentType, $userGroupContentInfo, $userGroupLocation, - $this->contentService->loadRelations($userGroup->getVersionInfo()) + $this->relationListHelper->getRelations($userGroup->getVersionInfo()) ); } @@ -917,7 +922,7 @@ public function assignUserToUserGroup(int $userId, Request $request): Values\Use $contentType, $userGroupContentInfo, $userGroupLocation, - $this->contentService->loadRelations($userGroup->getVersionInfo()) + $this->relationListHelper->getRelations($userGroup->getVersionInfo()) ); } diff --git a/src/lib/Server/Output/ValueObjectVisitor/Location.php b/src/lib/Server/Output/ValueObjectVisitor/Location.php index a34836eb..5d7de771 100644 --- a/src/lib/Server/Output/ValueObjectVisitor/Location.php +++ b/src/lib/Server/Output/ValueObjectVisitor/Location.php @@ -7,13 +7,13 @@ namespace Ibexa\Rest\Server\Output\ValueObjectVisitor; -use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException; use Ibexa\Contracts\Core\Repository\LocationService; use Ibexa\Contracts\Core\Repository\Values\Content; use Ibexa\Contracts\Rest\Output\Generator; use Ibexa\Contracts\Rest\Output\ValueObjectVisitor; use Ibexa\Contracts\Rest\Output\Visitor; +use Ibexa\Core\Helper\RelationListHelper; use Ibexa\Rest\Server\Values\RestContent as RestContentValue; /** @@ -21,18 +21,10 @@ */ class Location extends ValueObjectVisitor { - /** @var \Ibexa\Contracts\Core\Repository\LocationService */ - private $locationService; - - /** @var \Ibexa\Contracts\Core\Repository\ContentService */ - private $contentService; - public function __construct( - LocationService $locationService, - ContentService $contentService + private readonly LocationService $locationService, + private readonly RelationListHelper $relationListHelper ) { - $this->locationService = $locationService; - $this->contentService = $contentService; } /** @@ -172,7 +164,7 @@ protected function visitLocationAttributes( $mainLocation, $content, $content->getContentType(), - $this->contentService->loadRelations($content->getVersionInfo()) + $this->relationListHelper->getRelations($content->getVersionInfo()) ) ); diff --git a/src/lib/Server/Output/ValueObjectVisitor/RestExecutedView.php b/src/lib/Server/Output/ValueObjectVisitor/RestExecutedView.php index bcc72d7c..0a71b339 100644 --- a/src/lib/Server/Output/ValueObjectVisitor/RestExecutedView.php +++ b/src/lib/Server/Output/ValueObjectVisitor/RestExecutedView.php @@ -7,7 +7,6 @@ namespace Ibexa\Rest\Server\Output\ValueObjectVisitor; -use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; use Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException; use Ibexa\Contracts\Core\Repository\LocationService; @@ -16,6 +15,7 @@ use Ibexa\Contracts\Rest\Output\Generator; use Ibexa\Contracts\Rest\Output\ValueObjectVisitor; use Ibexa\Contracts\Rest\Output\Visitor; +use Ibexa\Core\Helper\RelationListHelper; use Ibexa\Rest\Server\Values\RestContent as RestContentValue; /** @@ -23,30 +23,10 @@ */ class RestExecutedView extends ValueObjectVisitor { - /** - * Location service. - * - * @var \Ibexa\Contracts\Core\Repository\LocationService - */ - protected $locationService; - - /** - * Content service. - * - * @var \Ibexa\Contracts\Core\Repository\ContentService - */ - protected $contentService; - - /** - * @param \Ibexa\Contracts\Core\Repository\LocationService $locationService - * @param \Ibexa\Contracts\Core\Repository\ContentService $contentService - */ public function __construct( - LocationService $locationService, - ContentService $contentService + private readonly LocationService $locationService, + private readonly RelationListHelper $relationListHelper ) { - $this->locationService = $locationService; - $this->contentService = $contentService; } /** @@ -128,7 +108,7 @@ public function visit(Visitor $visitor, Generator $generator, $data) $mainLocation, $searchHit->valueObject, $searchHit->valueObject->getContentType(), - $this->contentService->loadRelations($searchHit->valueObject->getVersionInfo()) + $this->relationListHelper->getRelations($searchHit->valueObject->getVersionInfo()) ); } elseif ($searchHit->valueObject instanceof ApiValues\Location) { $valueObject = $searchHit->valueObject; diff --git a/src/lib/Server/Output/ValueObjectVisitor/User.php b/src/lib/Server/Output/ValueObjectVisitor/User.php index a2a09120..d9a32751 100644 --- a/src/lib/Server/Output/ValueObjectVisitor/User.php +++ b/src/lib/Server/Output/ValueObjectVisitor/User.php @@ -8,21 +8,17 @@ namespace Ibexa\Rest\Server\Output\ValueObjectVisitor; -use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Rest\Output\Generator; use Ibexa\Contracts\Rest\Output\ValueObjectVisitor; use Ibexa\Contracts\Rest\Output\Visitor; +use Ibexa\Core\Helper\RelationListHelper; use Ibexa\Rest\Output\DelegateValueObjectVisitor; use Ibexa\Rest\Server\Values\RestUser; final class User extends ValueObjectVisitor implements DelegateValueObjectVisitor { - /** @var \Ibexa\Contracts\Core\Repository\ContentService */ - private $contentService; - - public function __construct(ContentService $contentService) + public function __construct(private readonly RelationListHelper $relationListHelper) { - $this->contentService = $contentService; } /** @@ -36,7 +32,7 @@ public function visit(Visitor $visitor, Generator $generator, $data): void $data->getContentType(), $data->contentInfo, $data->contentInfo->getMainLocation(), - $this->contentService->loadRelations( + $this->relationListHelper->getRelations( $data->getVersionInfo() ) ) diff --git a/src/lib/Server/Output/ValueObjectVisitor/UserGroup.php b/src/lib/Server/Output/ValueObjectVisitor/UserGroup.php index cc20c031..92e4ef89 100644 --- a/src/lib/Server/Output/ValueObjectVisitor/UserGroup.php +++ b/src/lib/Server/Output/ValueObjectVisitor/UserGroup.php @@ -8,21 +8,18 @@ namespace Ibexa\Rest\Server\Output\ValueObjectVisitor; -use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Rest\Output\Generator; use Ibexa\Contracts\Rest\Output\ValueObjectVisitor; use Ibexa\Contracts\Rest\Output\Visitor; +use Ibexa\Core\Helper\RelationListHelper; use Ibexa\Rest\Output\DelegateValueObjectVisitor; use Ibexa\Rest\Server\Values\RestUserGroup; final class UserGroup extends ValueObjectVisitor implements DelegateValueObjectVisitor { - /** @var \Ibexa\Contracts\Core\Repository\ContentService */ - private $contentService; - - public function __construct(ContentService $contentService) - { - $this->contentService = $contentService; + public function __construct( + private readonly RelationListHelper $relationListHelper + ) { } /** @@ -36,7 +33,7 @@ public function visit(Visitor $visitor, Generator $generator, $data): void $data->getContentType(), $data->contentInfo, $data->contentInfo->getMainLocation(), - $this->contentService->loadRelations($data->getVersionInfo()) + $this->relationListHelper->getRelations($data->getVersionInfo()) ) ); }