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-1999: Added countAll function for URLWildcards #282

Merged
merged 3 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions eZ/Publish/API/Repository/URLWildcardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ public function loadAll(int $offset = 0, int $limit = -1): iterable;
* @return \eZ\Publish\API\Repository\Values\Content\URLWildcardTranslationResult
*/
public function translate(string $url): URLWildcardTranslationResult;

/**
* Counts URL Wildcards.
*/
public function countAll(): int;
}
10 changes: 10 additions & 0 deletions eZ/Publish/Core/Persistence/Cache/UrlWildcardHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,14 @@ public function exactSourceUrlExists(string $sourceUrl): bool

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

/**
* @see \eZ\Publish\SPI\Persistence\Content\UrlWildcard\Handler::countAll()
*/
public function countAll(): int
{
$this->logger->logCall(__METHOD__);

return $this->persistenceHandler->urlWildcardHandler()->countAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ 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;
}
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('count(id)')
mateuszdebinski marked this conversation as resolved.
Show resolved Hide resolved
->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,4 +98,13 @@ 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);
}
}
}
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 eZ/Publish/Core/Repository/URLWildcardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ public function loadAll(int $offset = 0, int $limit = -1): iterable
return $urlWildcards;
}

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

/**
* Translates an url to an existing uri resource based on the
* source/destination patterns of the url wildcard.
Expand Down
5 changes: 5 additions & 0 deletions eZ/Publish/SPI/Persistence/Content/UrlWildcard/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,9 @@ public function translate(string $sourceUrl): UrlWildcard;
* @return bool
*/
public function exactSourceUrlExists(string $sourceUrl): bool;

/**
* Counts URL Wildcards.
*/
public function countAll(): int;
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ public function translate(string $url): URLWildcardTranslationResult
{
return $this->innerService->translate($url);
}

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