fix: defensive ServiceProvider (class_exists guards), fixed install.sh apply_patch logic

This commit is contained in:
2026-06-11 21:05:57 -05:00
parent 338dc52f76
commit d413bca7e9
3 changed files with 103 additions and 45 deletions

32
scripts/fix_asp.py Normal file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env python3
"""Fix AppServiceProvider — ensure AddonServiceProvider is registered."""
import sys
f = '/var/www/pterodactyl/app/Providers/AppServiceProvider.php'
content = open(f).read()
if 'AddonServiceProvider' in content and '$this->app->register' in content.split('AddonServiceProvider')[0].split('\n')[-2:][0]:
print('Already correctly patched')
sys.exit(0)
# Remove the broken line (the one without $this->)
lines = content.splitlines(keepends=True)
fixed = []
for line in lines:
# Replace the broken orphan line
if '->app->register(\\Pterodactyl\\Addons\\AdvancedAdmin\\AddonServiceProvider::class)' in line and not '$this' in line:
fixed.append(' $this->app->register(\\Pterodactyl\\Addons\\AdvancedAdmin\\AddonServiceProvider::class);\n')
else:
fixed.append(line)
content = ''.join(fixed)
open(f, 'w').write(content)
print('Fixed: $this-> added to AddonServiceProvider line')
# Verify
result = open(f).read()
if '$this->app->register(\\Pterodactyl\\Addons\\AdvancedAdmin\\AddonServiceProvider::class)' in result:
print('Verification OK')
else:
print('ERROR: Verification failed')
sys.exit(1)