Skip to content

Commit

Permalink
Merged branch '1.3' of ezsystems/ezplatform-kernel into main (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz authored Jan 28, 2022
2 parents d3b4c6b + 9be8e22 commit dcf4562
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/contracts/Persistence/Content/UrlWildcard/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public function translate(string $sourceUrl): UrlWildcard;
* @return bool
*/
public function exactSourceUrlExists(string $sourceUrl): bool;

/**
* Counts URL Wildcards.
*/
public function countAll(): int;
}

class_alias(Handler::class, 'eZ\Publish\SPI\Persistence\Content\UrlWildcard\Handler');
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public function translate(string $url): URLWildcardTranslationResult
{
return $this->innerService->translate($url);
}

public function countAll(): int
{
return $this->innerService->countAll();
}
}

class_alias(URLWildcardServiceDecorator::class, 'eZ\Publish\SPI\Repository\Decorator\URLWildcardServiceDecorator');
5 changes: 5 additions & 0 deletions src/contracts/Repository/URLWildcardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public function loadAll(int $offset = 0, int $limit = -1): iterable;
* @return \Ibexa\Contracts\Core\Repository\Values\Content\URLWildcardTranslationResult
*/
public function translate(string $url): URLWildcardTranslationResult;

/**
* Counts URL Wildcards.
*/
public function countAll(): int;
}

class_alias(URLWildcardService::class, 'eZ\Publish\API\Repository\URLWildcardService');
7 changes: 7 additions & 0 deletions src/lib/Persistence/Cache/UrlWildcardHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ public function exactSourceUrlExists(string $sourceUrl): bool

return $this->persistenceHandler->urlWildcardHandler()->exactSourceUrlExists($sourceUrl);
}

public function countAll(): int
{
$this->logger->logCall(__METHOD__);

return $this->persistenceHandler->urlWildcardHandler()->countAll();
}
}

class_alias(UrlWildcardHandler::class, 'eZ\Publish\Core\Persistence\Cache\UrlWildcardHandler');
2 changes: 2 additions & 0 deletions src/lib/Persistence/Legacy/Content/UrlWildcard/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ abstract public function loadUrlWildcardsData(int $offset = 0, int $limit = -1):
* Load the UrlWildcard by source url $sourceUrl.
*/
abstract public function loadUrlWildcardBySourceUrl(string $sourceUrl): array;

abstract public function countAll(): int;
}

class_alias(Gateway::class, 'eZ\Publish\Core\Persistence\Legacy\Content\UrlWildcard\Gateway');
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ public function loadUrlWildcardBySourceUrl(string $sourceUrl): array
return false !== $result ? $result : [];
}

public function countAll(): int
{
$query = $this->connection->createQueryBuilder();
$query
->select($this->connection->getDatabasePlatform()->getCountExpression('id'))
->from(self::URL_WILDCARD_TABLE);

return (int) $query->execute()->fetchColumn();
}

private function trimUrl(string $url): string
{
return trim($url, '/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ public function loadUrlWildcardBySourceUrl(string $sourceUrl): array
throw DatabaseException::wrap($e);
}
}

public function countAll(): int
{
try {
return $this->innerGateway->countAll();
} catch (DBALException | PDOException $e) {
throw DatabaseException::wrap($e);
}
}
}

class_alias(ExceptionConversion::class, 'eZ\Publish\Core\Persistence\Legacy\Content\UrlWildcard\Gateway\ExceptionConversion');
8 changes: 8 additions & 0 deletions src/lib/Persistence/Legacy/Content/UrlWildcard/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ public function exactSourceUrlExists(string $sourceUrl): bool
return !empty($row);
}

/**
* {@inheritDoc}
*/
public function countAll(): int
{
return $this->gateway->countAll();
}

/**
* Tests if the given url matches against the given url wildcard.
*
Expand Down
8 changes: 8 additions & 0 deletions src/lib/Repository/URLWildcardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ public function translate(string $url): URLWildcardTranslationResult
);
}

/**
* {@inheritDoc}
*/
public function countAll(): int
{
return $this->urlWildcardHandler->countAll();
}

/**
* Builds API UrlWildcard object from given SPI UrlWildcard object.
*
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/Core/Repository/URLWildcardServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,24 @@ public function testTranslateThrowsNotFoundExceptionWhenNotAliasOrWildcardMatche
$urlWildcardService->translate('/sindelfingen');
/* END: Use Case */
}

public function testCountAllReturnsZeroByDefault(): void
{
$repository = $this->getRepository();
$urlWildcardService = $repository->getURLWildcardService();

$this->assertSame(0, $urlWildcardService->countAll());
}

public function testCountAll(): void
{
$repository = $this->getRepository();
$urlWildcardService = $repository->getURLWildcardService();

$urlWildcardService->create('/articles/*', '/content/{1}');

$this->assertSame(1, $urlWildcardService->countAll());
}
}

class_alias(URLWildcardServiceTest::class, 'eZ\Publish\API\Repository\Tests\URLWildcardServiceTest');

0 comments on commit dcf4562

Please sign in to comment.