Skip to content

Commit

Permalink
IBX-8534: Dropped deprecated loadRelations usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniTou committed Oct 25, 2024
1 parent 7c9ab33 commit 8832185
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 79 deletions.
1 change: 1 addition & 0 deletions src/bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions src/bundle/Resources/config/value_object_visitors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }

Expand Down
25 changes: 15 additions & 10 deletions src/lib/Server/Controller/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
);

Expand Down Expand Up @@ -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())
),
]
);
Expand Down Expand Up @@ -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())
),
]
);
Expand Down Expand Up @@ -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()
);
}
Expand Down Expand Up @@ -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)
);

Expand Down Expand Up @@ -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)
);

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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(
Expand Down
37 changes: 21 additions & 16 deletions src/lib/Server/Controller/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,6 +63,8 @@ final class User extends RestController

private PermissionResolver $permissionResolver;

private RelationListHelper $relationListHelper;

public function __construct(
UserService $userService,
RoleService $roleService,
Expand All @@ -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;
Expand All @@ -80,6 +84,7 @@ public function __construct(
$this->sectionService = $sectionService;
$this->repository = $repository;
$this->permissionResolver = $permissionResolver;
$this->relationListHelper = $relationListHelper;
}

/**
Expand Down Expand Up @@ -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]
);
Expand All @@ -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()) {
Expand Down Expand Up @@ -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())
),
]
);
Expand Down Expand Up @@ -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())
),
]
);
Expand Down Expand Up @@ -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())
);
}

Expand Down Expand Up @@ -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())
);
}

Expand Down Expand Up @@ -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())
);
}

Expand All @@ -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')) {
Expand Down Expand Up @@ -536,7 +541,7 @@ public function loadUserGroupByRemoteId(Request $request): Values\RestUserGroup
$contentType,
$contentInfo,
$userGroupLocation,
$this->contentService->loadRelations($userGroup->getVersionInfo())
$this->relationListHelper->getRelations($userGroup->getVersionInfo())
);
}

Expand Down Expand Up @@ -566,7 +571,7 @@ public function loadUserGroupsAssignedToRole($roleId): array
$contentType,
$userGroupContentInfo,
$userGroupLocation,
$this->contentService->loadRelations($userGroup->getVersionInfo())
$this->relationListHelper->getRelations($userGroup->getVersionInfo())
);
}
}
Expand Down Expand Up @@ -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())
);
}

Expand Down Expand Up @@ -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())
);
}

Expand Down Expand Up @@ -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())
);
}

Expand Down Expand Up @@ -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())
);
}

Expand Down Expand Up @@ -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())
);
}

Expand Down
16 changes: 4 additions & 12 deletions src/lib/Server/Output/ValueObjectVisitor/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,24 @@

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;

/**
* Location value object visitor.
*/
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;
}

/**
Expand Down Expand Up @@ -172,7 +164,7 @@ protected function visitLocationAttributes(
$mainLocation,
$content,
$content->getContentType(),
$this->contentService->loadRelations($content->getVersionInfo())
$this->relationListHelper->getRelations($content->getVersionInfo())
)
);

Expand Down
Loading

0 comments on commit 8832185

Please sign in to comment.