Rewrite site update with wpredis

This commit is contained in:
VirtuBox
2019-06-17 00:25:10 +02:00
parent 675f57d36b
commit c66b9f7b86

View File

@@ -4,6 +4,7 @@ from cement.core import handler, hook
from wo.core.cron import WOCron from wo.core.cron import WOCron
from wo.core.sslutils import SSL from wo.core.sslutils import SSL
from wo.core.variables import WOVariables from wo.core.variables import WOVariables
from wo.core.shellexec import WOShellExec
from wo.core.domainvalidate import ValidateDomain from wo.core.domainvalidate import ValidateDomain
from wo.core.fileutils import WOFileUtils from wo.core.fileutils import WOFileUtils
from wo.cli.plugins.site_functions import * from wo.cli.plugins.site_functions import *
@@ -1610,34 +1611,17 @@ class WOSiteUpdateController(CementBaseController):
if oldcachetype != 'wpredis' and data['wpredis']: if oldcachetype != 'wpredis' and data['wpredis']:
try: try:
if installwp_plugin(self, 'redis-cache', data): if installwp_plugin(self, 'redis-cache', data):
# search for wp-config.php # add WP_CACHE_KEY_SALT if not already set
if WOFileUtils.isexist(self, "{0}/wp-config.php"
.format(wo_site_webroot)):
config_path = '{0}/wp-config.php'.format(
wo_site_webroot)
elif WOFileUtils.isexist(self, "{0}/htdocs/wp-config.php"
.format(wo_site_webroot)):
config_path = '{0}/htdocs/wp-config.php'.format(
wo_site_webroot)
else:
Log.debug(
self, "Updating wp-config.php failed. "
"File could not be located.")
Log.error(
self, "wp-config.php could not be located !!")
raise SiteError
if WOShellExec.cmd_exec(self, "grep -q "
"\"WP_CACHE_KEY_SALT\" {0}"
.format(config_path)):
pass
else:
try: try:
wpconfig = open("{0}".format(config_path), Log.debug(self, "Updating wp-config.php.")
encoding='utf-8', mode='a') WOShellExec.cmd_exec(self,
wpconfig.write("\n\ndefine( \'WP_CACHE_KEY_SALT\'," "bash -c \"php {0} --allow-root "
" \'{0}:\' );".format(wo_domain)) .format(WOVariables.wo_wpcli_path) +
wpconfig.close() "config set --add "
"WP_CACHE_KEY_SALT "
"\'{0}:\' --path={1}\""
.format(wo_domain,
wo_site_webroot))
except IOError as e: except IOError as e:
Log.debug(self, str(e)) Log.debug(self, str(e))
Log.debug(self, "Updating wp-config.php failed.") Log.debug(self, "Updating wp-config.php failed.")