forked from unimatrix/web
Add confirmed credit review links to Support tickets
This commit is contained in:
parent
3fdfc907dc
commit
d5d067370b
1 changed files with 110 additions and 23 deletions
|
|
@ -1,16 +1,45 @@
|
|||
"""Install the existing-flow loan ticket adapter from a CI-approved release."""
|
||||
"""Install bank ticket integration from a CI-approved release."""
|
||||
from pathlib import Path
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
source = Path(__file__).resolve().parents[1] / 'integrations/osticket/bank-credit-ticket.php'
|
||||
target = Path('/home/dunerealms/apps/integrations/osticket/bank-credit-ticket.php')
|
||||
subprocess.run(['php', '-l', str(source)], check=True)
|
||||
if '--apply' not in sys.argv:
|
||||
print('Plan: install one private CLI ticket adapter; no changes applied')
|
||||
sys.exit(0)
|
||||
temporary = target.with_name(target.name + '.migration-new')
|
||||
temporary.write_bytes(source.read_bytes())
|
||||
temporary.chmod(0o644)
|
||||
os.replace(temporary, target)
|
||||
print('Installed private bank-credit ticket adapter; native core unchanged')
|
||||
|
||||
|
||||
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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff