Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check warning on line 1 in src/contracts/Repository/Decorator/URLAliasServiceDecorator.php

View workflow job for this annotation

GitHub Actions / Run code style check (8.1)

Found violation(s) of type: braces_position

Check warning on line 1 in src/contracts/Repository/Decorator/URLAliasServiceDecorator.php

View workflow job for this annotation

GitHub Actions / Run code style check (8.1)

Found violation(s) of type: Ibexa/multiline_parameters

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
Expand Down Expand Up @@ -92,9 +92,9 @@
);
}

public function load(string $id): URLAlias
public function load(string $id, ?bool $showAllTranslations = null): URLAlias
{
return $this->innerService->load($id);
return $this->innerService->load($id, $showAllTranslations);
}

public function refreshSystemUrlAliasesForLocation(Location $location): void
Expand Down
3 changes: 2 additions & 1 deletion src/contracts/Repository/URLAliasService.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check warning on line 1 in src/contracts/Repository/URLAliasService.php

View workflow job for this annotation

GitHub Actions / Run code style check (8.1)

Found violation(s) of type: Ibexa/multiline_parameters

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
Expand Down Expand Up @@ -156,10 +156,11 @@
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*
* @param string $id
* @param bool|null $showAllTranslations If enabled will include all aliases as if they were always available.
*
* @return \Ibexa\Contracts\Core\Repository\Values\Content\URLAlias
*/
public function load(string $id): URLAlias;
public function load(string $id, ?bool $showAllTranslations = null): URLAlias;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that sometimes we add additional parameters to the API method, but I just wanted to be sure that we want to do this in this scenario.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's justified here. listLocationAliases() and reverseLookup() already take ?bool $showAllTranslations = null with the same meaning, so load() was the odd one out. The admin-ui removeAction() gets alias IDs from a list that is built with all translations, then reloads each one by ID using the SiteAccess default. Aliases in languages outside the prioritized list therefore throw NotFoundException and can't be removed.

But I'm open to changing this if you think we shouldn't do it.


/**
* Refresh all system URL aliases for the given Location (and historize outdated if needed).
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Repository/SiteAccessAware/URLAliasService.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check warning on line 1 in src/lib/Repository/SiteAccessAware/URLAliasService.php

View workflow job for this annotation

GitHub Actions / Run code style check (8.1)

Found violation(s) of type: braces_position

Check warning on line 1 in src/lib/Repository/SiteAccessAware/URLAliasService.php

View workflow job for this annotation

GitHub Actions / Run code style check (8.1)

Found violation(s) of type: Ibexa/multiline_parameters

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
Expand Down Expand Up @@ -103,9 +103,9 @@
);
}

public function load(string $id): URLAlias
public function load(string $id, ?bool $showAllTranslations = null): URLAlias
{
return $this->service->load($id);
return $this->service->load($id, $showAllTranslations);
}

public function refreshSystemUrlAliasesForLocation(Location $location): void
Expand Down
5 changes: 3 additions & 2 deletions src/lib/Repository/URLAliasService.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check warning on line 1 in src/lib/Repository/URLAliasService.php

View workflow job for this annotation

GitHub Actions / Run code style check (8.1)

Found violation(s) of type: braces_position

Check warning on line 1 in src/lib/Repository/URLAliasService.php

View workflow job for this annotation

GitHub Actions / Run code style check (8.1)

Found violation(s) of type: Ibexa/multiline_parameters

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
Expand Down Expand Up @@ -721,16 +721,17 @@
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*
* @param string $id
* @param bool|null $showAllTranslations If enabled will include all aliases as if they were always available.
*
* @return \Ibexa\Contracts\Core\Repository\Values\Content\URLAlias
*/
public function load(string $id): URLAlias
public function load(string $id, ?bool $showAllTranslations = null): URLAlias
{
$spiUrlAlias = $this->urlAliasHandler->loadUrlAlias($id);
$path = $this->extractPath(
$spiUrlAlias,
null,
$this->languageResolver->getShowAllTranslations(),
$this->languageResolver->getShowAllTranslations($showAllTranslations),
$this->languageResolver->getPrioritizedLanguages()
);

Expand Down
93 changes: 93 additions & 0 deletions tests/integration/Core/Repository/URLAliasServiceTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check warning on line 1 in tests/integration/Core/Repository/URLAliasServiceTest.php

View workflow job for this annotation

GitHub Actions / Run code style check (8.1)

Found violation(s) of type: blank_lines_before_namespace

Check warning on line 1 in tests/integration/Core/Repository/URLAliasServiceTest.php

View workflow job for this annotation

GitHub Actions / Run code style check (8.1)

Found violation(s) of type: header_comment

Check warning on line 1 in tests/integration/Core/Repository/URLAliasServiceTest.php

View workflow job for this annotation

GitHub Actions / Run code style check (8.1)

Found violation(s) of type: fully_qualified_strict_types

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
Expand All @@ -14,6 +14,7 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Contracts\Core\Repository\Values\Content\URLAlias;
use Ibexa\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter;
use Ibexa\Core\Repository\SiteAccessAware\Language\LanguageResolver;
use Ibexa\Tests\Integration\Core\Repository\Common\SlugConverter as TestSlugConverter;
use PDO;
use RuntimeException;
Expand Down Expand Up @@ -145,6 +146,98 @@
);
}

public function testLoadThrowsNotFoundExceptionForTranslationNotInPrioritizedLanguages(): void
{
$repository = $this->getRepository();

$locationService = $repository->getLocationService();
$urlAliasService = $repository->getURLAliasService();

$location = $locationService->loadLocation($this->generateId('location', 12));

$this->createLanguage('nor-NO', 'Norwegian');
$createdUrlAlias = $urlAliasService->createUrlAlias(
$location,
'/My/Great-norwegian-site',
'nor-NO',
false,
false
);

$this->expectException(NotFoundException::class);

$urlAliasService->load($createdUrlAlias->id);
}

public function testLoadWithShowAllTranslations(): void
{
$repository = $this->getRepository();

$locationService = $repository->getLocationService();
$urlAliasService = $repository->getURLAliasService();

$location = $locationService->loadLocation($this->generateId('location', 12));

$this->createLanguage('nor-NO', 'Norwegian');
$createdUrlAlias = $urlAliasService->createUrlAlias(
$location,
'/My/Great-norwegian-site',
'nor-NO',
false,
false
);

$loadedUrlAlias = $urlAliasService->load($createdUrlAlias->id, true);

$this->assertUrlAliasPropertiesSame(
[
'type' => URLAlias::LOCATION,
'destination' => $location->id,
'path' => '/My/Great-norwegian-site',
'languageCodes' => ['nor-NO'],
'alwaysAvailable' => false,
'isHistory' => false,
'isCustom' => true,
'forward' => false,
],
$loadedUrlAlias
);
}

Comment thread
papcio122 marked this conversation as resolved.
Resolved
public function testLoadWithExplicitlyDisabledShowAllTranslationsOverridesConfiguredDefault(): void
{
$repository = $this->getRepository();

$locationService = $repository->getLocationService();
$urlAliasService = $repository->getURLAliasService();

$location = $locationService->loadLocation($this->generateId('location', 12));

$this->createLanguage('nor-NO', 'Norwegian');
$createdUrlAlias = $urlAliasService->createUrlAlias(
$location,
'/My/Great-norwegian-site',
'nor-NO',
false,
false
);

/** @var \Ibexa\Core\Repository\SiteAccessAware\Language\LanguageResolver $languageResolver */
$languageResolver = $this->getSetupFactory()->getServiceContainer()->get(LanguageResolver::class);
$languageResolver->setShowAllTranslations(true);

try {
// Sanity check: configured default makes the alias loadable
self::assertSame($createdUrlAlias->id, $urlAliasService->load($createdUrlAlias->id)->id);

$this->expectException(NotFoundException::class);

$urlAliasService->load($createdUrlAlias->id, false);
} finally {
$languageResolver->setShowAllTranslations(false);
}
}

/**
* @param array $testData
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ public function testLoadDecorator()
$serviceMock = $this->createServiceMock();
$decoratedService = $this->createDecorator($serviceMock);

$parameters = ['random_value_5ced05ce0f4839.47843200'];
$parameters = [
'random_value_5ced05ce0f4839.47843200',
true,
];

$serviceMock->expects($this->once())->method('load')->with(...$parameters);

Expand Down
Loading