> /var/log/happybums_cleanup.log 2>&1
//
// SECURITY NOTES
// --------------
// Web access is intentionally low-risk: the worst outcome is that
// stale data is removed slightly ahead of schedule. No active wearer
// data can be lost as the 365-day threshold far exceeds any normal
// period of inactivity. Consider restricting web access via .htaccess
// if you prefer CLI-only operation.
//
// ============================================================
// Configuration
// ============================================================
// Path to the SQLite database file.
// __DIR__ means "same directory as this script", matching HappyBums.php behaviour.
// Change this if you place the script elsewhere.
$dbFile = __DIR__ . '/happybums.db';
// Wearers not seen within this many days will be removed.
$daysThreshold = 365;
// ============================================================
// Detect run context and dry-run flag
// ============================================================
$isCLI = (php_sapi_name() === 'cli');
$dryRun = false;
if ($isCLI) {
$dryRun = in_array('--dry-run', $argv ?? []);
} else {
$dryRun = isset($_GET['dry_run']) && $_GET['dry_run'] === '1';
}
// ============================================================
// Output helpers
// ============================================================
function out($line) {
global $isCLI;
if ($isCLI) {
echo $line . PHP_EOL;
} else {
echo htmlspecialchars($line) . "
\n";
}
}
function outSection($title) {
global $isCLI;
$bar = str_repeat('-', 60);
if ($isCLI) {
echo PHP_EOL . $bar . PHP_EOL . $title . PHP_EOL . $bar . PHP_EOL;
} else {
echo "