This commit is contained in:
2025-12-09 00:03:50 +01:00
parent 2a167c0c4d
commit 9488fe1ea4
2 changed files with 70 additions and 10 deletions

View File

@@ -2011,9 +2011,10 @@ class ApiKernel
private function ensureCustomerSettingsTableExists(): void
{
$table = $this->customerSettingsTable();
if ($this->tableExists($table)) return;
try {
$sql = <<<SQL
$justCreated = false;
if (!$this->tableExists($table)) {
try {
$sql = <<<SQL
CREATE TABLE IF NOT EXISTS `$table` (
`customer_id` int(10) unsigned NOT NULL,
`bridge_url` varchar(500) DEFAULT NULL,
@@ -2026,10 +2027,45 @@ CREATE TABLE IF NOT EXISTS `$table` (
PRIMARY KEY (`customer_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
SQL;
$this->pdo->exec($sql);
$this->tableExistsCache[$table] = true;
$this->pdo->exec($sql);
$this->tableExistsCache[$table] = true;
$justCreated = true;
} catch (Throwable $e) {
$this->fail('Customer-Settings Tabelle fehlt und konnte nicht erstellt werden', $e->getMessage(), 500);
}
}
if ($justCreated) {
return;
}
$this->ensureCustomerSettingsColumns($table);
}
private function ensureCustomerSettingsColumns(string $table): void
{
try {
$columns = $this->tableColumns($table);
} catch (Throwable $e) {
$this->fail('Customer-Settings Tabelle fehlt und konnte nicht erstellt werden', $e->getMessage(), 500);
$this->fail('Customer-Settings Tabelle konnte nicht gelesen werden', $e->getMessage(), 500);
return;
}
$missing = [];
if (!in_array('bridge_tables', $columns, true)) {
$missing[] = 'ADD COLUMN `bridge_tables` text DEFAULT NULL';
}
if (!$missing) {
return;
}
try {
$sql = 'ALTER TABLE `' . $table . '` ' . implode(', ', $missing);
$this->pdo->exec($sql);
} catch (Throwable $e) {
$this->fail('Customer-Settings Tabelle konnte nicht aktualisiert werden', $e->getMessage(), 500);
}
}