Skip to content

Commit db7d0f5

Browse files
committed
bug fix: wp staging
1 parent 8743fa9 commit db7d0f5

1 file changed

Lines changed: 54 additions & 17 deletions

File tree

websiteFunctions/StagingSetup.py

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ def startCloning(self):
3636

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

39+
masterPath = '/home/%s/public_html' % (masterDomain)
40+
41+
command = 'chmod 755 %s' % (masterPath)
42+
ProcessUtilities.executioner(command)
43+
3944
## Creating Child Domain
4045

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

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

6570
## Copying Data
6671

67-
masterPath = '/home/%s/public_html' % (masterDomain)
72+
## Fetch child domain path
73+
74+
childDomainPaths = []
75+
76+
for childs in website.childdomains_set.all():
77+
childDomainPaths.append(childs.path)
78+
79+
filesAndFolder = os.listdir(masterPath)
80+
81+
for items in filesAndFolder:
82+
completePath = '%s/%s' % (masterPath, items)
83+
84+
if completePath in childDomainPaths:
85+
continue
86+
else:
87+
command = 'cp -r %s %s/' % (completePath, path)
88+
ProcessUtilities.executioner(command, website.externalApp)
89+
90+
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)]
91+
92+
for rmv in foldersToBeRemoved:
93+
command = 'rm -rf %s' % (rmv)
94+
ProcessUtilities.executioner(command, website.externalApp)
6895

69-
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' % (
70-
domain, masterPath, path)
71-
ProcessUtilities.executioner(command, website.externalApp)
7296

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

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

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

85-
if not os.path.exists(configPath):
109+
command = 'ls -la %s' % (configPath)
110+
output = ProcessUtilities.outputExecutioner(command)
111+
112+
if output.find('No such file or') > -1:
86113
logging.statusWriter(tempStatusPath, 'WordPress is not detected. [404]')
87114
return 0
88115

89-
data = open(configPath, 'r').readlines()
116+
command = 'cat %s' % (configPath)
117+
data = ProcessUtilities.outputExecutioner(command).split('\n')
90118

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

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

108-
command = "sed -i 's/%s/%s/g' %s" % (masterDomain, domain, databasePath)
109-
ProcessUtilities.executioner(command, 'cyberpanel')
110-
command = "sed -i 's/%s/%s/g' %s" % ('https', 'http', databasePath)
111-
ProcessUtilities.executioner(command, 'cyberpanel')
112-
113136
if not mysqlUtilities.restoreDatabaseBackup(dbNameRestore, '/home/cyberpanel', None, 1, dbName):
114137
try:
115138
os.remove(databasePath)
@@ -125,22 +148,31 @@ def startCloning(self):
125148
## Update final config file
126149

127150
pathFinalConfig = '%s/wp-config.php' % (path)
128-
data = open(pathFinalConfig, 'r').readlines()
151+
152+
command = 'cat %s' % (configPath)
153+
data = ProcessUtilities.outputExecutioner(command).split('\n')
129154

130155
tmp = "/tmp/" + str(randint(1000, 9999))
131156
writeToFile = open(tmp, 'w')
132157

133158
for items in data:
134159
if items.find('DB_NAME') > -1:
135-
writeToFile.write("define( 'DB_NAME', '%s' );\n" % (dbNameRestore))
160+
writeToFile.write("\ndefine( 'DB_NAME', '%s' );\n" % (dbNameRestore))
136161
elif items.find('DB_USER') > -1:
137-
writeToFile.write("define( 'DB_USER', '%s' );\n" % (dbUser))
162+
writeToFile.write("\ndefine( 'DB_USER', '%s' );\n" % (dbUser))
138163
elif items.find('DB_PASSWORD') > -1:
139-
writeToFile.write("define( 'DB_PASSWORD', '%s' );\n" % (dbPassword))
164+
writeToFile.write("\ndefine( 'DB_PASSWORD', '%s' );\n" % (dbPassword))
140165
elif items.find('WP_SITEURL') > -1:
141166
continue
167+
elif items.find("That's all, stop editing! Happy publishing.") > -1:
168+
content = """
169+
define('WP_HOME','http://%s');
170+
define('WP_SITEURL','http://%s');
171+
""" % (domain, domain)
172+
writeToFile.write(content)
173+
writeToFile.writelines(items)
142174
else:
143-
writeToFile.write(items)
175+
writeToFile.write(items + '\n')
144176

145177
writeToFile.close()
146178

@@ -157,6 +189,11 @@ def startCloning(self):
157189
except:
158190
pass
159191

192+
from filemanager.filemanager import FileManager
193+
194+
fm = FileManager(None, None)
195+
fm.fixPermissions(masterDomain)
196+
160197
logging.statusWriter(tempStatusPath, 'Data copied..,[200]')
161198

162199
return 0

0 commit comments

Comments
 (0)