importer general
All checks were successful
Deploy / deploy-staging (push) Successful in 5s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-04-11 03:25:38 +02:00
parent 37f5b7f5e6
commit 067f962cb2
8 changed files with 277 additions and 25 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Modules\MiningChecker\Infrastructure;
use App\SqlDataImporter;
use App\UploadedSqlFile;
use Modules\MiningChecker\Support\ApiException;
use PDO;
@@ -370,34 +371,16 @@ final class SchemaManager
public function importSqlFile(array $uploadedFile): array
{
$errorCode = (int) ($uploadedFile['error'] ?? UPLOAD_ERR_NO_FILE);
if ($errorCode !== UPLOAD_ERR_OK) {
throw new ApiException(
'SQL-Datei konnte nicht hochgeladen werden.',
422,
['upload_error' => $errorCode]
);
try {
$file = UploadedSqlFile::read($uploadedFile);
} catch (\RuntimeException $exception) {
throw new ApiException($exception->getMessage(), 422);
}
$originalName = (string) ($uploadedFile['name'] ?? 'import.sql');
$tmpPath = (string) ($uploadedFile['tmp_name'] ?? '');
if ($tmpPath === '' || !is_uploaded_file($tmpPath)) {
throw new ApiException('Ungueltige Upload-Datei fuer SQL-Import.', 422);
}
if (!preg_match('/\.sql$/i', $originalName)) {
throw new ApiException('Bitte eine SQL-Datei mit Endung .sql hochladen.', 422, ['file' => $originalName]);
}
$sql = @file_get_contents($tmpPath);
if (!is_string($sql) || trim($sql) === '') {
throw new ApiException('Die hochgeladene SQL-Datei ist leer oder konnte nicht gelesen werden.', 422, ['file' => $originalName]);
}
$statementCount = $this->executeSqlContent($sql, $originalName);
$statementCount = $this->executeSqlContent((string) $file['sql'], (string) $file['file']);
return [
'file' => $originalName,
'file' => (string) $file['file'],
'statement_count' => $statementCount,
'message' => 'SQL-Datei wurde erfolgreich eingespielt.',
];