mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-06 21:35:55 +01:00
improve wp staging
This commit is contained in:
@@ -37,16 +37,28 @@ class StagingSetup(multi.Thread):
|
|||||||
website = Websites.objects.get(domain=masterDomain)
|
website = Websites.objects.get(domain=masterDomain)
|
||||||
|
|
||||||
masterPath = '/home/%s/public_html' % (masterDomain)
|
masterPath = '/home/%s/public_html' % (masterDomain)
|
||||||
|
configPath = '%s/wp-config.php' % (masterPath)
|
||||||
|
|
||||||
|
## Check if WP Detected on Main Site
|
||||||
|
|
||||||
|
command = 'ls -la %s' % (configPath)
|
||||||
|
output = ProcessUtilities.outputExecutioner(command)
|
||||||
|
|
||||||
|
if output.find('No such file or') > -1:
|
||||||
|
logging.statusWriter(tempStatusPath, 'WordPress is not detected. [404]')
|
||||||
|
return 0
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
command = 'chmod 755 %s' % (masterPath)
|
command = 'chmod 755 %s' % (masterPath)
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
## Creating Child Domain
|
## Creating Child Domain
|
||||||
|
|
||||||
path = "/home/" + masterDomain + "/public_html/" + domain
|
path = "/home/" + masterDomain + "/" + domain
|
||||||
|
|
||||||
logging.statusWriter(tempStatusPath, 'Creating domain for staging environment..,5')
|
logging.statusWriter(tempStatusPath, 'Creating domain for staging environment..,5')
|
||||||
phpSelection = 'PHP 7.2'
|
phpSelection = website.phpSelection
|
||||||
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
|
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
|
||||||
|
|
||||||
execPath = execPath + " createDomain --masterDomain " + masterDomain + " --virtualHostName " + domain + \
|
execPath = execPath + " createDomain --masterDomain " + masterDomain + " --virtualHostName " + domain + \
|
||||||
@@ -67,128 +79,49 @@ class StagingSetup(multi.Thread):
|
|||||||
|
|
||||||
logging.statusWriter(tempStatusPath, 'Domain successfully created..,15')
|
logging.statusWriter(tempStatusPath, 'Domain successfully created..,15')
|
||||||
|
|
||||||
## Copying Data
|
## Creating WP Site and setting Database
|
||||||
|
|
||||||
## Fetch child domain path
|
command = 'wp core download --path=%s' % (path)
|
||||||
|
|
||||||
childDomainPaths = []
|
|
||||||
|
|
||||||
for childs in website.childdomains_set.all():
|
|
||||||
childDomainPaths.append(childs.path)
|
|
||||||
|
|
||||||
filesAndFolder = os.listdir(masterPath)
|
|
||||||
|
|
||||||
for items in filesAndFolder:
|
|
||||||
completePath = '%s/%s' % (masterPath, items)
|
|
||||||
|
|
||||||
if completePath in childDomainPaths:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
command = 'cp -r %s %s/' % (completePath, path)
|
|
||||||
ProcessUtilities.executioner(command, website.externalApp)
|
ProcessUtilities.executioner(command, website.externalApp)
|
||||||
|
|
||||||
foldersToBeRemoved = ['%s/.git' % (path), '%s/wp-content/backups' % (path), '%s/wp-content/updraft' % (path), '%s/wp-content/cache' % (path), '%s/wp-content/plugins/litespeed-cache' % (path)]
|
|
||||||
|
|
||||||
for rmv in foldersToBeRemoved:
|
|
||||||
command = 'rm -rf %s' % (rmv)
|
|
||||||
ProcessUtilities.executioner(command, website.externalApp)
|
|
||||||
|
|
||||||
|
|
||||||
logging.statusWriter(tempStatusPath, 'Data copied..,50')
|
|
||||||
|
|
||||||
## Creating Database
|
|
||||||
|
|
||||||
logging.statusWriter(tempStatusPath, 'Creating and copying database..,50')
|
logging.statusWriter(tempStatusPath, 'Creating and copying database..,50')
|
||||||
|
|
||||||
dbNameRestore, dbUser, dbPassword = ApplicationInstaller(None, None).dbCreation(tempStatusPath, website)
|
dbNameRestore, dbUser, dbPassword = ApplicationInstaller(None, None).dbCreation(tempStatusPath, website)
|
||||||
|
|
||||||
# Create dump of existing database
|
command = 'wp core config --dbname=%s --dbuser=%s --dbpass=%s --path=%s' % (dbNameRestore, dbUser, dbPassword, path)
|
||||||
|
ProcessUtilities.executioner(command, website.externalApp)
|
||||||
|
|
||||||
configPath = '%s/wp-config.php' % (masterPath)
|
## Exporting and importing database
|
||||||
|
|
||||||
command = 'ls -la %s' % (configPath)
|
command = 'wp --allow-root --path=%s db export %s/dbexport-stage.sql' % (masterPath, path)
|
||||||
output = ProcessUtilities.outputExecutioner(command)
|
|
||||||
|
|
||||||
if output.find('No such file or') > -1:
|
|
||||||
logging.statusWriter(tempStatusPath, 'WordPress is not detected. [404]')
|
|
||||||
return 0
|
|
||||||
|
|
||||||
command = 'cat %s' % (configPath)
|
|
||||||
data = ProcessUtilities.outputExecutioner(command).split('\n')
|
|
||||||
|
|
||||||
for items in data:
|
|
||||||
if items.find('DB_NAME') > -1 and items[0] != '/':
|
|
||||||
try:
|
|
||||||
dbName = items.split("'")[3]
|
|
||||||
if mysqlUtilities.createDatabaseBackup(dbName, '/home/cyberpanel'):
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise BaseException('Failed to create database backup.')
|
|
||||||
except:
|
|
||||||
dbName = items.split('"')[1]
|
|
||||||
if mysqlUtilities.createDatabaseBackup(dbName, '/home/cyberpanel'):
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise BaseException('Failed to create database backup.')
|
|
||||||
|
|
||||||
databasePath = '%s/%s.sql' % ('/home/cyberpanel', dbName)
|
|
||||||
|
|
||||||
if not mysqlUtilities.restoreDatabaseBackup(dbNameRestore, '/home/cyberpanel', None, 1, dbName):
|
|
||||||
try:
|
|
||||||
os.remove(databasePath)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
raise BaseException('Failed to restore database backup.')
|
|
||||||
|
|
||||||
try:
|
|
||||||
os.remove(databasePath)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
## Update final config file
|
|
||||||
|
|
||||||
pathFinalConfig = '%s/wp-config.php' % (path)
|
|
||||||
|
|
||||||
command = 'cat %s' % (configPath)
|
|
||||||
data = ProcessUtilities.outputExecutioner(command).split('\n')
|
|
||||||
|
|
||||||
tmp = "/tmp/" + str(randint(1000, 9999))
|
|
||||||
writeToFile = open(tmp, 'w')
|
|
||||||
|
|
||||||
for items in data:
|
|
||||||
if items.find('DB_NAME') > -1:
|
|
||||||
writeToFile.write("\ndefine( 'DB_NAME', '%s' );\n" % (dbNameRestore))
|
|
||||||
elif items.find('DB_USER') > -1:
|
|
||||||
writeToFile.write("\ndefine( 'DB_USER', '%s' );\n" % (dbUser))
|
|
||||||
elif items.find('DB_PASSWORD') > -1:
|
|
||||||
writeToFile.write("\ndefine( 'DB_PASSWORD', '%s' );\n" % (dbPassword))
|
|
||||||
elif items.find('WP_SITEURL') > -1:
|
|
||||||
continue
|
|
||||||
elif items.find("table_prefix") > -1:
|
|
||||||
writeToFile.writelines(items)
|
|
||||||
content = """
|
|
||||||
define('WP_HOME','http://%s');
|
|
||||||
define('WP_SITEURL','http://%s');
|
|
||||||
""" % (domain, domain)
|
|
||||||
writeToFile.write(content)
|
|
||||||
else:
|
|
||||||
writeToFile.write(items + '\n')
|
|
||||||
|
|
||||||
writeToFile.close()
|
|
||||||
|
|
||||||
command = 'mv %s %s' % (tmp, pathFinalConfig)
|
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
command = 'chown %s:%s %s' % (website.externalApp, website.externalApp, pathFinalConfig)
|
## Import
|
||||||
|
|
||||||
|
command = 'wp --allow-root --path=%s --quiet db import %s/dbexport-stage.sql' % (path, path)
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
logging.statusWriter(tempStatusPath, 'Database synced..,100')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(databasePath)
|
command = 'rm -f %s/dbexport-stage.sql' % (path)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
## Sync WP-Content Folder
|
||||||
|
|
||||||
|
command = 'rsync -avz %s/wp-content/ %s/wp-content/' % (masterPath, path)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
## Search and replace url
|
||||||
|
|
||||||
|
command = 'wp search-replace --allow-root --path=%s "%s" "%s"' % (path, masterDomain, domain)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
command = 'wp search-replace --allow-root --path=%s "www.%s" "%s"' % (path, masterDomain, domain)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
logging.statusWriter(tempStatusPath, 'Fixing permissions..,90')
|
||||||
|
|
||||||
from filemanager.filemanager import FileManager
|
from filemanager.filemanager import FileManager
|
||||||
|
|
||||||
fm = FileManager(None, None)
|
fm = FileManager(None, None)
|
||||||
@@ -197,7 +130,7 @@ define('WP_SITEURL','http://%s');
|
|||||||
from plogical.installUtilities import installUtilities
|
from plogical.installUtilities import installUtilities
|
||||||
installUtilities.reStartLiteSpeed()
|
installUtilities.reStartLiteSpeed()
|
||||||
|
|
||||||
logging.statusWriter(tempStatusPath, 'Data copied..,[200]')
|
logging.statusWriter(tempStatusPath, 'Completed,[200]')
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
@@ -208,11 +141,13 @@ define('WP_SITEURL','http://%s');
|
|||||||
try:
|
try:
|
||||||
tempStatusPath = self.extraArgs['tempStatusPath']
|
tempStatusPath = self.extraArgs['tempStatusPath']
|
||||||
childDomain = self.extraArgs['childDomain']
|
childDomain = self.extraArgs['childDomain']
|
||||||
eraseCheck = self.extraArgs['eraseCheck']
|
#eraseCheck = self.extraArgs['eraseCheck']
|
||||||
dbCheck = self.extraArgs['dbCheck']
|
dbCheck = self.extraArgs['dbCheck']
|
||||||
copyChanged = self.extraArgs['copyChanged']
|
#copyChanged = self.extraArgs['copyChanged']
|
||||||
|
|
||||||
|
|
||||||
child = ChildDomains.objects.get(domain=childDomain)
|
child = ChildDomains.objects.get(domain=childDomain)
|
||||||
|
masterPath = '/home/%s/public_html' % (child.master.domain)
|
||||||
|
|
||||||
command = 'chmod 755 /home/%s/public_html' % (child.master.domain)
|
command = 'chmod 755 /home/%s/public_html' % (child.master.domain)
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
@@ -223,59 +158,38 @@ define('WP_SITEURL','http://%s');
|
|||||||
logging.statusWriter(tempStatusPath, 'WordPress is not detected. [404]')
|
logging.statusWriter(tempStatusPath, 'WordPress is not detected. [404]')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if dbCheck:
|
## Restore db
|
||||||
|
|
||||||
logging.statusWriter(tempStatusPath, 'Syncing databases..,10')
|
logging.statusWriter(tempStatusPath, 'Syncing databases..,10')
|
||||||
|
|
||||||
## Create backup of child-domain database
|
command = 'wp --allow-root --path=%s db export %s/dbexport-stage.sql' % (child.path, masterPath)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
configPath = '%s/wp-config.php' % (child.path)
|
|
||||||
|
|
||||||
data = open(configPath, 'r').readlines()
|
|
||||||
|
|
||||||
for items in data:
|
|
||||||
if items.find('DB_NAME') > -1 and items[0] != '/':
|
|
||||||
dbName = items.split("'")[3]
|
|
||||||
if mysqlUtilities.createDatabaseBackup(dbName, '/home/cyberpanel'):
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise BaseException('Failed to create database backup.')
|
|
||||||
|
|
||||||
databasePath = '%s/%s.sql' % ('/home/cyberpanel', dbName)
|
|
||||||
|
|
||||||
## Restore to master domain
|
## Restore to master domain
|
||||||
|
|
||||||
masterPath = '/home/%s/public_html' % (child.master.domain)
|
command = 'wp --allow-root --path=%s --quiet db import %s/dbexport-stage.sql' % (masterPath, masterPath)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
configPath = '%s/wp-config.php' % (masterPath)
|
|
||||||
|
|
||||||
data = open(configPath, 'r').readlines()
|
|
||||||
|
|
||||||
for items in data:
|
|
||||||
if items.find('DB_NAME') > -1 and items[0] != '/':
|
|
||||||
dbNameRestore = items.split("'")[3]
|
|
||||||
if not mysqlUtilities.restoreDatabaseBackup(dbNameRestore, '/home/cyberpanel', None, 1, dbName):
|
|
||||||
try:
|
|
||||||
os.remove(databasePath)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
raise BaseException('Failed to restore database backup.')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove(databasePath)
|
command = 'rm -f %s/dbexport-stage.sql' % (masterPath)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
if eraseCheck:
|
|
||||||
sourcePath = child.path
|
|
||||||
destinationPath = '/home/%s/public_html' % (child.master.domain)
|
|
||||||
|
|
||||||
command = 'rsync -avzh --exclude "wp-config.php" %s/ %s' % (sourcePath, destinationPath)
|
## Sync WP-Content Folder
|
||||||
ProcessUtilities.executioner(command, child.master.externalApp)
|
|
||||||
elif copyChanged:
|
|
||||||
sourcePath = child.path
|
|
||||||
destinationPath = '/home/%s/public_html' % (child.master.domain)
|
|
||||||
|
|
||||||
command = 'rsync -avzh --exclude "wp-config.php" %s/ %s' % (sourcePath, destinationPath)
|
logging.statusWriter(tempStatusPath, 'Syncing data..,50')
|
||||||
ProcessUtilities.executioner(command, child.master.externalApp)
|
|
||||||
|
command = 'rsync -avz %s/wp-content/ %s/wp-content/' % (child.path, masterPath)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
## Search and replace url
|
||||||
|
|
||||||
|
command = 'wp search-replace --allow-root --path=%s "%s" "%s"' % (masterPath, child.domain, child.master.domain)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
command = 'wp search-replace --allow-root --path=%s "www.%s" "%s"' % (masterPath, child.domain, child.master.domain)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
from filemanager.filemanager import FileManager
|
from filemanager.filemanager import FileManager
|
||||||
|
|
||||||
@@ -285,7 +199,7 @@ define('WP_SITEURL','http://%s');
|
|||||||
from plogical.installUtilities import installUtilities
|
from plogical.installUtilities import installUtilities
|
||||||
installUtilities.reStartLiteSpeed()
|
installUtilities.reStartLiteSpeed()
|
||||||
|
|
||||||
logging.statusWriter(tempStatusPath, 'Data copied..,[200]')
|
logging.statusWriter(tempStatusPath, 'Completed,[200]')
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
|
|||||||
Reference in New Issue
Block a user