diff --git a/modules/mining-checker/bootstrap.php b/modules/mining-checker/bootstrap.php index 8cfed81..a6d4744 100644 --- a/modules/mining-checker/bootstrap.php +++ b/modules/mining-checker/bootstrap.php @@ -1,6 +1,9 @@ registerFunction('mining-checker', 'sql_import_target', static function (): array { + $moduleBasePath = __DIR__; + $config = ModuleConfig::load($moduleBasePath); + + return [ + 'pdo' => ConnectionFactory::make($config), + 'label' => 'Mining-Checker Projekt-Datenbank', + ]; +}); diff --git a/modules/mining-checker/src/Infrastructure/SchemaManager.php b/modules/mining-checker/src/Infrastructure/SchemaManager.php index 58446a6..f421522 100644 --- a/modules/mining-checker/src/Infrastructure/SchemaManager.php +++ b/modules/mining-checker/src/Infrastructure/SchemaManager.php @@ -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.', ]; diff --git a/partials/landingpages/modules/install.php b/partials/landingpages/modules/install.php index 830c5d3..a7391ce 100644 --- a/partials/landingpages/modules/install.php +++ b/partials/landingpages/modules/install.php @@ -31,6 +31,9 @@ foreach ($modules as $m) {
Module

Module installieren/aktivieren

Erkannte Module basieren auf Ordnern in modules/.

+

+ Zentralen SQL-Import oeffnen +