Refactor wp-config.php setup

This commit is contained in:
VirtuBox
2019-10-29 19:26:51 +01:00
parent aa5f2eeb49
commit b874616343

View File

@@ -23,6 +23,7 @@ from wo.core.services import WOService
from wo.core.shellexec import CommandExecutionError, WOShellExec from wo.core.shellexec import CommandExecutionError, WOShellExec
from wo.core.sslutils import SSL from wo.core.sslutils import SSL
from wo.core.variables import WOVar from wo.core.variables import WOVar
from wo.core.wpcli import WOWp
class SiteError(Exception): class SiteError(Exception):
@@ -366,45 +367,33 @@ def setupwordpress(self, data, vhostonly=False):
except CommandExecutionError: except CommandExecutionError:
raise SiteError("generate wp-config failed for wp multi site") raise SiteError("generate wp-config failed for wp multi site")
try: # set all wp-config.php variables
wp_conf_variables = [
['WP_CACHE_KEY_SALT', '{0}:'.format(wo_domain_name)],
['WP_MEMORY_LIMIT', '128M'],
['WP_MAX_MEMORY_LIMIT', '256M'],
['CONCATENATE_SCRIPTS', 'false'],
['WP_POST_REVISIONS', '10'],
['MEDIA_TRASH', 'true'],
['EMPTY_TRASH_DAYS', '15'],
['WP_AUTO_UPDATE_CORE', 'minor']]
WOShellExec.cmd_exec(self, "/bin/bash -c \"{0} --allow-root " for wp_conf in wp_conf_variables:
.format(WOVar.wo_wpcli_path) + wp_var = wp_conf[0]
"config set WP_CACHE_KEY_SALT " wp_val = wp_conf[1]
"\'{0}:\'\"".format(wo_domain_name)) if wp_val == 'true' or wp_val == 'false':
var_raw = True
WOShellExec.cmd_exec(self, "/bin/bash -c \"{0} --allow-root " try:
.format(WOVar.wo_wpcli_path) + WOShellExec.cmd_exec(
"config set WP_MEMORY_LIMIT " self, "/bin/bash -c \"{0} --allow-root "
"\'128M\'\"") .format(WOVar.wo_wpcli_path) +
WOShellExec.cmd_exec(self, "/bin/bash -c \"{0} --allow-root " "config set {0} "
.format(WOVar.wo_wpcli_path) + "\'{1}\' {wp_raw}\""
"config set WP_MAX_MEMORY_LIMIT " .format(wp_var, wp_val,
"\'256M\'\"") wp_raw='--raw' if var_raw is True else ''))
WOShellExec.cmd_exec(self, "/bin/bash -c \"{0} --allow-root " except CommandExecutionError as e:
.format(WOVar.wo_wpcli_path) + Log.debug(self, str(e))
"config set CONCATENATE_SCRIPTS " Log.error(self, 'Unable to define wp-config.php variables')
"false --raw\"")
WOShellExec.cmd_exec(self, "/bin/bash -c \"{0} --allow-root "
.format(WOVar.wo_wpcli_path) +
"config set WP_POST_REVISIONS "
"\'10\'\"")
WOShellExec.cmd_exec(self, "/bin/bash -c \"{0} --allow-root "
.format(WOVar.wo_wpcli_path) +
"config set MEDIA_TRASH "
"true --raw\"")
WOShellExec.cmd_exec(self, "/bin/bash -c \"{0} --allow-root "
.format(WOVar.wo_wpcli_path) +
"config set EMPTY_TRASH_DAYS "
"\'15\'\"")
WOShellExec.cmd_exec(self, "/bin/bash -c \"{0} --allow-root "
.format(WOVar.wo_wpcli_path) +
"config set WP_AUTO_UPDATE_CORE "
"minor\"")
except CommandExecutionError as e:
Log.debug(self, str(e))
Log.error(self, "Unable to define extra variable in wp-config.php")
# WOFileUtils.mvfile(self, os.getcwd()+'/wp-config.php', # WOFileUtils.mvfile(self, os.getcwd()+'/wp-config.php',
# os.path.abspath(os.path.join(os.getcwd(), os.pardir))) # os.path.abspath(os.path.join(os.getcwd(), os.pardir)))
@@ -458,7 +447,8 @@ def setupwordpress(self, data, vhostonly=False):
if not data['multisite']: if not data['multisite']:
Log.debug(self, "Creating tables for WordPress Single site") Log.debug(self, "Creating tables for WordPress Single site")
Log.debug(self, "{0} --allow-root core install " Log.debug(
self, "{0} --allow-root core install "
.format(WOVar.wo_wpcli_path) + .format(WOVar.wo_wpcli_path) +
"--url=\'{0}\' --title=\'{0}\' --admin_name=\'{1}\' " "--url=\'{0}\' --title=\'{0}\' --admin_name=\'{1}\' "
.format(data['site_name'], wo_wp_user) + .format(data['site_name'], wo_wp_user) +
@@ -605,6 +595,11 @@ def setupwordpress(self, data, vhostonly=False):
plugin_data = json.dumps(plugin_data_object) plugin_data = json.dumps(plugin_data_object)
setupwp_plugin(self, 'cache-enabler', 'cache-enabler', setupwp_plugin(self, 'cache-enabler', 'cache-enabler',
plugin_data, data) plugin_data, data)
WOShellExec.cmd_exec(
self, "/bin/bash -c \"{0} --allow-root "
.format(WOVar.wo_wpcli_path) +
"config set WP_CACHE "
"true --raw\"")
if vhostonly: if vhostonly:
try: try: