#!/bin/bash
# Rimuove log di debug agent da modmaker_14_Operatori_u.php
# Esecuzione: sudo bash strip-modmaker-debug-instrumentation.sh

set -euo pipefail
[[ "${EUID:-0}" -ne 0 ]] && { echo "Esegui: sudo bash $0" >&2; exit 1; }

TARGET="/var/www/html/vte23083_2711/storage/custom_modules/modmaker_14_Operatori_u.php"

python3 <<'PY'
import re
from pathlib import Path

path = Path("/var/www/html/vte23083_2711/storage/custom_modules/modmaker_14_Operatori_u.php")
text = path.read_text()
pattern = r"\n\t\t// #region agent log\n\t\tfile_put_contents\('/var/www/html/\.cursor/debug-f568f6\.log'.*?\n\t\t// #endregion"
text2, n = re.subn(pattern, "", text, flags=re.DOTALL)
if n == 0:
	print("[OK] Nessuna strumentazione da rimuovere in modmaker_14_Operatori_u.php")
else:
	path.write_text(text2)
	print(f"[OK] Rimosse {n} blocchi di debug da modmaker_14_Operatori_u.php")
PY

chown www-data:www-data "$TARGET"
rm -f /var/www/html/.cursor/debug-f568f6.log
echo "[OK] Pulizia completata."
