Skip to content

Commit

Permalink
EZP-27150 Content fetching ERROR.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Musiał committed Mar 30, 2017
1 parent e4b9e88 commit 608c611
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Rest/Controller/ContentController.php
Expand Up @@ -5,6 +5,7 @@
*/
namespace EzSystems\RecommendationBundle\Rest\Controller;

use eZ\Publish\Core\Base\Exceptions\UnauthorizedException;
use eZ\Publish\Core\MVC\ConfigResolverInterface;
use eZ\Publish\API\Repository\Values\Content\Content;
use eZ\Publish\API\Repository\Values\Content\Query;
Expand Down Expand Up @@ -150,7 +151,7 @@ public function getContent($contentIdList, $responseType, Request $request)

$contentItems = $this->searchService->findContent($query)->searchHits;

$content = $this->prepareContent($contentItems, $request);
$content = $this->prepareContent(array($contentItems), $request);

return new ContentDataValue($content, [
'responseType' => 'http',
Expand Down Expand Up @@ -252,9 +253,13 @@ private function getAuthor(Content $contentValue, ContentType $contentType)
);

if (null === $author) {
$ownerId = empty($contentValue->contentInfo->ownerId) ? $this->defaultAuthorId : $contentValue->contentInfo->ownerId;
$userContentInfo = $this->contentService->loadContentInfo($ownerId);
$author = $userContentInfo->name;
try {
$ownerId = empty($contentValue->contentInfo->ownerId) ? $this->defaultAuthorId : $contentValue->contentInfo->ownerId;
$userContentInfo = $this->contentService->loadContentInfo($ownerId);
$author = $userContentInfo->name;
} catch (UnauthorizedException $e) {
$author = '';
}
}

return (string) $author;
Expand Down

0 comments on commit 608c611

Please sign in to comment.