Add database cleanup feature to empty all sensor tables
Added a "Danger Zone" section on the database page that allows users to empty all sensor data tables while preserving configuration and timestamp tables. The feature includes: - New Python script (sqlite/empty_sensor_tables.py) to safely empty sensor tables - Backend endpoint in launcher.php (empty_sensor_tables) - Frontend UI with red warning card and confirmation dialog - Detailed feedback showing deleted record counts per table - i18n support for French and English Tables emptied: data_NPM, data_NPM_5channels, data_BME280, data_envea, data_WIND, data_MPPT, data_NOISE, modem_status Tables preserved: timestamp_table, config_table, envea_sondes_table, config_scripts_table 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1270,13 +1270,68 @@ if ($type == "toggle_systemd_service") {
|
||||
}
|
||||
}
|
||||
|
||||
// Empty all sensor tables (preserve config and timestamp tables)
|
||||
if ($type == "empty_sensor_tables") {
|
||||
try {
|
||||
// Execute the empty sensor tables script
|
||||
$command = 'sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/sqlite/empty_sensor_tables.py 2>&1';
|
||||
$output = shell_exec($command);
|
||||
|
||||
// Try to extract JSON result from output
|
||||
$json_start = strpos($output, '[JSON_RESULT]');
|
||||
if ($json_start !== false) {
|
||||
$json_data = substr($output, $json_start + strlen('[JSON_RESULT]'));
|
||||
$json_data = trim($json_data);
|
||||
|
||||
// Find the first { and last }
|
||||
$first_brace = strpos($json_data, '{');
|
||||
$last_brace = strrpos($json_data, '}');
|
||||
|
||||
if ($first_brace !== false && $last_brace !== false) {
|
||||
$json_data = substr($json_data, $first_brace, $last_brace - $first_brace + 1);
|
||||
$result = json_decode($json_data, true);
|
||||
|
||||
if ($result !== null) {
|
||||
echo json_encode($result);
|
||||
} else {
|
||||
// JSON decode failed, return raw output
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Tables emptied',
|
||||
'output' => $output
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Tables emptied',
|
||||
'output' => $output
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
// No JSON marker found, return raw output
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Tables emptied',
|
||||
'output' => $output
|
||||
]);
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => 'Script execution failed: ' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
_____ ____ _ _ _
|
||||
| ____|_ ____ _____ __ _ | _ \ ___| |_ ___ ___| |_(_) ___ _ __
|
||||
| _| | '_ \ \ / / _ \/ _` | | | | |/ _ \ __/ _ \/ __| __| |/ _ \| '_ \
|
||||
_____ ____ _ _ _
|
||||
| ____|_ ____ _____ __ _ | _ \ ___| |_ ___ ___| |_(_) ___ _ __
|
||||
| _| | '_ \ \ / / _ \/ _` | | | | |/ _ \ __/ _ \/ __| __| |/ _ \| '_ \
|
||||
| |___| | | \ V / __/ (_| | | |_| | __/ || __/ (__| |_| | (_) | | | |
|
||||
|_____|_| |_|\_/ \___|\__,_| |____/ \___|\__\___|\___|\__|_|\___/|_| |_|
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// Detect Envea devices on specified port
|
||||
|
||||
Reference in New Issue
Block a user