Skip to content

Commit

Permalink
#1056 Stabilizing bug that incorrectly called command service to setu…
Browse files Browse the repository at this point in the history
…p first site in db migration for multisite
  • Loading branch information
brianhyder committed Jun 6, 2016
1 parent 4504fb3 commit 8b6b3fc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 26 deletions.
27 changes: 17 additions & 10 deletions include/dao/db_migrate.js
Expand Up @@ -2,14 +2,15 @@ var url = require('url');
var async = require('async');
var util = require('../util.js');

module.exports = function DBMigrateModule(pb) {
module.exports = function (pb) {

/**
* Array of collections used to append a "site" value to all documents
* @private
* @static
* @readonly
* @property MIGRATE_ALL
* @type {string[]}
* @type {Array}
*/
var MIGRATE_ALL = [
'article',
Expand All @@ -31,7 +32,7 @@ module.exports = function DBMigrateModule(pb) {
* @static
* @readonly
* @property SITE_SPECIFIC_USERS
* @type {string[]}
* @type {Array}
*/
var SITE_SPECIFIC_USERS = [
pb.security.ACCESS_EDITOR,
Expand All @@ -45,7 +46,7 @@ module.exports = function DBMigrateModule(pb) {
* @static
* @readonly
* @property SITE_SPECIFIC_SETTINGS
* @type {string[]}
* @type {Array}
*/
var SITE_SPECIFIC_SETTINGS = [
'active_theme',
Expand All @@ -70,12 +71,18 @@ module.exports = function DBMigrateModule(pb) {
var self = this;
var siteService = new pb.SiteService();
siteService.getSiteMap(function (err, result) {
if (util.isError(err)) {
return cb(err);
}
if (!pb.config.multisite.enabled || result.active.length > 0 || result.inactive.length > 0) {
return cb(null, true);
}

self.createSite(function (err, isTaken, field, result) {
self.siteUid = result.uid;
self.createSite(function (err, result) {
if (util.isError(err)) {
return cb(err);
}
self.siteUid = result.site.uid;
var tasks = [
util.wrapTask(self, self.migrateContentAndPluginData),
util.wrapTask(self, self.migrateSettings),
Expand All @@ -91,12 +98,12 @@ module.exports = function DBMigrateModule(pb) {
* @param {Function} cb
*/
this.createSite = function (cb) {
var siteService = new pb.SiteService();
var site = pb.DocumentCreator.create('site', {
var site = {
displayName: pb.config.siteName,
hostname: url.parse(pb.config.siteRoot).host
});
siteService.createSite(site, '', cb);
};
var siteService = new pb.SiteService();
siteService.createSite(site, cb);
};

/**
Expand Down
4 changes: 1 addition & 3 deletions include/service/entities/site_service.js
Expand Up @@ -290,7 +290,7 @@ module.exports = function SiteServiceModule(pb) {
*/
SiteService.prototype.editSite = function(options, cb) {
cb = cb || util.cb;
var name = util.format("EDIT_SITE%s", options.site);
var name = util.format("EDIT_SITE%s", options.uid);
var job = new pb.SiteCreateEditJob();
job.setRunAsInitiator(true);
job.init(name);
Expand All @@ -303,10 +303,8 @@ module.exports = function SiteServiceModule(pb) {
* Creates a site and saves it to the database.
* @method createSite
* @param {Object} options - object containing site fields
* @param {String} options.uid - site unique id
* @param {String} options.hostname - result of site hostname edit/create
* @param {String} options.displayName - result of site display name edit/create
* @param {String} id - the site unique identifier for the database
* @param {Function} cb - callback function
*/
SiteService.prototype.createSite = function(options, cb) {
Expand Down
2 changes: 1 addition & 1 deletion include/system/command/command_service.js
Expand Up @@ -100,7 +100,7 @@ module.exports = function CommandServiceModule(pb) {

//instantiate the command broker
var self = this;
this.broker.init(function (err, result) {
this.broker.init(function (err) {
if (util.isError(err)) {
return cb(err);
}
Expand Down
10 changes: 5 additions & 5 deletions include/system/command/redis_command_broker.js
Expand Up @@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';

//dependencies
var util = require('../../util.js');
Expand Down Expand Up @@ -42,7 +43,7 @@ module.exports = function RedisCommandBrokerModule(pb) {
* @type {Client}
*/
this.subscribeClient = null;
};
}

//statics
/**
Expand Down Expand Up @@ -102,7 +103,7 @@ module.exports = function RedisCommandBrokerModule(pb) {
* @param {String} commandStr The message that was published
*/
RedisCommandBroker.prototype.onCommandReceived = function(channel, commandStr) {
pb.log.silly('RedisCommandBroker: Command recieved [%s]%s', channel, commandStr);
pb.log.silly('RedisCommandBroker: Command received [%s]%s', channel, commandStr);

if (SUBSCRIBERS[channel]) {
try{
Expand Down Expand Up @@ -146,9 +147,8 @@ module.exports = function RedisCommandBrokerModule(pb) {
* @param {Function} cb A callback that takes two parameters: cb(Error, [RESULT])
*/
RedisCommandBroker.prototype.subscribe = function(channel, onCommandReceived, cb) {
if (!pb.validation.validateNonEmptyStr(channel, true) || !util.isFunction(onCommandReceived)) {
cb(new Error('A valid channel string and handler function is required'));
return;
if (!pb.ValidationService.isNonEmptyStr(channel, true) || !util.isFunction(onCommandReceived)) {
return cb(new Error('A valid channel string and handler function is required'));
}

//setup the one time subscribe callback
Expand Down
15 changes: 8 additions & 7 deletions sample.config.js
@@ -1,11 +1,11 @@
/**
* This is a sample configuration meant to get users and up running on a local
* machine. The configuration will not support multi-process on a single
* server or multi-server/elastic environments. For more detailed information
* This is a sample configuration meant to get users and up running on a local
* machine. The configuration will not support multi-process on a single
* server or multi-server/elastic environments. For more detailed information
* on the options provided please refer to the /include/config.js file.
*
* The file can be renamed to "config.js" in the same directory as this file
* and it will be used as the configuration when PencilBlue is started. If
*
* The file can be renamed to "config.js" in the same directory as this file
* and it will be used as the configuration when PencilBlue is started. If
* this file is used then there is no need to create a "config.json"
*/

Expand All @@ -22,7 +22,8 @@ module.exports = {
"127.0.0.1:27017"
],
"name": "pencilblue",
"writeConcern": 1
"writeConcern": 1,
query_logging: false
},
"cache": {
"fake": true,
Expand Down

0 comments on commit 8b6b3fc

Please sign in to comment.