Debugs admin/plugins feature
parent
064614f73f
commit
aff2ec4003
|
|
@ -168,11 +168,11 @@ foreach ($pluginCatalog as $slug => $info) {
|
||||||
$migrationFiles = glob($info['path'] . '/migrations/*.sql');
|
$migrationFiles = glob($info['path'] . '/migrations/*.sql');
|
||||||
$hasMigration = !empty($migrationFiles);
|
$hasMigration = !empty($migrationFiles);
|
||||||
$existingTables = [];
|
$existingTables = [];
|
||||||
|
|
||||||
if ($hasMigration && isset($db) && $db instanceof PDO) {
|
if ($hasMigration && isset($db) && $db instanceof PDO) {
|
||||||
$stmt = $db->query("SHOW TABLES");
|
$stmt = $db->query("SHOW TABLES");
|
||||||
$allTables = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
|
$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) {
|
||||||
|
|
@ -404,19 +404,19 @@ if ($postAction !== '' && $postAction !== 'read_migration') {
|
||||||
try {
|
try {
|
||||||
$pluginPath = $pluginAdminMap[$slug]['path'];
|
$pluginPath = $pluginAdminMap[$slug]['path'];
|
||||||
$bootstrapPath = $pluginPath . '/bootstrap.php';
|
$bootstrapPath = $pluginPath . '/bootstrap.php';
|
||||||
|
|
||||||
if (!file_exists($bootstrapPath)) {
|
if (!file_exists($bootstrapPath)) {
|
||||||
Feedback::flash('ERROR', 'DEFAULT', 'Plugin has no bootstrap file.', false);
|
Feedback::flash('ERROR', 'DEFAULT', 'Plugin has no bootstrap file.', false);
|
||||||
} else {
|
} else {
|
||||||
// Load plugin bootstrap in isolation to test migrations
|
// Load plugin bootstrap in isolation to test migrations
|
||||||
$migrationFunctions = [];
|
$migrationFunctions = [];
|
||||||
$bootstrapContent = file_get_contents($bootstrapPath);
|
$bootstrapContent = file_get_contents($bootstrapPath);
|
||||||
|
|
||||||
// Check for migration functions
|
// Check for migration functions
|
||||||
if (strpos($bootstrapContent, '_ensure_tables') !== false) {
|
if (strpos($bootstrapContent, '_ensure_tables') !== false) {
|
||||||
// Temporarily include bootstrap to test migrations
|
// Temporarily include bootstrap to test migrations
|
||||||
include_once $bootstrapPath;
|
include_once $bootstrapPath;
|
||||||
|
|
||||||
$migrationFunctionName = str_replace('-', '_', $slug) . '_ensure_tables';
|
$migrationFunctionName = str_replace('-', '_', $slug) . '_ensure_tables';
|
||||||
if (function_exists($migrationFunctionName)) {
|
if (function_exists($migrationFunctionName)) {
|
||||||
$migrationFunctionName();
|
$migrationFunctionName();
|
||||||
|
|
@ -544,7 +544,7 @@ if ($queryAction === 'plugin_check_page' && isset($_GET['plugin'])) {
|
||||||
echo json_encode(['test' => 'working', 'timestamp' => time()]);
|
echo json_encode(['test' => 'working', 'timestamp' => time()]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug: Log request details
|
// Debug: Log request details
|
||||||
error_log('Plugin check request: ' . print_r([
|
error_log('Plugin check request: ' . print_r([
|
||||||
'action' => $queryAction,
|
'action' => $queryAction,
|
||||||
|
|
@ -554,23 +554,23 @@ if ($queryAction === 'plugin_check_page' && isset($_GET['plugin'])) {
|
||||||
'content_type' => $_SERVER['CONTENT_TYPE'] ?? 'not set',
|
'content_type' => $_SERVER['CONTENT_TYPE'] ?? 'not set',
|
||||||
'request_method' => $_SERVER['REQUEST_METHOD'] ?? 'not set'
|
'request_method' => $_SERVER['REQUEST_METHOD'] ?? 'not set'
|
||||||
], true));
|
], true));
|
||||||
|
|
||||||
// Start output buffering to catch any unwanted output
|
// Start output buffering to catch any unwanted output
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
// Disable error display for JSON responses
|
// Disable error display for JSON responses
|
||||||
$originalErrorReporting = error_reporting();
|
$originalErrorReporting = error_reporting();
|
||||||
$originalDisplayErrors = ini_get('display_errors');
|
$originalDisplayErrors = ini_get('display_errors');
|
||||||
|
|
||||||
$isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
|
$isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
|
||||||
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') ||
|
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') ||
|
||||||
isset($_GET['ajax']);
|
isset($_GET['ajax']);
|
||||||
|
|
||||||
if ($isAjax) {
|
if ($isAjax) {
|
||||||
error_reporting(0);
|
error_reporting(0);
|
||||||
ini_set('display_errors', 0);
|
ini_set('display_errors', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$pluginSlug = strtolower(trim($_GET['plugin']));
|
$pluginSlug = strtolower(trim($_GET['plugin']));
|
||||||
if (!isset($pluginAdminMap[$pluginSlug])) {
|
if (!isset($pluginAdminMap[$pluginSlug])) {
|
||||||
if ($isAjax) {
|
if ($isAjax) {
|
||||||
|
|
@ -583,28 +583,28 @@ if ($queryAction === 'plugin_check_page' && isset($_GET['plugin'])) {
|
||||||
header('Location: ' . $app_root . '?page=admin§ion=plugins');
|
header('Location: ' . $app_root . '?page=admin§ion=plugins');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pluginInfo = $pluginAdminMap[$pluginSlug];
|
$pluginInfo = $pluginAdminMap[$pluginSlug];
|
||||||
$checkResults = [];
|
$checkResults = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Check plugin files exist
|
// Check plugin files exist
|
||||||
$migrationFiles = glob($pluginInfo['path'] . '/migrations/*.sql');
|
$migrationFiles = glob($pluginInfo['path'] . '/migrations/*.sql');
|
||||||
$hasMigration = !empty($migrationFiles);
|
$hasMigration = !empty($migrationFiles);
|
||||||
|
|
||||||
$checkResults['files'] = [
|
$checkResults['files'] = [
|
||||||
'manifest' => file_exists($pluginInfo['path'] . '/plugin.json'),
|
'manifest' => file_exists($pluginInfo['path'] . '/plugin.json'),
|
||||||
'bootstrap' => file_exists($pluginInfo['path'] . '/bootstrap.php'),
|
'bootstrap' => file_exists($pluginInfo['path'] . '/bootstrap.php'),
|
||||||
'migration' => $hasMigration,
|
'migration' => $hasMigration,
|
||||||
];
|
];
|
||||||
|
|
||||||
// Check database tables
|
// Check database tables
|
||||||
global $db;
|
global $db;
|
||||||
$pluginTables = [];
|
$pluginTables = [];
|
||||||
if ($db instanceof PDO) {
|
if ($db instanceof PDO) {
|
||||||
$stmt = $db->query("SHOW TABLES");
|
$stmt = $db->query("SHOW TABLES");
|
||||||
$allTables = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
|
$allTables = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||||
|
|
||||||
if ($hasMigration) {
|
if ($hasMigration) {
|
||||||
// Check each migration file for table references
|
// Check each migration file for table references
|
||||||
foreach ($migrationFiles as $migrationFile) {
|
foreach ($migrationFiles as $migrationFile) {
|
||||||
|
|
@ -619,7 +619,7 @@ if ($queryAction === 'plugin_check_page' && isset($_GET['plugin'])) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$checkResults['tables'] = $pluginTables;
|
$checkResults['tables'] = $pluginTables;
|
||||||
|
|
||||||
// Check plugin functions
|
// Check plugin functions
|
||||||
$bootstrapPath = $pluginInfo['path'] . '/bootstrap.php';
|
$bootstrapPath = $pluginInfo['path'] . '/bootstrap.php';
|
||||||
if (file_exists($bootstrapPath)) {
|
if (file_exists($bootstrapPath)) {
|
||||||
|
|
@ -629,21 +629,21 @@ if ($queryAction === 'plugin_check_page' && isset($_GET['plugin'])) {
|
||||||
'migration' => function_exists($migrationFunction),
|
'migration' => function_exists($migrationFunction),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
$checkResults['error'] = $e->getMessage();
|
$checkResults['error'] = $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle AJAX request
|
// Handle AJAX request
|
||||||
if ($isAjax) {
|
if ($isAjax) {
|
||||||
// Restore error reporting
|
// Restore error reporting
|
||||||
error_reporting($originalErrorReporting);
|
error_reporting($originalErrorReporting);
|
||||||
ini_set('display_errors', $originalDisplayErrors);
|
ini_set('display_errors', $originalDisplayErrors);
|
||||||
|
|
||||||
ob_end_clean(); // Clear and end output buffer
|
ob_end_clean(); // Clear and end output buffer
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
header('Cache-Control: no-cache, must-revalidate');
|
header('Cache-Control: no-cache, must-revalidate');
|
||||||
|
|
||||||
$jsonData = json_encode([
|
$jsonData = json_encode([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'pluginInfo' => $pluginInfo,
|
'pluginInfo' => $pluginInfo,
|
||||||
|
|
@ -651,16 +651,16 @@ if ($queryAction === 'plugin_check_page' && isset($_GET['plugin'])) {
|
||||||
'csrf_token' => $csrf_token,
|
'csrf_token' => $csrf_token,
|
||||||
'app_root' => $app_root
|
'app_root' => $app_root
|
||||||
]);
|
]);
|
||||||
|
|
||||||
error_log('JSON response: ' . $jsonData);
|
error_log('JSON response: ' . $jsonData);
|
||||||
echo $jsonData;
|
echo $jsonData;
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore error reporting for non-AJAX requests
|
// Restore error reporting for non-AJAX requests
|
||||||
error_reporting($originalErrorReporting);
|
error_reporting($originalErrorReporting);
|
||||||
ini_set('display_errors', $originalDisplayErrors);
|
ini_set('display_errors', $originalDisplayErrors);
|
||||||
|
|
||||||
// Include check page template for non-AJAX requests
|
// Include check page template for non-AJAX requests
|
||||||
include '../app/templates/admin_plugin_check.php';
|
include '../app/templates/admin_plugin_check.php';
|
||||||
exit;
|
exit;
|
||||||
|
|
|
||||||
|
|
@ -654,30 +654,36 @@ endif; ?>
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Check plugin files exist
|
// Check plugin files exist
|
||||||
|
$migrationFiles = glob($plugin['path'] . '/migrations/*.sql');
|
||||||
|
$hasMigration = !empty($migrationFiles);
|
||||||
|
|
||||||
$checkResults['files'] = [
|
$checkResults['files'] = [
|
||||||
'manifest' => file_exists($plugin['path'] . '/plugin.json'),
|
'manifest' => file_exists($plugin['path'] . '/plugin.json'),
|
||||||
'bootstrap' => file_exists($plugin['path'] . '/bootstrap.php'),
|
'bootstrap' => file_exists($plugin['path'] . '/bootstrap.php'),
|
||||||
'migration' => file_exists($plugin['path'] . '/migrations/create_' . $plugin['slug'] . '_tables.sql'),
|
'migration' => $hasMigration,
|
||||||
];
|
];
|
||||||
|
|
||||||
// Check database tables
|
// Check database tables
|
||||||
global $db;
|
global $db;
|
||||||
|
$pluginTables = [];
|
||||||
if ($db instanceof PDO) {
|
if ($db instanceof PDO) {
|
||||||
$stmt = $db->query("SHOW TABLES LIKE 'user_pro_%'");
|
$stmt = $db->query("SHOW TABLES");
|
||||||
$allTables = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
|
$allTables = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||||
|
|
||||||
$migrationFile = $plugin['path'] . '/migrations/create_' . $plugin['slug'] . '_tables.sql';
|
if ($hasMigration) {
|
||||||
if (file_exists($migrationFile)) {
|
// Check each migration file for table references
|
||||||
$migrationContent = file_get_contents($migrationFile);
|
foreach ($migrationFiles as $migrationFile) {
|
||||||
$pluginTables = [];
|
$migrationContent = file_get_contents($migrationFile);
|
||||||
foreach ($allTables as $table) {
|
foreach ($allTables as $table) {
|
||||||
if (strpos($migrationContent, $table) !== false) {
|
if (strpos($migrationContent, $table) !== false) {
|
||||||
$pluginTables[] = $table;
|
$pluginTables[] = $table;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$checkResults['tables'] = $pluginTables;
|
$pluginTables = array_unique($pluginTables);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$checkResults['tables'] = $pluginTables;
|
||||||
|
|
||||||
// Check plugin functions
|
// Check plugin functions
|
||||||
$bootstrapPath = $plugin['path'] . '/bootstrap.php';
|
$bootstrapPath = $plugin['path'] . '/bootstrap.php';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue