debug: добавлена детальная отладка импорта CSV
- Добавлено логирование парсинга CSV на фронтенде - Добавлено логирование отправляемых данных - Добавлено детальное логирование в PHP бэкенде (каждая строка импорта) - Улучшена обработка ошибок с выводом подробной информации - Добавлен вывод SQL запросов при ошибках
This commit is contained in:
@@ -172,22 +172,63 @@ $app->post('/api/table/delete', function (Request $request, Response $response)
|
||||
|
||||
// API: импорт CSV (массовая вставка)
|
||||
$app->post('/api/table/import-csv', function (Request $request, Response $response) use ($container) {
|
||||
$payload = json_decode((string)$request->getBody(), true);
|
||||
error_log("\n========== ЗАПРОС НА ИМПОРТ CSV ==========");
|
||||
|
||||
$body = (string)$request->getBody();
|
||||
error_log("Тело запроса (первые 1000 символов): " . substr($body, 0, 1000));
|
||||
|
||||
$payload = json_decode($body, true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
error_log("ОШИБКА JSON: " . json_last_error_msg());
|
||||
$response->getBody()->write(json_encode(['error' => 'Invalid JSON: ' . json_last_error_msg()]));
|
||||
return $response->withHeader('Content-Type', 'application/json')->withStatus(400);
|
||||
}
|
||||
|
||||
error_log("Декодированный payload: " . json_encode($payload, JSON_PRETTY_PRINT));
|
||||
|
||||
$pdo = $container->get('db');
|
||||
$meta = new \App\MetaService($pdo);
|
||||
$ds = new \App\DataService($pdo);
|
||||
|
||||
$schema = $payload['schema'];
|
||||
$table = $payload['table'];
|
||||
$schema = $payload['schema'] ?? '';
|
||||
$table = $payload['table'] ?? '';
|
||||
$rows = $payload['rows'] ?? [];
|
||||
$metaArr = $meta->getTableMeta($schema, $table);
|
||||
|
||||
$result = $ds->insertMultipleRows($schema, $table, $rows, $metaArr['columns']);
|
||||
|
||||
$response->getBody()->write(json_encode($result));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
error_log("Schema: $schema");
|
||||
error_log("Table: $table");
|
||||
error_log("Количество строк: " . count($rows));
|
||||
|
||||
if (empty($schema) || empty($table)) {
|
||||
error_log("ОШИБКА: пустая schema или table");
|
||||
$response->getBody()->write(json_encode(['error' => 'Schema and table are required']));
|
||||
return $response->withHeader('Content-Type', 'application/json')->withStatus(400);
|
||||
}
|
||||
|
||||
try {
|
||||
$metaArr = $meta->getTableMeta($schema, $table);
|
||||
error_log("Метаданные таблицы получены, столбцов: " . count($metaArr['columns']));
|
||||
|
||||
$result = $ds->insertMultipleRows($schema, $table, $rows, $metaArr['columns']);
|
||||
|
||||
error_log("Результат импорта: " . json_encode($result));
|
||||
|
||||
$response->getBody()->write(json_encode($result));
|
||||
return $response->withHeader('Content-Type', 'application/json');
|
||||
} catch (\Exception $e) {
|
||||
error_log("КРИТИЧЕСКАЯ ОШИБКА: " . $e->getMessage());
|
||||
error_log("Stack trace: " . $e->getTraceAsString());
|
||||
|
||||
$response->getBody()->write(json_encode([
|
||||
'error' => $e->getMessage(),
|
||||
'inserted' => 0,
|
||||
'errors' => 1
|
||||
]));
|
||||
return $response->withHeader('Content-Type', 'application/json')->withStatus(500);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// API: экспорт CSV
|
||||
$app->post('/api/table/export-csv', function (Request $request, Response $response) use ($container) {
|
||||
$payload = json_decode((string)$request->getBody(), true);
|
||||
|
||||
Reference in New Issue
Block a user