fix: исправлена критическая ошибка дублирования метода convertDateFormat
- Удалено дублирование метода convertDateFormat в DataService.php - Метод был объявлен дважды, что вызывало PHP Fatal Error - Fatal Error приводил к выводу HTML вместо JSON, вызывая ошибку парсинга в Tabulator - Исправлена ошибка "SyntaxError: The string did not match the expected pattern"
This commit is contained in:
@@ -329,7 +329,7 @@ public function insertMultipleRows(string $schema, string $table, array $rows, a
|
|||||||
$errorMsg = "Строка " . ($index + 1) . ": " . $this->formatPDOError($e, $schema, $table);
|
$errorMsg = "Строка " . ($index + 1) . ": " . $this->formatPDOError($e, $schema, $table);
|
||||||
$errorMessages[] = $errorMsg;
|
$errorMessages[] = $errorMsg;
|
||||||
|
|
||||||
// Логируем только первые 10 ошибок, чтобы не засорять лог
|
// Логируем только первые 10 ошибок
|
||||||
if ($errors <= 10) {
|
if ($errors <= 10) {
|
||||||
error_log("Ошибка импорта строки " . ($index + 1) . ": " . $e->getMessage());
|
error_log("Ошибка импорта строки " . ($index + 1) . ": " . $e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -381,37 +381,6 @@ private function convertDateFormat(string $date): string
|
|||||||
return $date;
|
return $date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Конвертирует различные форматы дат в формат MySQL (YYYY-MM-DD)
|
|
||||||
*/
|
|
||||||
private function convertDateFormat(string $date): string
|
|
||||||
{
|
|
||||||
$date = trim($date);
|
|
||||||
|
|
||||||
// Уже в нужном формате YYYY-MM-DD
|
|
||||||
if (preg_match('/^\d{4}-\d{2}-\d{2}/', $date)) {
|
|
||||||
return substr($date, 0, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Формат DD.MM.YYYY или DD/MM/YYYY или DD-MM-YYYY
|
|
||||||
if (preg_match('/^(\d{1,2})[\.\/-](\d{1,2})[\.\/-](\d{4})/', $date, $matches)) {
|
|
||||||
$day = str_pad($matches[1], 2, '0', STR_PAD_LEFT);
|
|
||||||
$month = str_pad($matches[2], 2, '0', STR_PAD_LEFT);
|
|
||||||
$year = $matches[3];
|
|
||||||
return "$year-$month-$day";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Пробуем распарсить через strtotime
|
|
||||||
$timestamp = strtotime($date);
|
|
||||||
if ($timestamp !== false) {
|
|
||||||
return date('Y-m-d', $timestamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Если не удалось распарсить - возвращаем как есть (будет ошибка от БД)
|
|
||||||
return $date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function exportCSV(
|
public function exportCSV(
|
||||||
string $schema,
|
string $schema,
|
||||||
string $table,
|
string $table,
|
||||||
|
|||||||
Reference in New Issue
Block a user