fix: cache state detection - add --allow-root fallback, capture error detail for diagnostics
parent
df460c8b96
commit
0d40aa4f4b
|
|
@ -78,14 +78,24 @@ function get_cache_state() {
|
|||
return ['enabled' => null, 'note' => 'WordPress or WP-CLI not found'];
|
||||
}
|
||||
|
||||
$result = run_command("sudo -u litespeed " . escapeshellarg($wp) . " --path=" . escapeshellarg($wp_root) . " litespeed-option get cache 2>/dev/null");
|
||||
if ($result['return_var'] !== 0 || empty($result['output'][0])) {
|
||||
return ['enabled' => null, 'note' => 'LiteSpeed Cache plugin not active or unavailable'];
|
||||
// Try as litespeed user first (same pattern as manage_litespeed.php)
|
||||
$cmd = "sudo -u litespeed " . escapeshellarg($wp) . " --path=" . escapeshellarg($wp_root) . " litespeed-option get cache 2>&1";
|
||||
$result = run_command($cmd);
|
||||
|
||||
// Fallback: run as root with --allow-root (read-only operation, safe)
|
||||
if ($result['return_var'] !== 0 || empty($result['output'])) {
|
||||
$cmd = escapeshellarg($wp) . " --path=" . escapeshellarg($wp_root) . " litespeed-option get cache --allow-root 2>&1";
|
||||
$result = run_command($cmd);
|
||||
}
|
||||
|
||||
if ($result['return_var'] !== 0 || empty($result['output'])) {
|
||||
$detail = !empty($result['output']) ? implode(' ', $result['output']) : 'no output';
|
||||
return ['enabled' => null, 'note' => 'LiteSpeed Cache plugin not active or unavailable: ' . $detail];
|
||||
}
|
||||
|
||||
$value = trim($result['output'][0]);
|
||||
return [
|
||||
'enabled' => $value === '1',
|
||||
'enabled' => ($value === '1'),
|
||||
'raw' => $value
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue