56 lines
2.3 KiB
Python
56 lines
2.3 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');"
|
|
source = source.replace(hook + '\n', '')
|
|
anchor = "require_once(STAFFINC_DIR.$inc);"
|
|
if source.count(anchor) != 1:
|
|
raise RuntimeError('Native staff ticket view changed; no files installed')
|
|
return source
|
|
|
|
|
|
def reply_review_hook(source):
|
|
hook = "<?php require(dirname(__DIR__, 2).'/bank-credit-review.php'); ?>"
|
|
if hook in source:
|
|
return source
|
|
anchor = " <input class=\"save pending\" type=\"submit\" value=\"<?php echo __('Post Reply');?>\">"
|
|
if source.count(anchor) != 1:
|
|
raise RuntimeError('Native reply controls 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()
|
|
reply_view = target / 'include/staff/ticket-view.inc.php'
|
|
files[reply_view] = reply_review_hook(reply_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)
|

Staff