Files
fewo-stommer/app/Tenancy/AssignLegacyData.php
LarsandCursor 8ebc1a3878 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>
2026-10-23 12:00:11 +02:00

74 lines
1.7 KiB
PHP

<?php
namespace App\Tenancy;
use Illuminate\Support\Facades\DB;
/**
* Points every existing row at the landlord "Stommer". Used once, when tenancy is introduced
* on a database that already has the single-landlord data. Fresh databases have nothing to assign.
*/
class AssignLegacyData
{
/**
* Tables that gain a tenant_id. Order is irrelevant; nothing is deleted.
*
* @var list<string>
*/
public const TABLES = [
'sites',
'properties',
'guests',
'bookings',
'channels',
'portal_emails',
'photos',
'pages',
'appearances',
'notices',
'faqs',
'blocked_periods',
'amenities',
'reviews',
'channel_tasks',
'payments',
'seasons',
'extras',
'special_offers',
'channel_sync_logs',
'content_blocks',
];
public static function run(): void
{
$pending = false;
foreach (self::TABLES as $table) {
if (DB::table($table)->whereNull('tenant_id')->exists()) {
$pending = true;
break;
}
}
if (! $pending) {
return;
}
$tenantId = DB::table('tenants')->where('slug', 'stommer')->value('id');
if ($tenantId === null) {
$tenantId = DB::table('tenants')->insertGetId([
'name' => 'Stommer',
'slug' => 'stommer',
'is_active' => true,
'created_at' => now(),
'updated_at' => now(),
]);
}
foreach (self::TABLES as $table) {
DB::table($table)->whereNull('tenant_id')->update(['tenant_id' => $tenantId]);
}
}
}