Assign the existing site to one landlord so stommer.info can run tenancy.

Seebad 0.3 stays in this release. With a single landlord every host still reaches the default website.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-23 12:00:11 +02:00
1 parent d9e52c4789
commit 8ebc1a3878
93 files changed
+2506 -112

No files matched your search

+59 -4
View File
@@ -4,6 +4,8 @@
use App\Models\Appearance;
use App\Models\Site;
use App\Models\SiteDomain;
use App\Models\Tenant;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Schema;
@@ -17,7 +19,12 @@ public function __construct(private ThemeRegistry $registry) {}
public function forRequest(Request $request): Theme
{
$site = $this->site($request->getHost());
$site = $this->siteForRequest($request->getHost());
if ($site === null) {
abort(404);
}
$isSigned = ($request->query('vorschau') || $request->query('theme')) && $request->hasValidSignature();
$preview = $isSigned && $request->query('vorschau') ? $site->appearances()->find($request->query('vorschau')) : null;
@@ -43,15 +50,63 @@ public function forSite(Site $site, ?Appearance $preview = null, bool $isPreview
);
}
/**
* The website for a console command: a matching host, otherwise the default website.
*/
public function site(?string $host = null): Site
{
return $this->matchedSite($host) ?? $this->defaultSite();
}
/**
* The website for an HTTP request. With two or more landlords an unknown host is not a website.
*/
public function siteForRequest(?string $host): ?Site
{
if (! Schema::hasTable('sites')) {
return $this->fallbackSite();
}
return ($host ? Site::query()->where('domain', $host)->first() : null)
?? Site::query()->where('is_default', true)->first()
?? Site::query()->orderBy('id')->first()
$matched = $this->matchedSite($host);
if ($matched !== null) {
return $matched;
}
if (Schema::hasTable('tenants') && Tenant::query()->count() > 1) {
return null;
}
return $this->defaultSite();
}
private function matchedSite(?string $host): ?Site
{
$host = is_string($host) ? mb_strtolower(trim($host)) : '';
if ($host === '' || ! Schema::hasTable('sites')) {
return null;
}
if (Schema::hasTable('site_domains')) {
$siteId = SiteDomain::query()->where('host', $host)->value('site_id');
if ($siteId) {
return Site::withoutGlobalScope('tenant')->find($siteId);
}
}
return Site::withoutGlobalScope('tenant')->whereRaw('lower(domain) = ?', [$host])->first();
}
private function defaultSite(): Site
{
if (! Schema::hasTable('sites')) {
return $this->fallbackSite();
}
return Site::withoutGlobalScope('tenant')->where('is_default', true)->first()
?? Site::withoutGlobalScope('tenant')->orderBy('id')->first()
?? $this->fallbackSite();
}