mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-14 17:26:17 +01:00
bug fix: staging site issue
This commit is contained in:
@@ -25,7 +25,7 @@ from managePHP.phpManager import PHPManager
|
|||||||
from plogical.vhostConfs import vhostConfs
|
from plogical.vhostConfs import vhostConfs
|
||||||
from ApachController.ApacheVhosts import ApacheVhost
|
from ApachController.ApacheVhosts import ApacheVhost
|
||||||
try:
|
try:
|
||||||
from websiteFunctions.models import Websites, ChildDomains, aliasDomains, DockerSites
|
from websiteFunctions.models import Websites, ChildDomains, aliasDomains, DockerSites, WPSites, WPStaging
|
||||||
from databases.models import Databases
|
from databases.models import Databases
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@@ -404,6 +404,21 @@ class vhost:
|
|||||||
|
|
||||||
if ACLManager.FindIfChild() == 0:
|
if ACLManager.FindIfChild() == 0:
|
||||||
|
|
||||||
|
### Delete WordPress Sites and Staging Sites first
|
||||||
|
try:
|
||||||
|
wpSites = WPSites.objects.filter(owner=delWebsite)
|
||||||
|
for wpSite in wpSites:
|
||||||
|
# Delete any staging sites associated with this WP site
|
||||||
|
stagingSites = WPStaging.objects.filter(wpsite=wpSite)
|
||||||
|
for staging in stagingSites:
|
||||||
|
staging.delete()
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(f"Deleted staging site record: {staging.id}")
|
||||||
|
# Delete the WP site itself
|
||||||
|
wpSite.delete()
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(f"Deleted WP site: {wpSite.id}")
|
||||||
|
except Exception as msg:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(f"Error cleaning up WP/Staging sites: {str(msg)}")
|
||||||
|
|
||||||
### Delete Docker Sites first before website deletion
|
### Delete Docker Sites first before website deletion
|
||||||
|
|
||||||
if os.path.exists('/home/docker/%s' % (virtualHostName)):
|
if os.path.exists('/home/docker/%s' % (virtualHostName)):
|
||||||
@@ -497,6 +512,21 @@ class vhost:
|
|||||||
## child check to make sure no database entires are being deleted from child server
|
## child check to make sure no database entires are being deleted from child server
|
||||||
|
|
||||||
if ACLManager.FindIfChild() == 0:
|
if ACLManager.FindIfChild() == 0:
|
||||||
|
### Delete WordPress Sites and Staging Sites first
|
||||||
|
try:
|
||||||
|
wpSites = WPSites.objects.filter(owner=delWebsite)
|
||||||
|
for wpSite in wpSites:
|
||||||
|
# Delete any staging sites associated with this WP site
|
||||||
|
stagingSites = WPStaging.objects.filter(wpsite=wpSite)
|
||||||
|
for staging in stagingSites:
|
||||||
|
staging.delete()
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(f"Deleted staging site record: {staging.id}")
|
||||||
|
# Delete the WP site itself
|
||||||
|
wpSite.delete()
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(f"Deleted WP site: {wpSite.id}")
|
||||||
|
except Exception as msg:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(f"Error cleaning up WP/Staging sites: {str(msg)}")
|
||||||
|
|
||||||
for items in databases:
|
for items in databases:
|
||||||
mysqlUtilities.deleteDatabase(items.dbName, items.dbUser)
|
mysqlUtilities.deleteDatabase(items.dbName, items.dbUser)
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ from ApachController.ApacheVhosts import ApacheVhost
|
|||||||
from managePHP.phpManager import PHPManager
|
from managePHP.phpManager import PHPManager
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from websiteFunctions.models import Websites, ChildDomains, aliasDomains
|
from websiteFunctions.models import Websites, ChildDomains, aliasDomains, WPSites, WPStaging
|
||||||
from loginSystem.models import Administrator
|
from loginSystem.models import Administrator
|
||||||
from packages.models import Package
|
from packages.models import Package
|
||||||
from CLManager.models import CLPackages
|
from CLManager.models import CLPackages
|
||||||
@@ -598,6 +598,41 @@ local_name %s {
|
|||||||
'This website already exists as child domain. [404]')
|
'This website already exists as child domain. [404]')
|
||||||
return 0, "This website already exists as child domain."
|
return 0, "This website already exists as child domain."
|
||||||
|
|
||||||
|
# Check for orphaned staging site domain conflicts
|
||||||
|
try:
|
||||||
|
# Check if there are any WP sites with FinalURL matching this domain
|
||||||
|
conflicting_wp_sites = WPSites.objects.filter(FinalURL__icontains=virtualHostName)
|
||||||
|
for wp_site in conflicting_wp_sites:
|
||||||
|
# Check if the WP site's owner website still exists
|
||||||
|
try:
|
||||||
|
owner_website = wp_site.owner
|
||||||
|
if not Websites.objects.filter(id=owner_website.id).exists():
|
||||||
|
# Orphaned WP site found, clean it up
|
||||||
|
wp_site.delete()
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(f"Cleaned up orphaned WP site: {wp_site.id} with URL: {wp_site.FinalURL}")
|
||||||
|
except:
|
||||||
|
# WP site owner is missing, delete it
|
||||||
|
wp_site.delete()
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(f"Cleaned up orphaned WP site: {wp_site.id} (missing owner)")
|
||||||
|
|
||||||
|
# Check for orphaned staging sites
|
||||||
|
orphaned_staging = WPStaging.objects.filter(wpsite__FinalURL__icontains=virtualHostName)
|
||||||
|
for staging in orphaned_staging:
|
||||||
|
try:
|
||||||
|
# Check if the staging site's wpsite still exists and has valid owner
|
||||||
|
wpsite = staging.wpsite
|
||||||
|
owner_website = wpsite.owner
|
||||||
|
if not Websites.objects.filter(id=owner_website.id).exists():
|
||||||
|
# Owner website doesn't exist, clean up staging
|
||||||
|
staging.delete()
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(f"Cleaned up orphaned staging site: {staging.id}")
|
||||||
|
except:
|
||||||
|
# Staging site has invalid references, delete it
|
||||||
|
staging.delete()
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(f"Cleaned up orphaned staging site: {staging.id} (invalid references)")
|
||||||
|
except Exception as e:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(f"Error during staging site cleanup: {str(e)}")
|
||||||
|
|
||||||
####### Limitations Check End
|
####### Limitations Check End
|
||||||
|
|
||||||
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'Creating DNS records..,10')
|
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'Creating DNS records..,10')
|
||||||
|
|||||||
@@ -216,8 +216,21 @@ class WebsiteManager:
|
|||||||
|
|
||||||
if DeleteID != None:
|
if DeleteID != None:
|
||||||
wstagingDelete = WPStaging.objects.get(pk=DeleteID, owner=WPobj)
|
wstagingDelete = WPStaging.objects.get(pk=DeleteID, owner=WPobj)
|
||||||
|
|
||||||
|
# Get the associated staging WPSites and Websites records
|
||||||
|
staging_wpsite = wstagingDelete.wpsite
|
||||||
|
staging_website = staging_wpsite.owner
|
||||||
|
|
||||||
|
# Delete the WPStaging record first
|
||||||
wstagingDelete.delete()
|
wstagingDelete.delete()
|
||||||
|
|
||||||
|
# Delete the staging WPSites record
|
||||||
|
staging_wpsite.delete()
|
||||||
|
|
||||||
|
# Delete the staging Websites record and all associated data
|
||||||
|
from plogical.vhost import vhost
|
||||||
|
vhost.deleteVirtualHostConfigurations(staging_website.domain, staging_website.adminEmail, staging_website.package.packageName)
|
||||||
|
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
da = str(msg)
|
da = str(msg)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user