mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-14 00:39:57 +09:00
Load site_module_info from 'domains' table instead of 'sites' table
This commit is contained in:
parent
a69bac6e2b
commit
726220d3eb
4 changed files with 85 additions and 121 deletions
|
|
@ -262,14 +262,10 @@ class Context
|
|||
{
|
||||
$oModuleModel = getModel('module');
|
||||
$site_module_info = $oModuleModel->getDefaultMid() ?: new stdClass;
|
||||
|
||||
// if site_srl of site_module_info is 0 (default site), compare the domain to default_url of db_config
|
||||
if($site_module_info->site_srl == 0 && $site_module_info->domain != $this->db_info->default_url)
|
||||
{
|
||||
$site_module_info->domain = $this->db_info->default_url;
|
||||
}
|
||||
|
||||
self::set('site_module_info', $site_module_info);
|
||||
self::set('_http_port', self::$_instance->db_info->http_port = $site_module_info->http_port ?: null);
|
||||
self::set('_https_port', self::$_instance->db_info->https_port = $site_module_info->https_port ?: null);
|
||||
self::set('_use_ssl', self::$_instance->db_info->use_ssl = $site_module_info->security ?: 'none');
|
||||
if($site_module_info->site_srl && isSiteID($site_module_info->domain))
|
||||
{
|
||||
self::set('vid', $site_module_info->domain, TRUE);
|
||||
|
|
@ -312,9 +308,9 @@ class Context
|
|||
|
||||
if(!$this->lang_type || !isset($enabled_langs[$this->lang_type]))
|
||||
{
|
||||
if($site_module_info->default_language)
|
||||
if($site_module_info->settings->language)
|
||||
{
|
||||
$this->lang_type = $this->db_info->lang_type = $site_module_info->default_language;
|
||||
$this->lang_type = $this->db_info->lang_type = $site_module_info->settings->language;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -470,9 +466,6 @@ class Context
|
|||
// Copy to old format for backward compatibility.
|
||||
self::$_instance->db_info = self::convertDBInfo($config);
|
||||
self::$_instance->allow_rewrite = self::$_instance->db_info->use_rewrite === 'Y';
|
||||
self::set('_http_port', self::$_instance->db_info->http_port ?: null);
|
||||
self::set('_https_port', self::$_instance->db_info->https_port ?: null);
|
||||
self::set('_use_ssl', self::$_instance->db_info->use_ssl);
|
||||
$GLOBALS['_time_zone'] = self::$_instance->db_info->time_zone;
|
||||
}
|
||||
|
||||
|
|
@ -1568,19 +1561,14 @@ class Context
|
|||
// if $domain is set, compare current URL. If they are same, remove the domain, otherwise link to the domain.
|
||||
if($domain)
|
||||
{
|
||||
$domain_info = parse_url($domain);
|
||||
if(is_null($current_info))
|
||||
{
|
||||
$current_info = parse_url((RX_SSL ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . RX_BASEURL);
|
||||
$current_info = parse_url((RX_SSL ? 'https' : 'http') . '://' . Rhymix\Framework\URL::decodeIdna($_SERVER['HTTP_HOST']) . RX_BASEURL);
|
||||
}
|
||||
if($domain_info['host'] . $domain_info['path'] == $current_info['host'] . $current_info['path'])
|
||||
if($domain === $current_info['host'])
|
||||
{
|
||||
unset($domain);
|
||||
}
|
||||
else
|
||||
{
|
||||
$domain = rtrim(preg_replace('/^(http|https):\/\//i', '', trim($domain)), '/') . '/';
|
||||
}
|
||||
}
|
||||
|
||||
$get_vars = array();
|
||||
|
|
@ -1794,7 +1782,7 @@ class Context
|
|||
|
||||
if($domain)
|
||||
{
|
||||
$target_url = rtrim(trim($domain), '/') . '/';
|
||||
$target_url = rtrim(trim($domain), '/') . RX_BASEURL;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ class module extends ModuleObject
|
|||
|
||||
if(!is_dir('./files/ruleset')) return true;
|
||||
|
||||
$args = new stdClass;
|
||||
$args->skin = '.';
|
||||
$output = executeQueryArray('module.getModuleSkinDotList', $args);
|
||||
if($output->data && count($output->data) > 0)
|
||||
|
|
@ -313,12 +314,7 @@ class module extends ModuleObject
|
|||
}
|
||||
|
||||
// Migrate domains
|
||||
if (!$oDB->isTableExists('domains'))
|
||||
{
|
||||
$oDB->createTableByXmlFile($this->module_path . 'schemas/domains.xml');
|
||||
}
|
||||
|
||||
$output = executeQuery('module.getDomains');
|
||||
$output = @executeQuery('module.getDomains');
|
||||
if (!$output->data)
|
||||
{
|
||||
$this->migrateDomains();
|
||||
|
|
@ -397,6 +393,12 @@ class module extends ModuleObject
|
|||
*/
|
||||
function migrateDomains()
|
||||
{
|
||||
// Create the domains table.
|
||||
if (!$oDB->isTableExists('domains'))
|
||||
{
|
||||
$oDB->createTableByXmlFile($this->module_path . 'schemas/domains.xml');
|
||||
}
|
||||
|
||||
// Initialize domains data.
|
||||
$domains = array();
|
||||
|
||||
|
|
|
|||
|
|
@ -51,16 +51,21 @@ class moduleModel extends module
|
|||
function getSiteInfo($site_srl, $columnList = array())
|
||||
{
|
||||
$args = new stdClass();
|
||||
$args->site_srl = $site_srl;
|
||||
$output = executeQuery('module.getSiteInfo', $args, $columnList);
|
||||
$args->domain_srl = $site_srl;
|
||||
$output = executeQuery('module.getDomainInfo', $args, $columnList);
|
||||
return $output->data;
|
||||
}
|
||||
|
||||
function getSiteInfoByDomain($domain, $columnList = array())
|
||||
{
|
||||
if (strpos($domain, '/') !== false)
|
||||
{
|
||||
$domain = parse_url($domain, PHP_URL_HOST);
|
||||
}
|
||||
|
||||
$args = new stdClass();
|
||||
$args->domain = $domain;
|
||||
$output = executeQuery('module.getSiteInfoByDomain', $args, $columnList);
|
||||
$output = executeQuery('module.getDomainInfo', $args, $columnList);
|
||||
return $output->data;
|
||||
}
|
||||
|
||||
|
|
@ -82,108 +87,52 @@ class moduleModel extends module
|
|||
*/
|
||||
function getDefaultMid()
|
||||
{
|
||||
$default_url = Context::getDefaultUrl();
|
||||
if($default_url && substr_compare($default_url, '/', -1) === 0) $default_url = substr($default_url, 0, -1);
|
||||
|
||||
$request_url = Context::getRequestUri();
|
||||
if($request_url && substr_compare($request_url, '/', -1) === 0) $request_url = substr($request_url, 0, -1);
|
||||
|
||||
$default_url_parse = parse_url($default_url);
|
||||
$request_url_parse = parse_url($request_url);
|
||||
$vid = Context::get('vid');
|
||||
$mid = Context::get('mid');
|
||||
|
||||
// Set up
|
||||
$domain = '';
|
||||
$site_info = NULL;
|
||||
if($default_url && $default_url_parse['host'] != $request_url_parse['host'])
|
||||
// Get current domain.
|
||||
$domain = strtolower(preg_replace('/:\d+$/', '', $_SERVER['HTTP_HOST']));
|
||||
if (strpos($domain, 'xn--') !== false)
|
||||
{
|
||||
$url_info = parse_url($request_url);
|
||||
$hostname = $url_info['host'];
|
||||
$path = $url_info['path'];
|
||||
if(strlen($path) >= 1 && substr_compare($path, '/', -1) === 0) $path = substr($path, 0, -1);
|
||||
|
||||
$domain = sprintf('%s%s%s', $hostname, $url_info['port']&&$url_info['port']!=80?':'.$url_info['port']:'',$path);
|
||||
$domain = Rhymix\Framework\URL::decodeIdna($domain);
|
||||
}
|
||||
|
||||
if($domain === '')
|
||||
// Find the domain information.
|
||||
$domain_info = Rhymix\Framework\Cache::get('site_and_module:domain_info:' . $domain);
|
||||
if (!$domain_info)
|
||||
{
|
||||
if(!$vid) $vid = $mid;
|
||||
if($vid)
|
||||
$output = executeQuery('module.getDomainInfo', (object)array('domain' => $domain));
|
||||
if ($output->data)
|
||||
{
|
||||
$domain = $vid;
|
||||
}
|
||||
}
|
||||
|
||||
// If domain is set, look for subsite
|
||||
if($domain !== '')
|
||||
{
|
||||
$site_info = Rhymix\Framework\Cache::get('site_and_module:site_info:' . md5($domain));
|
||||
if($site_info === null)
|
||||
{
|
||||
$args = new stdClass();
|
||||
$args->domain = $domain;
|
||||
$output = executeQuery('module.getSiteInfoByDomain', $args);
|
||||
$site_info = $output->data;
|
||||
Rhymix\Framework\Cache::set('site_and_module:site_info:' . md5($domain), $site_info, 0, true);
|
||||
}
|
||||
|
||||
if($site_info && $vid)
|
||||
{
|
||||
Context::set('vid', $site_info->domain, true);
|
||||
if(strtolower($mid)==strtolower($site_info->domain)) Context::set('mid', $site_info->mid,true);
|
||||
}
|
||||
if(!$site_info || !$site_info->domain) { $domain = ''; unset($site_info); }
|
||||
}
|
||||
|
||||
// If no virtual website was found, get default website
|
||||
if($domain === '')
|
||||
{
|
||||
$site_info = Rhymix\Framework\Cache::get('site_and_module:default_site');
|
||||
if($site_info === null)
|
||||
{
|
||||
$args = new stdClass();
|
||||
$args->site_srl = 0;
|
||||
$output = executeQuery('module.getSiteInfo', $args);
|
||||
// Update the related informaion if there is no default site info
|
||||
if(!$output->data)
|
||||
{
|
||||
// Create a table if sites table doesn't exist
|
||||
$oDB = &DB::getInstance();
|
||||
if(!$oDB->isTableExists('sites')) $oDB->createTableByXmlFile(_XE_PATH_.'modules/module/schemas/sites.xml');
|
||||
if(!$oDB->isTableExists('sites')) return;
|
||||
|
||||
// Get mid, language
|
||||
$mid_output = $oDB->executeQuery('module.getDefaultMidInfo', $args);
|
||||
$domain = Context::getDefaultUrl();
|
||||
$url_info = parse_url($domain);
|
||||
$domain = $url_info['host'].( (!empty($url_info['port'])&&$url_info['port']!=80)?':'.$url_info['port']:'').$url_info['path'];
|
||||
|
||||
$site_args = new stdClass;
|
||||
$site_args->site_srl = 0;
|
||||
$site_args->index_module_srl = $mid_output->data->module_srl;
|
||||
$site_args->domain = $domain;
|
||||
$site_args->default_language = config('locale.default_lang');
|
||||
|
||||
if($output->data && !$output->data->index_module_srl)
|
||||
{
|
||||
$output = executeQuery('module.updateSite', $site_args);
|
||||
$domain_info = $output->data;
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = executeQuery('module.insertSite', $site_args);
|
||||
if(!$output->toBool()) return $output;
|
||||
$output = executeQuery('module.getDomainInfo', (object)array('domain_srl' => 0));
|
||||
if ($output->data)
|
||||
{
|
||||
$domain_info = $output->data;
|
||||
}
|
||||
$output = executeQuery('module.getSiteInfo', $args);
|
||||
}
|
||||
$site_info = $output->data;
|
||||
Rhymix\Framework\Cache::set('site_and_module:default_site', $site_info, 0, true);
|
||||
else
|
||||
{
|
||||
$this->migrateDomains();
|
||||
return $this->getDefaultMid();
|
||||
}
|
||||
}
|
||||
|
||||
if(!$site_info->module_srl) return $site_info;
|
||||
if(is_array($site_info) && $site_info->data[0]) $site_info = $site_info[0];
|
||||
return $this->addModuleExtraVars($site_info);
|
||||
$domain_info->site_srl = $domain_info->domain_srl;
|
||||
$domain_info->settings = $domain_info->settings ? json_decode($domain_info->settings) : new stdClass;
|
||||
$domain_info->default_language = $domain_info->settings->language ?: config('locale.default_lang');
|
||||
|
||||
Rhymix\Framework\Cache::set('site_and_module:domain_info:' . $domain, $domain_info, 0, true);
|
||||
}
|
||||
|
||||
// Fill in module extra vars and return.
|
||||
if ($domain_info->module_srl)
|
||||
{
|
||||
return $this->addModuleExtraVars($domain_info);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $domain_info;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
25
modules/module/queries/getDomainInfo.xml
Normal file
25
modules/module/queries/getDomainInfo.xml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<query id="getDomainInfo" action="select">
|
||||
<tables>
|
||||
<table name="domains" />
|
||||
<table name="modules" />
|
||||
</tables>
|
||||
<columns>
|
||||
<column name="domains.domain_srl" />
|
||||
<column name="domains.domain" />
|
||||
<column name="domains.index_module_srl" />
|
||||
<column name="domains.index_document_srl" />
|
||||
<column name="domains.default_layout_srl" />
|
||||
<column name="domains.default_mlayout_srl" />
|
||||
<column name="domains.default_menu_srl" />
|
||||
<column name="domains.http_port" />
|
||||
<column name="domains.https_port" />
|
||||
<column name="domains.security" />
|
||||
<column name="domains.settings" />
|
||||
<column name="modules.*" />
|
||||
</columns>
|
||||
<conditions>
|
||||
<condition operation="equal" column="modules.module_srl" default="domains.index_module_srl" notnull="notnull" />
|
||||
<condition operation="equal" column="domain_srl" var="domain_srl" pipe="and" />
|
||||
<condition operation="equal" column="domain" var="domain" pipe="and" />
|
||||
</conditions>
|
||||
</query>
|
||||
Loading…
Add table
Add a link
Reference in a new issue