mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-10-26 07:46:35 +01:00
Fix: Preserve new INSTALLED_APPS during upgrade by not overwriting settings.py
The issue was that restoreCriticalFiles was restoring the OLD settings.py from backup which didn't have new apps like 'aiScanner' in INSTALLED_APPS. Solution: - Modified restoreCriticalFiles to skip settings.py restoration - Keep the NEW settings.py from the fresh clone (which has aiScanner in INSTALLED_APPS) - Only update the DATABASES section with saved credentials from backup - This preserves all new app registrations while maintaining database connectivity This properly fixes the RuntimeError about aiScanner.status_models.ScanStatusUpdate not being in INSTALLED_APPS after upgrades.
This commit is contained in:
6
.idea/workspace.xml
generated
6
.idea/workspace.xml
generated
@@ -4,9 +4,7 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="5251c5c9-f2a1-41f2-bc76-10b517091df1" name="Changes" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
</list>
|
||||
<list default="true" id="5251c5c9-f2a1-41f2-bc76-10b517091df1" name="Changes" comment="" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
@@ -117,7 +115,7 @@
|
||||
<workItem from="1754429757112" duration="3503000" />
|
||||
<workItem from="1754433799097" duration="517000" />
|
||||
<workItem from="1754448353513" duration="2970000" />
|
||||
<workItem from="1754511414251" duration="24525000" />
|
||||
<workItem from="1754511414251" duration="25159000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
|
||||
@@ -2360,6 +2360,11 @@ CREATE TABLE `websiteFunctions_backupsv2` (`id` integer AUTO_INCREMENT NOT NULL
|
||||
def restoreCriticalFiles(backup_dir, backed_up_files):
|
||||
"""Restore critical configuration files after upgrade"""
|
||||
for original_path, backup_path in backed_up_files.items():
|
||||
# Skip settings.py - we'll handle it separately to preserve INSTALLED_APPS
|
||||
if 'settings.py' in original_path:
|
||||
Upgrade.stdOut(f"Skipping {original_path} - will be handled separately")
|
||||
continue
|
||||
|
||||
try:
|
||||
if os.path.isdir(backup_path):
|
||||
if os.path.exists(original_path):
|
||||
@@ -2463,23 +2468,23 @@ CREATE TABLE `websiteFunctions_backupsv2` (`id` integer AUTO_INCREMENT NOT NULL
|
||||
if not Upgrade.executioner(command, command, 1):
|
||||
Upgrade.stdOut(f"Warning: Failed to checkout branch {branch}, continuing with default branch")
|
||||
|
||||
# Restore all backed up configuration files
|
||||
# Restore all backed up configuration files (except settings.py)
|
||||
Upgrade.stdOut("Restoring configuration files...")
|
||||
Upgrade.restoreCriticalFiles(backup_dir, backed_up_files)
|
||||
|
||||
## Update settings file with database credentials while preserving other settings
|
||||
## Handle settings.py separately to preserve NEW INSTALLED_APPS while keeping old database credentials
|
||||
|
||||
# Read the current settings file (which was just restored from backup)
|
||||
# Read the NEW settings file from the fresh clone (has new INSTALLED_APPS like 'aiScanner')
|
||||
settingsData = open(settingsFile, 'r').read()
|
||||
|
||||
# Replace only the DATABASES section while keeping everything else (including INSTALLED_APPS)
|
||||
# Replace only the DATABASES section with our saved credentials
|
||||
import re
|
||||
|
||||
# More precise pattern to match the entire DATABASES dictionary including nested dictionaries
|
||||
# This pattern looks for DATABASES = { ... } including the 'default' and 'rootdb' nested dicts
|
||||
database_pattern = r'DATABASES\s*=\s*\{[^}]*\{[^}]*\}[^}]*\{[^}]*\}[^}]*\}'
|
||||
|
||||
# Replace the DATABASES section with our saved credentials
|
||||
# Replace the DATABASES section with our saved credentials from before upgrade
|
||||
settingsData = re.sub(database_pattern, completDBString.strip(), settingsData, flags=re.DOTALL)
|
||||
|
||||
# Write back the updated settings
|
||||
@@ -2487,7 +2492,7 @@ CREATE TABLE `websiteFunctions_backupsv2` (`id` integer AUTO_INCREMENT NOT NULL
|
||||
writeToFile.write(settingsData)
|
||||
writeToFile.close()
|
||||
|
||||
Upgrade.stdOut('Settings file restored with database credentials!')
|
||||
Upgrade.stdOut('Settings file updated with database credentials while preserving new INSTALLED_APPS!')
|
||||
|
||||
Upgrade.staticContent()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user