Skip to content

[BUGFIX] Add check if generator is valid before traversing it #4283

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

Merged
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
13 changes: 12 additions & 1 deletion Classes/Domain/Site/SiteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ public function getFirstAvailableSite(bool $stopOnInvalidSite = false): ?Site
{
$siteGenerator = $this->getAvailableTYPO3ManagedSites($stopOnInvalidSite);
$siteGenerator->rewind();

if (!$siteGenerator->valid()) {
return null;
}
$site = $siteGenerator->current();

return $site instanceof Site ? $site : null;
Expand All @@ -132,6 +134,9 @@ public function getAvailableSites(bool $stopOnInvalidSite = false): array
$siteGenerator->rewind();

$sites = [];
if (!$siteGenerator->valid()) {
return $sites;
}
foreach ($siteGenerator as $rootPageId => $site) {
if (isset($sites[$rootPageId])) {
//get each site only once
Expand All @@ -153,6 +158,9 @@ public function hasAvailableSites(bool $stopOnInvalidSite = false): bool
{
$siteGenerator = $this->getAvailableTYPO3ManagedSites($stopOnInvalidSite);
$siteGenerator->rewind();
if (!$siteGenerator->valid()) {
return false;
}

return ($site = $siteGenerator->current()) && $site instanceof Site;
}
Expand All @@ -171,6 +179,9 @@ public function hasExactlyOneAvailableSite(bool $stopOnInvalidSite = false): boo

$siteGenerator = $this->getAvailableTYPO3ManagedSites($stopOnInvalidSite);
$siteGenerator->rewind();
if (!$siteGenerator->valid()) {
return false;
}

// We start with 1 here as we know from hasAvailableSites() above we have at least one site
$counter = 1;
Expand Down
Loading