From 8b6b3fc63425d46a8033e38768748909bf873e1a Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Mon, 6 Jun 2016 18:44:17 -0400 Subject: [PATCH] #1056 Stabilizing bug that incorrectly called command service to setup first site in db migration for multisite --- include/dao/db_migrate.js | 27 ++++++++++++------- include/service/entities/site_service.js | 4 +-- include/system/command/command_service.js | 2 +- .../system/command/redis_command_broker.js | 10 +++---- sample.config.js | 15 ++++++----- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/include/dao/db_migrate.js b/include/dao/db_migrate.js index 8f03770a3..8be64afa0 100644 --- a/include/dao/db_migrate.js +++ b/include/dao/db_migrate.js @@ -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', @@ -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, @@ -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', @@ -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), @@ -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); }; /** diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 510f57446..fa6b1b1df 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -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); @@ -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) { diff --git a/include/system/command/command_service.js b/include/system/command/command_service.js index 27b7e73ad..e78f686d2 100755 --- a/include/system/command/command_service.js +++ b/include/system/command/command_service.js @@ -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); } diff --git a/include/system/command/redis_command_broker.js b/include/system/command/redis_command_broker.js index 0afbc447a..cc1d2840f 100755 --- a/include/system/command/redis_command_broker.js +++ b/include/system/command/redis_command_broker.js @@ -14,6 +14,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +'use strict'; //dependencies var util = require('../../util.js'); @@ -42,7 +43,7 @@ module.exports = function RedisCommandBrokerModule(pb) { * @type {Client} */ this.subscribeClient = null; - }; + } //statics /** @@ -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{ @@ -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 diff --git a/sample.config.js b/sample.config.js index 51628282f..3b252d9b4 100644 --- a/sample.config.js +++ b/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" */ @@ -22,7 +22,8 @@ module.exports = { "127.0.0.1:27017" ], "name": "pencilblue", - "writeConcern": 1 + "writeConcern": 1, + query_logging: false }, "cache": { "fake": true,