MC/website/scripts/install-bank-credit-support.py
2026-11-16 01:42:50 +01:00

45 lines
1.7 KiB
Python

"""Install bank ticket integration from a CI-approved release."""
from pathlib import Path
import os
import subprocess
import sys
def ticket_review_hook(source):
hook = "require_once(dirname(__DIR__).'/bank-credit-review.php');"
if hook in source:
return source
anchor = "require_once(STAFFINC_DIR.$inc);"
if source.count(anchor) != 1:
raise RuntimeError('Native staff ticket view changed; no files installed')
return source.replace(anchor, hook + '\n' + anchor)
def install(apply=False):
source = Path(__file__).resolve().parents[1] / 'integrations/osticket'
target = Path('/home/dunerealms/apps/integrations/osticket')
files = {target / name: (source / name).read_bytes()
for name in ['bank-credit-ticket.php', 'bank-credit-review.php']}
ticket_view = target / 'scp/tickets.php'
files[ticket_view] = ticket_review_hook(ticket_view.read_text()).encode()
for name in ['bank-credit-ticket.php', 'bank-credit-review.php']:
subprocess.run(['php', '-l', str(source / name)], check=True)
if not apply:
print('Plan: install bank ticket adapter and staff decision links; no changes applied')
return
for path, content in files.items():
if path.exists() and path.read_bytes() == content:
continue
temporary = path.with_name(path.name + '.migration-new')
temporary.write_bytes(content)
temporary.chmod(0o644)
try:
subprocess.run(['php', '-l', str(temporary)], check=True)
os.replace(temporary, path)
finally:
temporary.unlink(missing_ok=True)
print('Installed bank ticket adapter and staff decision links')
if __name__ == '__main__':
install('--apply' in sys.argv)