From 64a7a592e1e0ad911fac89de5cb47fb06a52755d Mon Sep 17 00:00:00 2001 From: Bartek Date: Wed, 26 Aug 2020 13:20:44 +0200 Subject: [PATCH] EZP-31776: Provided 'null' as Location in RestExecutedView if unavailable (#53) Co-authored-by: Bartek Wajda --- .../Output/ValueObjectVisitor/RestExecutedView.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib/Server/Output/ValueObjectVisitor/RestExecutedView.php b/src/lib/Server/Output/ValueObjectVisitor/RestExecutedView.php index 9ebe3a8e..935e9927 100644 --- a/src/lib/Server/Output/ValueObjectVisitor/RestExecutedView.php +++ b/src/lib/Server/Output/ValueObjectVisitor/RestExecutedView.php @@ -6,6 +6,8 @@ */ namespace EzSystems\EzPlatformRest\Server\Output\ValueObjectVisitor; +use eZ\Publish\API\Repository\Exceptions\NotFoundException; +use eZ\Publish\API\Repository\Exceptions\UnauthorizedException; use eZ\Publish\API\Repository\Values\Content as ApiValues; use EzSystems\EzPlatformRest\Exceptions; use EzSystems\EzPlatformRest\Output\ValueObjectVisitor; @@ -113,9 +115,16 @@ public function visit(Visitor $visitor, Generator $generator, $data) if ($searchHit->valueObject instanceof ApiValues\Content) { /** @var \eZ\Publish\API\Repository\Values\Content\Content $searchHit->valueObject */ $contentInfo = $searchHit->valueObject->contentInfo; + + try { + $mainLocation = $this->locationService->loadLocation($contentInfo->mainLocationId); + } catch (NotFoundException | UnauthorizedException $e) { + $mainLocation = null; + } + $valueObject = new RestContentValue( $contentInfo, - $this->locationService->loadLocation($contentInfo->mainLocationId), + $mainLocation, $searchHit->valueObject, $searchHit->valueObject->getContentType(), $this->contentService->loadRelations($searchHit->valueObject->getVersionInfo())