51 lines
2.4 KiB
Python
51 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
# V91: Fix enterprise-model.html TDZ (Temporal Dead Zone) bug
|
|
# Line 90 uses AG before let AG=[] on line 237
|
|
# Fix: move line 90 DP filter to AFTER AG declaration (right after the big AG=[] line)
|
|
|
|
path = "/var/www/html/enterprise-model.html"
|
|
with open(path, "rb") as f:
|
|
raw = f.read()
|
|
|
|
if b"V91 TDZ fix" in raw:
|
|
print("ALREADY")
|
|
exit(0)
|
|
|
|
# The problematic line to MOVE (line 90):
|
|
# DP=DP.filter(function(d){var c=AG.filter(function(a){return a.rm===d.id;}).length;return c>0||["meet","lean"].indexOf(d.id)>=0;});
|
|
bad_line = b'// V17: hide empty departments (wire/intg/dorm/meet/lean kept for pipelines but filter agents)\nDP=DP.filter(function(d){var c=AG.filter(function(a){return a.rm===d.id;}).length;return c>0||["meet","lean"].indexOf(d.id)>=0;});'
|
|
|
|
if bad_line not in raw:
|
|
print("MARKER_NOT_FOUND - checking shorter marker")
|
|
# Try just the DP filter line
|
|
marker2 = b'DP=DP.filter(function(d){var c=AG.filter(function(a){return a.rm===d.id;}).length;return c>0||["meet","lean"].indexOf(d.id)>=0;});'
|
|
if marker2 not in raw:
|
|
print("SHORT MARKER NOT FOUND EITHER")
|
|
exit(1)
|
|
# Replace with comment placeholder - NOOP here
|
|
old_at_line90 = b'// V17: hide empty departments (wire/intg/dorm/meet/lean kept for pipelines but filter agents)\n' + marker2
|
|
new_at_line90 = b'// V91 TDZ fix: moved DP.filter after AG declaration (was line 90, now runs after AG=[])'
|
|
if old_at_line90 in raw:
|
|
# Find and remove
|
|
raw = raw.replace(old_at_line90, new_at_line90, 1)
|
|
else:
|
|
# Just replace the bare marker
|
|
raw = raw.replace(marker2, b'// V91 TDZ fix: moved below', 1)
|
|
else:
|
|
# Remove the problematic line
|
|
raw = raw.replace(bad_line, b"// V91 TDZ fix: moved DP.filter after AG declaration", 1)
|
|
|
|
# Now add the filter AFTER the AG.filter(function(a){return a&&a.n;}); at line 402
|
|
# Find marker ligne 402
|
|
marker402 = b'AG=AG.filter(function(a){return a&&a.n;});'
|
|
if marker402 not in raw:
|
|
print("AG CLEAN MARKER NOT FOUND")
|
|
exit(1)
|
|
|
|
addon = b'\nAG=AG.filter(function(a){return a&&a.n;});\n// V91 TDZ fix: DP filter moved here (after AG declaration) - was at line 90\nDP=DP.filter(function(d){var c=AG.filter(function(a){return a.rm===d.id;}).length;return c>0||["meet","lean"].indexOf(d.id)>=0;});'
|
|
raw = raw.replace(b'\n' + marker402, addon, 1)
|
|
|
|
with open(path, "wb") as f:
|
|
f.write(raw)
|
|
print(f"Fixed! size: {len(raw)}")
|