Skip to content

Commit

Permalink
bug fix: wp staging
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed May 15, 2020
1 parent 8743fa9 commit db7d0f5
Showing 1 changed file with 54 additions and 17 deletions.
71 changes: 54 additions & 17 deletions websiteFunctions/StagingSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def startCloning(self):

website = Websites.objects.get(domain=masterDomain)

masterPath = '/home/%s/public_html' % (masterDomain)

command = 'chmod 755 %s' % (masterPath)
ProcessUtilities.executioner(command)

## Creating Child Domain

path = "/home/" + masterDomain + "/public_html/" + domain
Expand All @@ -57,18 +62,37 @@ def startCloning(self):
if data.find('[200]') > -1:
pass
else:
logging.statusWriter(tempStatusPath, 'Failed to create child-domain for staging enviroment. [404]')
logging.statusWriter(tempStatusPath, 'Failed to create child-domain for staging environment. [404]')
return 0

logging.statusWriter(tempStatusPath, 'Domain successfully created..,15')

## Copying Data

masterPath = '/home/%s/public_html' % (masterDomain)
## Fetch child domain 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)

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)

command = 'rsync -avzh --exclude "%s" --exclude ".git" --exclude "wp-content/backups" --exclude "wp-content/updraft" --exclude "wp-content/cache" --exclude "wp-content/plugins/litespeed-cache" %s/ %s' % (
domain, masterPath, path)
ProcessUtilities.executioner(command, website.externalApp)

logging.statusWriter(tempStatusPath, 'Data copied..,50')

Expand All @@ -82,11 +106,15 @@ def startCloning(self):

configPath = '%s/wp-config.php' % (masterPath)

if not os.path.exists(configPath):
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

data = open(configPath, 'r').readlines()
command = 'cat %s' % (configPath)
data = ProcessUtilities.outputExecutioner(command).split('\n')

for items in data:
if items.find('DB_NAME') > -1:
Expand All @@ -105,11 +133,6 @@ def startCloning(self):

databasePath = '%s/%s.sql' % ('/home/cyberpanel', dbName)

command = "sed -i 's/%s/%s/g' %s" % (masterDomain, domain, databasePath)
ProcessUtilities.executioner(command, 'cyberpanel')
command = "sed -i 's/%s/%s/g' %s" % ('https', 'http', databasePath)
ProcessUtilities.executioner(command, 'cyberpanel')

if not mysqlUtilities.restoreDatabaseBackup(dbNameRestore, '/home/cyberpanel', None, 1, dbName):
try:
os.remove(databasePath)
Expand All @@ -125,22 +148,31 @@ def startCloning(self):
## Update final config file

pathFinalConfig = '%s/wp-config.php' % (path)
data = open(pathFinalConfig, 'r').readlines()

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("define( 'DB_NAME', '%s' );\n" % (dbNameRestore))
writeToFile.write("\ndefine( 'DB_NAME', '%s' );\n" % (dbNameRestore))
elif items.find('DB_USER') > -1:
writeToFile.write("define( 'DB_USER', '%s' );\n" % (dbUser))
writeToFile.write("\ndefine( 'DB_USER', '%s' );\n" % (dbUser))
elif items.find('DB_PASSWORD') > -1:
writeToFile.write("define( 'DB_PASSWORD', '%s' );\n" % (dbPassword))
writeToFile.write("\ndefine( 'DB_PASSWORD', '%s' );\n" % (dbPassword))
elif items.find('WP_SITEURL') > -1:
continue
elif items.find("That's all, stop editing! Happy publishing.") > -1:
content = """
define('WP_HOME','http://%s');
define('WP_SITEURL','http://%s');
""" % (domain, domain)
writeToFile.write(content)
writeToFile.writelines(items)
else:
writeToFile.write(items)
writeToFile.write(items + '\n')

writeToFile.close()

Expand All @@ -157,6 +189,11 @@ def startCloning(self):
except:
pass

from filemanager.filemanager import FileManager

fm = FileManager(None, None)
fm.fixPermissions(masterDomain)

logging.statusWriter(tempStatusPath, 'Data copied..,[200]')

return 0
Expand Down

0 comments on commit db7d0f5

Please sign in to comment.