diff --git a/app/pages/admin.php b/app/pages/admin.php index 7d343b2..9af4a03 100644 --- a/app/pages/admin.php +++ b/app/pages/admin.php @@ -603,25 +603,41 @@ if ($queryAction === 'plugin_check_page' && isset($_GET['plugin'])) { // Check database tables $db = \App\App::db(); - $pluginTables = []; - if ($db instanceof PDO) { - $stmt = $db->query("SHOW TABLES"); + $pluginOwnedTables = []; + $pluginReferencedTables = []; + if ($db && method_exists($db, 'getConnection')) { + $pdo = $db->getConnection(); + $stmt = $pdo->query("SHOW TABLES"); $allTables = $stmt->fetchAll(PDO::FETCH_COLUMN, 0); if ($hasMigration) { - // Check each migration file for table references foreach ($migrationFiles as $migrationFile) { $migrationContent = file_get_contents($migrationFile); + + // Extract tables created by this migration (plugin-owned) + if (preg_match_all('/CREATE\s+TABLE(?:\s+IF\s+NOT\s+EXISTS)?\s+`?([a-zA-Z0-9_]+)`?/i', $migrationContent, $matches)) { + foreach ($matches[1] as $tableName) { + if (in_array($tableName, $allTables)) { + $pluginOwnedTables[] = $tableName; + } + } + } + + // Find all referenced tables (dependencies) foreach ($allTables as $table) { - if (strpos($migrationContent, $table) !== false) { - $pluginTables[] = $table; + if (strpos($migrationContent, $table) !== false && !in_array($table, $pluginOwnedTables)) { + $pluginReferencedTables[] = $table; } } } - $pluginTables = array_unique($pluginTables); + $pluginOwnedTables = array_unique($pluginOwnedTables); + $pluginReferencedTables = array_unique($pluginReferencedTables); } } - $checkResults['tables'] = $pluginTables; + $checkResults['tables'] = [ + 'owned' => $pluginOwnedTables, + 'referenced' => $pluginReferencedTables, + ]; // Check plugin functions $bootstrapPath = $pluginInfo['path'] . '/bootstrap.php'; diff --git a/app/templates/admin.php b/app/templates/admin.php index b96dfe5..2c91227 100644 --- a/app/templates/admin.php +++ b/app/templates/admin.php @@ -628,25 +628,41 @@ endif; ?> // Check database tables $db = \App\App::db(); - $pluginTables = []; - if ($db instanceof PDO) { - $stmt = $db->query("SHOW TABLES"); + $pluginOwnedTables = []; + $pluginReferencedTables = []; + if ($db && method_exists($db, 'getConnection')) { + $pdo = $db->getConnection(); + $stmt = $pdo->query("SHOW TABLES"); $allTables = $stmt->fetchAll(PDO::FETCH_COLUMN, 0); if ($hasMigration) { - // Check each migration file for table references foreach ($migrationFiles as $migrationFile) { $migrationContent = file_get_contents($migrationFile); + + // Extract tables created by this migration (plugin-owned) + if (preg_match_all('/CREATE\s+TABLE(?:\s+IF\s+NOT\s+EXISTS)?\s+`?([a-zA-Z0-9_]+)`?/i', $migrationContent, $matches)) { + foreach ($matches[1] as $tableName) { + if (in_array($tableName, $allTables)) { + $pluginOwnedTables[] = $tableName; + } + } + } + + // Find all referenced tables (dependencies) foreach ($allTables as $table) { - if (strpos($migrationContent, $table) !== false) { - $pluginTables[] = $table; + if (strpos($migrationContent, $table) !== false && !in_array($table, $pluginOwnedTables)) { + $pluginReferencedTables[] = $table; } } } - $pluginTables = array_unique($pluginTables); + $pluginOwnedTables = array_unique($pluginOwnedTables); + $pluginReferencedTables = array_unique($pluginReferencedTables); } } - $checkResults['tables'] = $pluginTables; + $checkResults['tables'] = [ + 'owned' => $pluginOwnedTables, + 'referenced' => $pluginReferencedTables, + ]; // Check plugin functions and integrations $bootstrapPath = $plugin['path'] . '/bootstrap.php'; @@ -773,13 +789,29 @@ endif; ?>