Debugs admin/plugins. Makes it use App API

main
Yasen Pramatarov 2026-01-19 12:08:17 +02:00
parent ddd8fdac3a
commit 0b3ff9e40b
2 changed files with 63 additions and 25 deletions

View File

@ -169,19 +169,22 @@ foreach ($pluginCatalog as $slug => $info) {
$hasMigration = !empty($migrationFiles); $hasMigration = !empty($migrationFiles);
$existingTables = []; $existingTables = [];
if ($hasMigration && isset($db) && $db instanceof PDO) { if ($hasMigration) {
$stmt = $db->query("SHOW TABLES"); $db = \App\App::db();
$allTables = $stmt->fetchAll(PDO::FETCH_COLUMN, 0); if ($db instanceof PDO) {
$stmt = $db->query("SHOW TABLES");
$allTables = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
foreach ($migrationFiles as $migrationFile) { foreach ($migrationFiles as $migrationFile) {
$migrationContent = file_get_contents($migrationFile); $migrationContent = file_get_contents($migrationFile);
foreach ($allTables as $table) { foreach ($allTables as $table) {
if (strpos($migrationContent, $table) !== false) { if (strpos($migrationContent, $table) !== false) {
$existingTables[] = $table; $existingTables[] = $table;
}
} }
} }
$existingTables = array_unique($existingTables);
} }
$existingTables = array_unique($existingTables);
} }
$pluginAdminMap[$slug] = [ $pluginAdminMap[$slug] = [
@ -599,7 +602,7 @@ if ($queryAction === 'plugin_check_page' && isset($_GET['plugin'])) {
]; ];
// Check database tables // Check database tables
global $db; $db = \App\App::db();
$pluginTables = []; $pluginTables = [];
if ($db instanceof PDO) { if ($db instanceof PDO) {
$stmt = $db->query("SHOW TABLES"); $stmt = $db->query("SHOW TABLES");

View File

@ -664,7 +664,7 @@ endif; ?>
]; ];
// Check database tables // Check database tables
global $db; $db = \App\App::db();
$pluginTables = []; $pluginTables = [];
if ($db instanceof PDO) { if ($db instanceof PDO) {
$stmt = $db->query("SHOW TABLES"); $stmt = $db->query("SHOW TABLES");
@ -690,8 +690,30 @@ endif; ?>
if (file_exists($bootstrapPath)) { if (file_exists($bootstrapPath)) {
include_once $bootstrapPath; include_once $bootstrapPath;
$migrationFunction = str_replace('-', '_', $plugin['slug']) . '_ensure_tables'; $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'] = [ $checkResults['functions'] = [
'migration' => function_exists($migrationFunction), 'migration' => function_exists($migrationFunction),
'migration_test' => $migrationTestResult ?: 'not applicable',
]; ];
} }
@ -752,13 +774,33 @@ endif; ?>
<h6 class="card-title mb-0">Functions Check</h6> <h6 class="card-title mb-0">Functions Check</h6>
</div> </div>
<div class="card-body"> <div class="card-body">
<?php foreach ($checkResults['functions'] ?? [] as $func => $exists): ?> <?php foreach ($checkResults['functions'] ?? [] as $func => $value): ?>
<div class="d-flex justify-content-between align-items-center mb-2"> <?php if ($func === 'migration_test'): ?>
<span><?= htmlspecialchars($func) ?>()</span> <div class="d-flex justify-content-between align-items-center mb-2">
<span class="badge bg-<?= $exists ? 'success' : 'danger' ?>"> <span>Migration Test</span>
<?= $exists ? 'Available' : 'Missing' ?> <?php if ($value === 'not applicable'): ?>
</span> <span class="badge bg-secondary">Not Applicable</span>
</div> <?php elseif ($value === 'already installed'): ?>
<span class="badge bg-info">Already Installed</span>
<?php elseif (strpos($value, 'error') === false): ?>
<span class="badge bg-success">Passed</span>
<?php else: ?>
<span class="badge bg-danger">Failed</span>
<?php endif; ?>
</div>
<?php if ($value === 'already installed'): ?>
<div class="text-muted small mb-2">Plugin tables already exist - migration not needed</div>
<?php elseif (strpos($value, 'error') !== false): ?>
<div class="text-muted small mb-2"><?= htmlspecialchars($value) ?></div>
<?php endif; ?>
<?php elseif ($func === 'migration'): ?>
<div class="d-flex justify-content-between align-items-center mb-2">
<span><?= htmlspecialchars($func) ?>()</span>
<span class="badge bg-<?= $value ? 'success' : 'danger' ?>">
<?= $value ? 'Available' : 'Missing' ?>
</span>
</div>
<?php endif; ?>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
</div> </div>
@ -793,13 +835,6 @@ endif; ?>
<input type="hidden" name="action" value="plugin_install"> <input type="hidden" name="action" value="plugin_install">
<button type="submit" class="btn btn-primary">Install Tables</button> <button type="submit" class="btn btn-primary">Install Tables</button>
</form> </form>
<form method="post" class="d-inline">
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrf_token) ?>">
<input type="hidden" name="section" value="plugins">
<input type="hidden" name="plugin" value="<?= htmlspecialchars($plugin['slug']) ?>">
<input type="hidden" name="action" value="test_plugin_migrations">
<button type="submit" class="btn btn-info">Test Migrations</button>
</form>
<form method="post" class="d-inline"> <form method="post" class="d-inline">
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrf_token) ?>"> <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrf_token) ?>">
<input type="hidden" name="section" value="plugins"> <input type="hidden" name="section" value="plugins">