|
|
@ -4,7 +4,6 @@ from sqlalchemy.orm import relationship, backref |
|
|
|
from sqlalchemy.ext.declarative import declarative_base |
|
|
|
from ee.core.logging import Log |
|
|
|
from ee.core.database import db_session |
|
|
|
from ee.core.fileutils import EEFileUtils |
|
|
|
from ee.cli.plugins.models import SiteDB |
|
|
|
import sys |
|
|
|
import glob |
|
|
@ -117,47 +116,3 @@ def getAllsites(self): |
|
|
|
except Exception as e: |
|
|
|
Log.debug(self, "{0}".format(e)) |
|
|
|
Log.error(self, "Unable to query database") |
|
|
|
|
|
|
|
|
|
|
|
class EESync(object): |
|
|
|
|
|
|
|
def __init__(self, app): |
|
|
|
self.app = app |
|
|
|
|
|
|
|
def syncdbinfo(self): |
|
|
|
""" |
|
|
|
1. reads database information from wp/ee-config.php |
|
|
|
2. updates records into ee database accordingly. |
|
|
|
""" |
|
|
|
sites = getAllsites(self) |
|
|
|
if not sites: |
|
|
|
pass |
|
|
|
for site in sites: |
|
|
|
if site.site_type in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']: |
|
|
|
ee_site_webroot = site.site_path |
|
|
|
# Read config files |
|
|
|
configfiles = glob.glob(ee_site_webroot + '/*-config.php') |
|
|
|
if configfiles: |
|
|
|
if EEFileUtils.isexist(self, configfiles[0]): |
|
|
|
ee_db_name = (EEFileUtils.grep(self, configfiles[0], |
|
|
|
'DB_NAME').split(',')[1] |
|
|
|
.split(')')[0].strip().replace('\'', '')) |
|
|
|
ee_db_user = (EEFileUtils.grep(self, configfiles[0], |
|
|
|
'DB_USER').split(',')[1] |
|
|
|
.split(')')[0].strip().replace('\'', '')) |
|
|
|
ee_db_pass = (EEFileUtils.grep(self, configfiles[0], |
|
|
|
'DB_PASSWORD').split(',')[1] |
|
|
|
.split(')')[0].strip().replace('\'', '')) |
|
|
|
ee_db_host = (EEFileUtils.grep(self, configfiles[0], |
|
|
|
'DB_HOST').split(',')[1] |
|
|
|
.split(')')[0].strip().replace('\'', '')) |
|
|
|
|
|
|
|
if site.db_name != ee_db_name: |
|
|
|
# update records if any mismatch found |
|
|
|
Log.debug(self, "Updating {0}" |
|
|
|
.format(site.sitename)) |
|
|
|
updateSiteInfo(self, site.sitename, |
|
|
|
db_name=ee_db_name, |
|
|
|
db_user=ee_db_user, |
|
|
|
db_password=ee_db_pass, |
|
|
|
db_host=ee_db_host) |
|
|
|