Skip to content

Commit

Permalink
Add logging to the RelationService
Browse files Browse the repository at this point in the history
  • Loading branch information
pspanja committed Mar 1, 2023
1 parent bd0fb55 commit 8f0c53b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
32 changes: 28 additions & 4 deletions lib/Core/Site/RelationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
use Netgen\IbexaSiteApi\API\Values\Location;
use Netgen\IbexaSiteApi\Core\Site\Plugins\FieldType\RelationResolver\Registry as RelationResolverRegistry;
use Netgen\IbexaSiteApi\Core\Traits\SearchResultExtractorTrait;
use Psr\Log\LoggerInterface;

use function array_filter;
use function array_flip;
use function array_slice;
use function in_array;
use function sprintf;
use function usort;

/**
Expand All @@ -34,6 +36,7 @@ class RelationService implements RelationServiceInterface
public function __construct(
private readonly SiteInterface $site,
private readonly RelationResolverRegistry $relationResolverRegistry,
private readonly LoggerInterface $logger,
) {
}

Expand Down Expand Up @@ -102,13 +105,26 @@ public function loadFieldRelationLocations(

foreach ($relatedContentItems as $relatedContentItem) {
try {
if ($relatedContentItem->mainLocation === null) {
if ($relatedContentItem->mainLocationId === null) {
$this->logger->debug(
sprintf(
'Could not load related Location: Content #%s has no Locations',
$relatedContentItem->id,
),
);

continue;
}

$relatedLocations[] = $relatedContentItem->mainLocation;
} catch (Exception) {
// do nothing
} catch (Exception $exception) {
$this->logger->debug(
sprintf(
'Could not load related Location #%s: %s',
$relatedContentItem->mainLocationId,
$exception->getMessage(),
),
);
}
}

Expand Down Expand Up @@ -140,7 +156,15 @@ private function getRelatedContentItems(array $relatedContentIds, array $content
foreach ($relatedContentIds as $contentId) {
try {
$content = $this->site->getLoadService()->loadContent($contentId);
} catch (Exception) {
} catch (Exception $exception) {
$this->logger->debug(
sprintf(
'Could not load related Content #%s: %s',
$contentId,
$exception->getMessage(),
),
);

continue;
}

Expand Down
1 change: 1 addition & 0 deletions lib/Core/Site/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public function getRelationService(): APIRelationService
$this->relationService = new RelationService(
$this,
$this->relationResolverRegistry,
$this->logger,
);
}

Expand Down

0 comments on commit 8f0c53b

Please sign in to comment.