Skip to content

Commit dcf4562

Browse files
authored
Merged branch '1.3' of ezsystems/ezplatform-kernel into main (#64)
Merge up of ezsystems/ezplatform-kernel#282
2 parents d3b4c6b + 9be8e22 commit dcf4562

File tree

10 files changed

+77
-0
lines changed

10 files changed

+77
-0
lines changed

src/contracts/Persistence/Content/UrlWildcard/Handler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ public function translate(string $sourceUrl): UrlWildcard;
8383
* @return bool
8484
*/
8585
public function exactSourceUrlExists(string $sourceUrl): bool;
86+
87+
/**
88+
* Counts URL Wildcards.
89+
*/
90+
public function countAll(): int;
8691
}
8792

8893
class_alias(Handler::class, 'eZ\Publish\SPI\Persistence\Content\UrlWildcard\Handler');

src/contracts/Repository/Decorator/URLWildcardServiceDecorator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public function translate(string $url): URLWildcardTranslationResult
5959
{
6060
return $this->innerService->translate($url);
6161
}
62+
63+
public function countAll(): int
64+
{
65+
return $this->innerService->countAll();
66+
}
6267
}
6368

6469
class_alias(URLWildcardServiceDecorator::class, 'eZ\Publish\SPI\Repository\Decorator\URLWildcardServiceDecorator');

src/contracts/Repository/URLWildcardService.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ public function loadAll(int $offset = 0, int $limit = -1): iterable;
9595
* @return \Ibexa\Contracts\Core\Repository\Values\Content\URLWildcardTranslationResult
9696
*/
9797
public function translate(string $url): URLWildcardTranslationResult;
98+
99+
/**
100+
* Counts URL Wildcards.
101+
*/
102+
public function countAll(): int;
98103
}
99104

100105
class_alias(URLWildcardService::class, 'eZ\Publish\API\Repository\URLWildcardService');

src/lib/Persistence/Cache/UrlWildcardHandler.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ public function exactSourceUrlExists(string $sourceUrl): bool
167167

168168
return $this->persistenceHandler->urlWildcardHandler()->exactSourceUrlExists($sourceUrl);
169169
}
170+
171+
public function countAll(): int
172+
{
173+
$this->logger->logCall(__METHOD__);
174+
175+
return $this->persistenceHandler->urlWildcardHandler()->countAll();
176+
}
170177
}
171178

172179
class_alias(UrlWildcardHandler::class, 'eZ\Publish\Core\Persistence\Cache\UrlWildcardHandler');

src/lib/Persistence/Legacy/Content/UrlWildcard/Gateway.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ abstract public function loadUrlWildcardsData(int $offset = 0, int $limit = -1):
5454
* Load the UrlWildcard by source url $sourceUrl.
5555
*/
5656
abstract public function loadUrlWildcardBySourceUrl(string $sourceUrl): array;
57+
58+
abstract public function countAll(): int;
5759
}
5860

5961
class_alias(Gateway::class, 'eZ\Publish\Core\Persistence\Legacy\Content\UrlWildcard\Gateway');

src/lib/Persistence/Legacy/Content/UrlWildcard/Gateway/DoctrineDatabase.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,16 @@ public function loadUrlWildcardBySourceUrl(string $sourceUrl): array
176176
return false !== $result ? $result : [];
177177
}
178178

179+
public function countAll(): int
180+
{
181+
$query = $this->connection->createQueryBuilder();
182+
$query
183+
->select($this->connection->getDatabasePlatform()->getCountExpression('id'))
184+
->from(self::URL_WILDCARD_TABLE);
185+
186+
return (int) $query->execute()->fetchColumn();
187+
}
188+
179189
private function trimUrl(string $url): string
180190
{
181191
return trim($url, '/');

src/lib/Persistence/Legacy/Content/UrlWildcard/Gateway/ExceptionConversion.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ public function loadUrlWildcardBySourceUrl(string $sourceUrl): array
9898
throw DatabaseException::wrap($e);
9999
}
100100
}
101+
102+
public function countAll(): int
103+
{
104+
try {
105+
return $this->innerGateway->countAll();
106+
} catch (DBALException | PDOException $e) {
107+
throw DatabaseException::wrap($e);
108+
}
109+
}
101110
}
102111

103112
class_alias(ExceptionConversion::class, 'eZ\Publish\Core\Persistence\Legacy\Content\UrlWildcard\Gateway\ExceptionConversion');

src/lib/Persistence/Legacy/Content/UrlWildcard/Handler.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ public function exactSourceUrlExists(string $sourceUrl): bool
191191
return !empty($row);
192192
}
193193

194+
/**
195+
* {@inheritDoc}
196+
*/
197+
public function countAll(): int
198+
{
199+
return $this->gateway->countAll();
200+
}
201+
194202
/**
195203
* Tests if the given url matches against the given url wildcard.
196204
*

src/lib/Repository/URLWildcardService.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ public function translate(string $url): URLWildcardTranslationResult
229229
);
230230
}
231231

232+
/**
233+
* {@inheritDoc}
234+
*/
235+
public function countAll(): int
236+
{
237+
return $this->urlWildcardHandler->countAll();
238+
}
239+
232240
/**
233241
* Builds API UrlWildcard object from given SPI UrlWildcard object.
234242
*

tests/integration/Core/Repository/URLWildcardServiceTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,24 @@ public function testTranslateThrowsNotFoundExceptionWhenNotAliasOrWildcardMatche
538538
$urlWildcardService->translate('/sindelfingen');
539539
/* END: Use Case */
540540
}
541+
542+
public function testCountAllReturnsZeroByDefault(): void
543+
{
544+
$repository = $this->getRepository();
545+
$urlWildcardService = $repository->getURLWildcardService();
546+
547+
$this->assertSame(0, $urlWildcardService->countAll());
548+
}
549+
550+
public function testCountAll(): void
551+
{
552+
$repository = $this->getRepository();
553+
$urlWildcardService = $repository->getURLWildcardService();
554+
555+
$urlWildcardService->create('/articles/*', '/content/{1}');
556+
557+
$this->assertSame(1, $urlWildcardService->countAll());
558+
}
541559
}
542560

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

0 commit comments

Comments
 (0)