Skip to content

Commit 1e3fe3f

Browse files
authored
[BUGFIX] Add check if generator is valid before traversing it
If there's no solr configuration for any site, saving pages or content results in a PHP exception: Uncaught TYPO3 Exception: Cannot traverse an already closed generator | Exception thrown in file .../Classes/Domain/Site/SiteRepository.php in line 135 The added check prevents this error. Fixes: #4284
1 parent ad25480 commit 1e3fe3f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Classes/Domain/Site/SiteRepository.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ public function getFirstAvailableSite(bool $stopOnInvalidSite = false): ?Site
106106
{
107107
$siteGenerator = $this->getAvailableTYPO3ManagedSites($stopOnInvalidSite);
108108
$siteGenerator->rewind();
109-
109+
if (!$siteGenerator->valid()) {
110+
return null;
111+
}
110112
$site = $siteGenerator->current();
111113

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

134136
$sites = [];
137+
if (!$siteGenerator->valid()) {
138+
return $sites;
139+
}
135140
foreach ($siteGenerator as $rootPageId => $site) {
136141
if (isset($sites[$rootPageId])) {
137142
//get each site only once
@@ -153,6 +158,9 @@ public function hasAvailableSites(bool $stopOnInvalidSite = false): bool
153158
{
154159
$siteGenerator = $this->getAvailableTYPO3ManagedSites($stopOnInvalidSite);
155160
$siteGenerator->rewind();
161+
if (!$siteGenerator->valid()) {
162+
return false;
163+
}
156164

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

172180
$siteGenerator = $this->getAvailableTYPO3ManagedSites($stopOnInvalidSite);
173181
$siteGenerator->rewind();
182+
if (!$siteGenerator->valid()) {
183+
return false;
184+
}
174185

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

0 commit comments

Comments
 (0)