diff --git a/app/pages/admin.php b/app/pages/admin.php index 7c0b02b..7d343b2 100644 --- a/app/pages/admin.php +++ b/app/pages/admin.php @@ -169,19 +169,22 @@ foreach ($pluginCatalog as $slug => $info) { $hasMigration = !empty($migrationFiles); $existingTables = []; - if ($hasMigration && isset($db) && $db instanceof PDO) { - $stmt = $db->query("SHOW TABLES"); - $allTables = $stmt->fetchAll(PDO::FETCH_COLUMN, 0); + if ($hasMigration) { + $db = \App\App::db(); + if ($db instanceof PDO) { + $stmt = $db->query("SHOW TABLES"); + $allTables = $stmt->fetchAll(PDO::FETCH_COLUMN, 0); - foreach ($migrationFiles as $migrationFile) { - $migrationContent = file_get_contents($migrationFile); - foreach ($allTables as $table) { - if (strpos($migrationContent, $table) !== false) { - $existingTables[] = $table; + foreach ($migrationFiles as $migrationFile) { + $migrationContent = file_get_contents($migrationFile); + foreach ($allTables as $table) { + if (strpos($migrationContent, $table) !== false) { + $existingTables[] = $table; + } } } + $existingTables = array_unique($existingTables); } - $existingTables = array_unique($existingTables); } $pluginAdminMap[$slug] = [ @@ -599,7 +602,7 @@ if ($queryAction === 'plugin_check_page' && isset($_GET['plugin'])) { ]; // Check database tables - global $db; + $db = \App\App::db(); $pluginTables = []; if ($db instanceof PDO) { $stmt = $db->query("SHOW TABLES"); diff --git a/app/templates/admin.php b/app/templates/admin.php index f3fc745..0729e73 100644 --- a/app/templates/admin.php +++ b/app/templates/admin.php @@ -664,7 +664,7 @@ endif; ?> ]; // Check database tables - global $db; + $db = \App\App::db(); $pluginTables = []; if ($db instanceof PDO) { $stmt = $db->query("SHOW TABLES"); @@ -690,8 +690,30 @@ endif; ?> if (file_exists($bootstrapPath)) { include_once $bootstrapPath; $migrationFunction = str_replace('-', '_', $plugin['slug']) . '_ensure_tables'; + $migrationTestResult = null; + + // Test migration function if it exists + if (function_exists($migrationFunction)) { + try { + // Check if plugin tables already exist + $tablesExist = !empty($pluginTables); + + if ($tablesExist) { + $migrationTestResult = 'already installed'; + } else { + // For plugins without tables, the function exists and is ready + $migrationTestResult = 'function ready (tables not installed)'; + } + } catch (Exception $e) { + $migrationTestResult = 'error: ' . $e->getMessage(); + } + } else { + $migrationTestResult = 'not applicable'; + } + $checkResults['functions'] = [ 'migration' => function_exists($migrationFunction), + 'migration_test' => $migrationTestResult ?: 'not applicable', ]; } @@ -752,13 +774,33 @@ endif; ?>
Functions Check
- $exists): ?> -
- () - - - -
+ $value): ?> + +
+ Migration Test + + Not Applicable + + Already Installed + + Passed + + Failed + +
+ +
Plugin tables already exist - migration not needed
+ +
+ + +
+ () + + + +
+
@@ -793,13 +835,6 @@ endif; ?> -
- - - - - -