63 lines
5.4 KiB
Python
63 lines
5.4 KiB
Python
"""Configure the forked existing full QA on a separate vhost of the compatible Apache."""
|
|
from pathlib import Path
|
|
import json,re
|
|
ROOT=Path(__file__).resolve().parent.parent
|
|
PRIVATE=ROOT/'storage/app/private/investmoz-v2/portal-audit'
|
|
read=lambda p:json.loads(Path(p).read_text(encoding='utf-8-sig'))
|
|
plan=read(PRIVATE/'portal-stability-latest.json');source=Path(plan['source'])
|
|
link=read(PRIVATE/'portal-stability-consumers-latest.json')
|
|
actors=read(PRIVATE/'profiles-v1-actors-private.json')
|
|
env=(source/'.env').read_text(encoding='utf-8')
|
|
qa_key=re.search(r"'APP_KEY' => '([^']+)'",(ROOT/'tools/portal-qa-environment.php').read_text(encoding='utf-8')).group(1)
|
|
values={'APP_URL':'https://portal-investidor.test:18445','APP_KEY':qa_key,'DB_DATABASE':link['target']['database'],
|
|
'SESSION_COOKIE':'investmoz_stability_consumers_18445_qa',
|
|
'PORTAL_MANAGER_EMAILS':'opportunity-manager@example.invalid,geo-manager-qa@example.invalid',
|
|
'PORTAL_PROFILE_ACCESS_ENABLED':'true','PORTAL_OPPORTUNITY_DASHBOARD_ACCESS_ENABLED':'true',
|
|
'PORTAL_OPPORTUNITY_SPECIALIZED_DRAFTS_ENABLED':'true','PORTAL_OPPORTUNITY_MODULAR_PROFILES_QA_ENABLED':'true',
|
|
'PORTAL_LEGACY_CONTENT_QA_ENABLED':'true','INVESTOR_PATH_ENABLED':'true','TERRITORY_GEOMETRY_IMPORT_ENABLED':'true'}
|
|
for name,value in values.items():
|
|
line=name+'='+value
|
|
env=re.sub(r'^'+name+r'=.*$',lambda _:line,env,flags=re.M) if re.search(r'^'+name+r'=',env,re.M) else env+'\n'+line+'\n'
|
|
(source/'.env.stability-consumers').write_text(env,encoding='utf-8')
|
|
settings={'target':link['target'],'proof':link['path'],'base':'https://portal-investidor.test:18445',
|
|
'http_base':'http://portal-investidor.test:18107','QA_scope':'Consumer corrections, existing QA flags; never target activation'}
|
|
(source/'stability-consumers-qa.json').write_text(json.dumps(settings,indent=2),encoding='utf-8')
|
|
runtime=source/'tools/portal-stability-runtime.php'
|
|
text=runtime.read_text(encoding='utf-8')
|
|
text=text.replace("$settings = json_decode(file_get_contents($root.'/stability-qa.json'), true, 512, JSON_THROW_ON_ERROR);",
|
|
"""$consumerMode = ($_SERVER['HTTP_HOST'] ?? '') === 'portal-investidor.test:18445' || getenv('STABILITY_QA_MODE') === 'consumers';
|
|
$settings = json_decode(file_get_contents($root.($consumerMode?'/stability-consumers-qa.json':'/stability-qa.json')), true, 512, JSON_THROW_ON_ERROR);
|
|
$envPath = $root.($consumerMode?'/.env.stability-consumers':'/.env');""")
|
|
text=text.replace("($_SERVER['HTTP_HOST'] ?? '') !== 'portal-investidor.test:18443'",
|
|
"(!in_array($_SERVER['HTTP_HOST'] ?? '', ['portal-investidor.test:18443','portal-investidor.test:18444','portal-investidor.test:18445'],true))")
|
|
text=text.replace("file_get_contents($root.'/.env')",'file_get_contents($envPath)')
|
|
text=text.replace("preg_match('/^country_candidate_\\d{8}_\\d{6}_test$/D', $c['database'])", "preg_match('/^(?:country_candidate|stability_consumers)_\\d{8}_\\d{6}_test$/D', $c['database'])")
|
|
anchor="$app->make(Kernel::class)->bootstrap();"
|
|
text=text.replace(anchor,anchor+"\nif ($consumerMode) config(['inertia.ssr.enabled'=>false,'suitecrm.enabled'=>false,'investmoz_ai.enabled'=>false]);")
|
|
runtime.write_text(text,encoding='utf-8')
|
|
index=source/'public/index.php';text=index.read_text(encoding='utf-8')
|
|
anchor="$request = Illuminate\\Http\\Request::capture();"
|
|
health="""if (parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH) === '/_qa/runtime') {
|
|
header('Content-Type: application/json'); header('Cache-Control: no-store');
|
|
echo json_encode(['target'=>['database'=>config('database.connections.pgsql.database'),'port'=>config('database.connections.pgsql.port')],
|
|
'php'=>PHP_VERSION,'sapi'=>PHP_SAPI,'ini'=>php_ini_loaded_file(),'extensions'=>get_loaded_extensions(),
|
|
'curl'=>function_exists('curl_version')?curl_version()['version']:null,'session'=>['driver'=>config('session.driver'),'cookie'=>config('session.cookie'),'secure'=>config('session.secure')],
|
|
'cipher'=>config('app.cipher'),'country_enabled'=>config('portal.organization_country_enabled'),'active_writes'=>0],JSON_THROW_ON_ERROR);exit;
|
|
}
|
|
"""
|
|
assert anchor in text;text=text.replace(anchor,health+anchor);index.write_text(text,encoding='utf-8')
|
|
conf=Path(plan['compatible_apache_conf']);text=conf.read_text(encoding='utf-8')
|
|
vhosts=text[text.index('<VirtualHost '):]
|
|
extra=vhosts.replace(':18106',':18107').replace(':18444',':18445')
|
|
text=text.replace('Listen 127.0.0.1:18106','Listen 127.0.0.1:18106\nListen 127.0.0.1:18445\nListen 127.0.0.1:18107')+'\n'+extra
|
|
conf.write_text(text,encoding='utf-8')
|
|
# The corrected COUNTRY endpoint changes only its port and cookie; keys/data remain intact.
|
|
text=(source/'.env').read_text(encoding='utf-8').replace('portal-investidor.test:18443','portal-investidor.test:18444').replace('investmoz_stability_18443_qa','investmoz_stability_18444_qa')
|
|
(source/'.env').write_text(text,encoding='utf-8')
|
|
country=read(source/'stability-qa.json');country['base']='https://portal-investidor.test:18444';country['http_base']='http://portal-investidor.test:18106'
|
|
(source/'stability-qa.json').write_text(json.dumps(country,indent=2),encoding='utf-8')
|
|
plan.update({'qa_environment':country,'consumer_environment':settings})
|
|
(PRIVATE/'portal-stability-latest.json').write_text(json.dumps(plan,ensure_ascii=False,indent=2),encoding='utf-8')
|
|
print(json.dumps({'result':'QA_consumer_environment_prepared','origin':settings['base'],'target':settings['target'],
|
|
'country_origin':country['base'],'active_writes':0,'active_configuration_modified':False}))
|