Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

IBX-6644: Gracefully handle broken custom URL aliases #2111

Merged
merged 3 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ services:
lazy: true
arguments:
$configResolver: '@ezpublish.config.resolver'
tags:
- { name: 'monolog.logger', channel: 'ibexa.admin_ui' }

EzSystems\EzPlatformAdminUi\UI\Service\:
resource: '../../../lib/UI/Service'
Expand Down
28 changes: 26 additions & 2 deletions src/lib/UI/Dataset/CustomUrlsDataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

namespace EzSystems\EzPlatformAdminUi\UI\Dataset;

use eZ\Publish\API\Repository\Exceptions\BadStateException;
use eZ\Publish\API\Repository\URLAliasService;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\Content\URLAlias;
use EzSystems\EzPlatformAdminUi\UI\Value\ValueFactory;
use Psr\Log\LoggerInterface;

class CustomUrlsDataset
{
Expand All @@ -24,16 +26,21 @@ class CustomUrlsDataset
/** @var \EzSystems\EzPlatformAdminUi\UI\Value\Content\UrlAlias[] */
private $data;

/** @var \Psr\Log\LoggerInterface */
private $logger;

/**
* @param \eZ\Publish\API\Repository\URLAliasService $urlAliasService
* @param \EzSystems\EzPlatformAdminUi\UI\Value\ValueFactory $valueFactory
*/
public function __construct(
URLAliasService $urlAliasService,
ValueFactory $valueFactory
ValueFactory $valueFactory,
LoggerInterface $logger
) {
$this->urlAliasService = $urlAliasService;
$this->valueFactory = $valueFactory;
$this->logger = $logger;
}

/**
Expand All @@ -43,7 +50,24 @@ public function __construct(
*/
public function load(Location $location): self
{
$customUrlAliases = $this->urlAliasService->listLocationAliases($location, true, null, true);
try {
$customUrlAliases = $this->urlAliasService->listLocationAliases(
$location,
true,
null,
true
);
} catch (BadStateException $e) {
$this->logger->warning(
sprintf(
'At least one custom alias belonging to location %d is broken. Fix it by using the ezplatform:urls:regenerate-aliases command.',
$location->id
),
['exception' => $e]
);
$customUrlAliases = [];
}

$this->data = array_map(
function (URLAlias $urlAlias) {
return $this->valueFactory->createUrlAlias($urlAlias);
Expand Down
14 changes: 11 additions & 3 deletions src/lib/UI/Dataset/DatasetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@
use eZ\Publish\API\Repository\UserService;
use eZ\Publish\Core\MVC\ConfigResolverInterface;
use EzSystems\EzPlatformAdminUi\UI\Value\ValueFactory;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

class DatasetFactory
class DatasetFactory implements LoggerAwareInterface
{
use LoggerAwareTrait;

/** @var \eZ\Publish\API\Repository\ContentService */
protected $contentService;

Expand Down Expand Up @@ -66,7 +72,8 @@ public function __construct(
UserService $userService,
BookmarkService $bookmarkService,
ValueFactory $valueFactory,
ConfigResolverInterface $configResolver
ConfigResolverInterface $configResolver,
?LoggerInterface $logger = null
) {
$this->contentService = $contentService;
$this->contentTypeService = $contentTypeService;
Expand All @@ -79,6 +86,7 @@ public function __construct(
$this->bookmarkService = $bookmarkService;
$this->valueFactory = $valueFactory;
$this->configResolver = $configResolver;
$this->logger = $logger ?? new NullLogger();
}

/**
Expand Down Expand Up @@ -150,7 +158,7 @@ public function objectStates(): ObjectStatesDataset
*/
public function customUrls(): CustomUrlsDataset
{
return new CustomUrlsDataset($this->urlAliasService, $this->valueFactory);
return new CustomUrlsDataset($this->urlAliasService, $this->valueFactory, $this->logger);
}

/**
Expand Down
Loading