Skip to content

Commit

Permalink
#1197 removes more circular references
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhyder committed Mar 9, 2017
1 parent 242849a commit 1128971
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
2 changes: 0 additions & 2 deletions include/http/request_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ const UrlUtils = require('../../lib/utils/urlUtils');
*/
RequestHandler.DEFAULT_THEME = Configuration.active.plugins.default;

RequestHandler.sites = {};
RequestHandler.redirectHosts = {};
var GLOBAL_SITE = SiteUtils.GLOBAL_SITE;

/**
Expand Down
6 changes: 4 additions & 2 deletions include/service/entities/site_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,10 @@ class SiteService extends BaseObjectService {
return hostname !== newHostname;
});
data.prevHostnames.push(prevHostname);
RequestHandler.redirectHosts[prevHostname] = newHostname;
RequestHandler.sites[prevHostname] = null;

//TODO [1.0] did this change prevent the ability for renamed sites to be active?
ActiveSiteService.setRedirectHost(prevHostname, newHostname);
ActiveSiteService.deregister(data.uid);
}
return data;
}
Expand Down
8 changes: 5 additions & 3 deletions include/system/analytics_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

//dependencies
const _ = require('lodash');
const ActiveSiteService = require('../../lib/service/sites/activeSiteService');
const async = require('async');
const Configuration = require('../config');
const domain = require('domain');
Expand Down Expand Up @@ -399,11 +400,12 @@ const ValidationService = require('../validation/validation_service');
* providers.
*/
AnalyticsManager.onPageRender = function(req, session, ls, cb) {
var context = {
site: RequestHandler.sites[req.headers.host] ? RequestHandler.sites[req.headers.host].uid : null,
let site = ActiveSiteService.getByHostname(req.headers.host);
let context = {
site: !!site ? site.uid : null,
timeout: Configuration.active.analytics.timeout
};
var managerInstance = new AnalyticsManager(context);
let managerInstance = new AnalyticsManager(context);
managerInstance.gatherData(req, session, ls, cb);
};

Expand Down
11 changes: 10 additions & 1 deletion lib/service/sites/activeSiteService.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ActiveSiteService {

//Populate redirect hosts index if this site has previous hostnames exist
siteSpec.prevHostnames.forEach(function (oldHostname) {
REDIRECT_HOSTS[oldHostname] = siteSpec.hostname;
ActiveSiteService.setRedirectHost(oldHostname, siteSpec.hostname);
});

return true;
Expand Down Expand Up @@ -125,6 +125,15 @@ class ActiveSiteService {
static getRedirectForHostname (hostname) {
return REDIRECT_HOSTS[hostname];
}

/**
*
* @param {string} hostname
* @param {string} redirectsToHostname
*/
static setRedirectHost(hostname, redirectsToHostname) {
REDIRECT_HOSTS[hostname] = redirectsToHostname;
}
}

module.exports = ActiveSiteService;
6 changes: 5 additions & 1 deletion plugins/ga/ga.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

module.exports = function (pb) {

//pb dependencies
const ActiveSiteService = pb.ActiveSiteService;

/**
* GoogleAnalytics - A sample for exemplifying what the main module file should
* look like.
Expand Down Expand Up @@ -91,7 +94,8 @@ module.exports = function (pb) {
* @param {function} cb (Error, string)
*/
GoogleAnalytics.onRequest = function(req, session, ls, cb) {
var siteId = pb.SiteService.getCurrentSite(pb.RequestHandler.sites[req.headers.host] ? pb.RequestHandler.sites[req.headers.host].uid : null);
let site = ActiveSiteService.getByHostname(req.headers.host);
var siteId = pb.SiteService.getCurrentSite(!!site ? site.uid : null);
var context = {
site: siteId,
pluginService: new pb.PluginService({site: siteId}),
Expand Down

0 comments on commit 1128971

Please sign in to comment.