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 2 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'
calls:
- [setLogger, ['@?logger']]
barw4 marked this conversation as resolved.
Show resolved Hide resolved

EzSystems\EzPlatformAdminUi\UI\Service\:
resource: '../../../lib/UI/Service'
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/Resources/translations/content_url.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
<note>key: tab.urls.modal_close</note>
</trans-unit>
<trans-unit id="56d218db883ed4cc59dbbca53364dc2e725013e4" resname="tab.urls.no_custom_urls">
<source>This Content item has no custom URL aliases.</source>
<target state="new">This Content item has no custom URL aliases.</target>
<source>This Content item has no custom URL aliases or they are broken.</source>
<target state="new">This Content item has no custom URL aliases or they are broken.</target>
<note>key: tab.urls.no_custom_urls</note>
</trans-unit>
<trans-unit id="c9fdd1434b44a4592626e8fe493c19141aab24d5" resname="tab.urls.no_system_urls">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<tr>
<td class="ez-table__cell ez-table__cell--no-content" colspan="4">
<p class="ez-table-no-content mb-0 py-0">
{{ 'tab.urls.no_custom_urls'|trans|desc('This Content item has no custom URL aliases.') }}
{{ 'tab.urls.no_custom_urls'|trans|desc('This Content item has no custom URL aliases or they are broken.') }}
barw4 marked this conversation as resolved.
Show resolved Hide resolved
</p>
</td>
</tr>
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
),
[$e->getMessage()]
);
barw4 marked this conversation as resolved.
Show resolved Hide resolved
$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