asdasd
This commit is contained in:
@@ -1455,7 +1455,6 @@ class ApiKernel
|
||||
|
||||
private function handlePlaceholderSchema(): void
|
||||
{
|
||||
$user = $this->requireAuth();
|
||||
$user = $this->requireAuth();
|
||||
$this->ensureRole($user, ['owner', 'admin']);
|
||||
$customerId = (int)($user['customer_id'] ?? 0);
|
||||
@@ -1534,79 +1533,6 @@ class ApiKernel
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
private function fetchSchemaFromDirect(array $direct, array $tablesAllow = []): array
|
||||
{
|
||||
$host = trim((string)($direct['host'] ?? ''));
|
||||
$dbName = trim((string)($direct['database'] ?? ''));
|
||||
$user = trim((string)($direct['user'] ?? ''));
|
||||
$pass = (string)($direct['password'] ?? '');
|
||||
$charset = trim((string)($direct['charset'] ?? 'utf8mb4')) ?: 'utf8mb4';
|
||||
$port = (int)($direct['port'] ?? 3306);
|
||||
|
||||
if ($host === '' || $dbName === '' || $user === '') {
|
||||
throw new RuntimeException('DB settings missing');
|
||||
}
|
||||
|
||||
$dsn = "mysql:host={$host};port={$port};dbname={$dbName};charset={$charset}";
|
||||
$pdo = new PDO($dsn, $user, $pass, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
|
||||
$whitelist = [];
|
||||
foreach ($tablesAllow as $tbl) {
|
||||
if (is_string($tbl) && $tbl !== '') {
|
||||
$whitelist[strtolower($tbl)] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$tablesStmt = $pdo->query('SHOW FULL TABLES');
|
||||
$tables = [];
|
||||
while ($row = $tablesStmt->fetch(PDO::FETCH_NUM)) {
|
||||
$tableName = $row[0] ?? null;
|
||||
if (!$tableName) {
|
||||
continue;
|
||||
}
|
||||
if ($whitelist && empty($whitelist[strtolower($tableName)])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$columnsStmt = $pdo->prepare(
|
||||
'SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT, COLUMN_KEY, EXTRA
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = :schema AND TABLE_NAME = :table
|
||||
ORDER BY ORDINAL_POSITION'
|
||||
);
|
||||
$columnsStmt->execute([
|
||||
':schema' => $dbName,
|
||||
':table' => $tableName,
|
||||
]);
|
||||
$columns = [];
|
||||
foreach ($columnsStmt as $col) {
|
||||
$columns[] = [
|
||||
'name' => $col['COLUMN_NAME'],
|
||||
'type' => $col['DATA_TYPE'],
|
||||
'nullable' => ($col['IS_NULLABLE'] === 'YES'),
|
||||
'default' => $col['COLUMN_DEFAULT'],
|
||||
'key' => $col['COLUMN_KEY'],
|
||||
'extra' => $col['EXTRA'],
|
||||
'placeholder' => strtoupper($tableName) . '__' . strtoupper($col['COLUMN_NAME']),
|
||||
];
|
||||
}
|
||||
|
||||
$tables[] = [
|
||||
'name' => $tableName,
|
||||
'columns' => $columns,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'tables' => $tables,
|
||||
'fetched' => date(DATE_ATOM),
|
||||
];
|
||||
}
|
||||
|
||||
private function placeholderCachePath(string $url, string $token): string
|
||||
{
|
||||
$hash = md5($url . '|' . $token);
|
||||
@@ -2145,33 +2071,6 @@ class ApiKernel
|
||||
$user = $this->requireAuth();
|
||||
$this->ensureRole($user, ['owner', 'admin']);
|
||||
$customerId = (int)($user['customer_id'] ?? 0);
|
||||
$setup = $this->getBridgeSetupData($customerId);
|
||||
$mode = strtolower((string)($this->in['mode'] ?? $this->in['db_mode'] ?? ($setup['mode'] ?? 'bridge')));
|
||||
$importType = strtolower((string)($this->in['import_type'] ?? $this->in['bridge_import'] ?? ($setup['import_type'] ?? 'schema')));
|
||||
$tablesAllow = $this->normalizeBridgeTables($this->in['tables'] ?? ($setup['tables'] ?? []));
|
||||
|
||||
if ($mode === 'direct') {
|
||||
$direct = [
|
||||
'host' => trim((string)($this->in['direct_host'] ?? ($setup['direct']['host'] ?? ''))),
|
||||
'port' => (int)($this->in['direct_port'] ?? ($setup['direct']['port'] ?? 3306)),
|
||||
'database' => trim((string)($this->in['direct_database'] ?? ($setup['direct']['database'] ?? ''))),
|
||||
'user' => trim((string)($this->in['direct_user'] ?? ($setup['direct']['user'] ?? ''))),
|
||||
'password' => (string)($this->in['direct_password'] ?? ($setup['direct']['password'] ?? '')),
|
||||
'charset' => trim((string)($this->in['direct_charset'] ?? ($setup['direct']['charset'] ?? 'utf8mb4'))) ?: 'utf8mb4',
|
||||
];
|
||||
try {
|
||||
$schema = $this->fetchSchemaFromDirect($direct, $tablesAllow);
|
||||
} catch (Throwable $e) {
|
||||
$this->fail('DB request failed', $e->getMessage(), 502);
|
||||
return;
|
||||
}
|
||||
$this->respond([
|
||||
'ok' => true,
|
||||
'tables' => $schema['tables'] ?? [],
|
||||
'fetched' => $schema['fetched'] ?? date(DATE_ATOM),
|
||||
]);
|
||||
}
|
||||
|
||||
$bridgeUrl = trim((string)($this->in['bridge_url'] ?? ''));
|
||||
$bridgeToken = trim((string)($this->in['bridge_token'] ?? ''));
|
||||
if ($bridgeUrl === '' || $bridgeToken === '') {
|
||||
@@ -2189,28 +2088,6 @@ class ApiKernel
|
||||
return;
|
||||
}
|
||||
|
||||
if ($importType === 'settings') {
|
||||
$hint = is_array($schema['setup_hint'] ?? null) ? $schema['setup_hint'] : [];
|
||||
$directHint = is_array($hint['direct'] ?? null) ? $hint['direct'] : [];
|
||||
$direct = [
|
||||
'host' => trim((string)($directHint['host'] ?? '')),
|
||||
'port' => (int)($directHint['port'] ?? 3306),
|
||||
'database' => trim((string)($directHint['database'] ?? '')),
|
||||
'user' => trim((string)($directHint['user'] ?? '')),
|
||||
'password' => (string)($directHint['password'] ?? ''),
|
||||
'charset' => trim((string)($directHint['charset'] ?? 'utf8mb4')) ?: 'utf8mb4',
|
||||
];
|
||||
if ($direct['host'] === '' || $direct['database'] === '' || $direct['user'] === '') {
|
||||
$this->fail('Bridge lieferte keine DB-Settings', null, 422);
|
||||
}
|
||||
try {
|
||||
$schema = $this->fetchSchemaFromDirect($direct, $tablesAllow);
|
||||
} catch (Throwable $e) {
|
||||
$this->fail('DB request failed', $e->getMessage(), 502);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->respond([
|
||||
'ok' => true,
|
||||
'tables' => $schema['tables'] ?? [],
|
||||
@@ -2401,8 +2278,7 @@ class ApiKernel
|
||||
{
|
||||
return [
|
||||
'tables' => [],
|
||||
'mode' => 'bridge',
|
||||
'import_type' => 'schema',
|
||||
'mode' => 'direct',
|
||||
'direct' => [
|
||||
'host' => '',
|
||||
'port' => 3306,
|
||||
|
||||
Reference in New Issue
Block a user