Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

IBX-8019: Replaced LocationService::loadLocationChildren use with SearchService #2119

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions src/lib/UI/Module/Subitems/ContentViewParameterSupplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
use eZ\Publish\API\Repository\ContentTypeService;
use eZ\Publish\API\Repository\LocationService;
use eZ\Publish\API\Repository\PermissionResolver;
use eZ\Publish\API\Repository\SearchService;
use eZ\Publish\API\Repository\Values\Content\Content;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
use eZ\Publish\Core\MVC\Symfony\View\ContentView;
use eZ\Publish\Core\Query\QueryFactoryInterface;
use EzSystems\EzPlatformAdminUi\UI\Config\Provider\ContentTypeMappings;
use EzSystems\EzPlatformAdminUi\UI\Module\Subitems\ValueObjectVisitor\SubitemsList as SubitemsListValueObjectVisitor;
use EzSystems\EzPlatformAdminUi\UI\Module\Subitems\Values\SubitemsList;
Expand Down Expand Up @@ -63,18 +65,12 @@ class ContentViewParameterSupplier
/** @var \EzSystems\EzPlatformUser\UserSetting\UserSettingService */
private $userSettingService;

/**
* @param \EzSystems\EzPlatformRest\Output\Visitor $outputVisitor
* @param \EzSystems\EzPlatformRest\Output\Generator\Json $outputGenerator
* @param \EzSystems\EzPlatformRest\Server\Output\ValueObjectVisitor\ContentTypeInfoList $contentTypeInfoListValueObjectVisitor
* @param \EzSystems\EzPlatformAdminUi\UI\Module\Subitems\ValueObjectVisitor\SubitemsList $subitemsListValueObjectVisitor
* @param \eZ\Publish\API\Repository\LocationService $locationService
* @param \eZ\Publish\API\Repository\ContentService $contentService
* @param \eZ\Publish\API\Repository\ContentTypeService $contentTypeService
* @param \eZ\Publish\API\Repository\PermissionResolver $permissionResolver
* @param \EzSystems\EzPlatformAdminUi\UI\Config\Provider\ContentTypeMappings $contentTypeMappings
* @param \EzSystems\EzPlatformUser\UserSetting\UserSettingService $userSettingService
*/
/** @var \eZ\Publish\Core\Query\QueryFactoryInterface */
private $queryFactory;

/** @var \eZ\Publish\API\Repository\SearchService */
private $searchService;

public function __construct(
Visitor $outputVisitor,
JsonOutputGenerator $outputGenerator,
Expand All @@ -85,7 +81,9 @@ public function __construct(
ContentTypeService $contentTypeService,
PermissionResolver $permissionResolver,
ContentTypeMappings $contentTypeMappings,
UserSettingService $userSettingService
UserSettingService $userSettingService,
QueryFactoryInterface $queryFactory,
SearchService $searchService
) {
$this->outputVisitor = $outputVisitor;
$this->outputGenerator = $outputGenerator;
Expand All @@ -97,6 +95,8 @@ public function __construct(
$this->permissionResolver = $permissionResolver;
$this->contentTypeMappings = $contentTypeMappings;
$this->userSettingService = $userSettingService;
$this->queryFactory = $queryFactory;
$this->searchService = $searchService;
}

/**
Expand All @@ -121,12 +121,17 @@ public function supply(ContentView $view)
$contentTypes = [];
$subitemsRows = [];
$location = $view->getLocation();
$childrenCount = $this->locationService->getLocationChildCount($location);

$subitemsLimit = (int)$this->userSettingService->getUserSetting('subitems_limit')->value;

$locationChildren = $this->locationService->loadLocationChildren($location, 0, $subitemsLimit);
foreach ($locationChildren->locations as $locationChild) {
/** @var \eZ\Publish\API\Repository\Values\Content\LocationQuery $locationChildrenQuery */
$locationChildrenQuery = $this->queryFactory->create('Children', ['location' => $location]);
$locationChildrenQuery->offset = 0;
$locationChildrenQuery->limit = $subitemsLimit;

$searchResult = $this->searchService->findLocations($locationChildrenQuery);
foreach ($searchResult->searchHits as $searchHit) {
/** @var \eZ\Publish\API\Repository\Values\Content\Location $locationChild */
$locationChild = $searchHit->valueObject;
$contentType = $locationChild->getContent()->getContentType();

if (!isset($contentTypes[$contentType->identifier])) {
Expand All @@ -136,7 +141,7 @@ public function supply(ContentView $view)
$subitemsRows[] = $this->createSubitemsRow($locationChild, $contentType);
}

$subitemsList = new SubitemsList($subitemsRows, $childrenCount);
$subitemsList = new SubitemsList($subitemsRows, $searchResult->totalCount);
$contentTypeInfoList = new ContentTypeInfoList($contentTypes, '');

$subitemsListJson = $this->visitSubitemsList($subitemsList);
Expand Down
Loading