Skip to content

Commit

Permalink
馃悰 fix direct blog migration and permission fixture options (#7320)
Browse files Browse the repository at this point in the history
* 馃悰 fix direct update

closes #7297
- move sitemap initialisation into sitemap handler
- initialise sitemap on first request to sitemap

* 馃悰 fix how we pass options to migration files

refs #7317
- clone options when passing them into the migration/fixture files
- do not use default sequence, because it does not clone the arguments
  • Loading branch information
kirrg001 authored and ErisDS committed Sep 6, 2016
1 parent 4e6b1d7 commit 2142a9c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
12 changes: 11 additions & 1 deletion core/server/data/migration/fixtures/update.js
Expand Up @@ -4,7 +4,17 @@
// E.g. if we update to version 004, all the tasks in /004/ are executed

var Promise = require('bluebird'),
sequence = require('../../../utils/sequence'),
_ = require('lodash'),
sequence = function sequence(tasks, modelOptions, logger) {
// utils/sequence.js does not offer an option to pass cloned arguments
return Promise.reduce(tasks, function (results, task) {
return task(_.cloneDeep(modelOptions), logger)
.then(function (result) {
results.push(result);
return results;
});
}, []);
},
update;

/**
Expand Down
13 changes: 11 additions & 2 deletions core/server/data/migration/update.js
@@ -1,14 +1,23 @@
// # Update Database
// Handles migrating a database between two different database versions
var Promise = require('bluebird'),
_ = require('lodash'),
backup = require('./backup'),
fixtures = require('./fixtures'),
errors = require('../../errors'),
i18n = require('../../i18n'),
db = require('../../data/db'),
sequence = require('../../utils/sequence'),
versioning = require('../schema').versioning,

sequence = function sequence(tasks, modelOptions, logger) {
// utils/sequence.js does not offer an option to pass cloned arguments
return Promise.reduce(tasks, function (results, task) {
return task(_.cloneDeep(modelOptions), logger)
.then(function (result) {
results.push(result);
return results;
});
}, []);
},
updateDatabaseSchema,
migrateToDatabaseVersion,
execute, logger, isDatabaseOutOfDate;
Expand Down
17 changes: 15 additions & 2 deletions core/server/data/xml/sitemap/handler.js
Expand Up @@ -24,7 +24,7 @@ module.exports = function handler(blogApp) {
res.send(sitemap.getIndexXml());
});

blogApp.get('/sitemap-:resource.xml', verifyResourceType, function sitemapResourceXML(req, res) {
blogApp.get('/sitemap-:resource.xml', verifyResourceType, function sitemapResourceXML(req, res, next) {
var type = req.params.resource,
page = 1,
siteMapXml = getResourceSiteMapXml(type, page);
Expand All @@ -33,6 +33,19 @@ module.exports = function handler(blogApp) {
'Cache-Control': 'public, max-age=' + utils.ONE_HOUR_S,
'Content-Type': 'text/xml'
});
res.send(siteMapXml);

// CASE: returns null if sitemap is not initialized
if (!siteMapXml) {
sitemap.init()
.then(function () {
siteMapXml = getResourceSiteMapXml(type, page);
res.send(siteMapXml);
})
.catch(function (err) {
next(err);
});
} else {
res.send(siteMapXml);
}
});
};
7 changes: 4 additions & 3 deletions core/server/index.js
Expand Up @@ -16,7 +16,6 @@ var express = require('express'),
models = require('./models'),
permissions = require('./permissions'),
apps = require('./apps'),
sitemap = require('./data/xml/sitemap'),
xmlrpc = require('./data/xml/xmlrpc'),
slack = require('./data/slack'),
GhostServer = require('./ghost-server'),
Expand Down Expand Up @@ -86,6 +85,10 @@ function init(options) {
}).then(function () {
config.maintenance.enabled = maintenanceState;
}).catch(function (err) {
if (!err) {
return;
}

errors.logErrorAndExit(err, err.context, err.help);
});
} else if (response.error) {
Expand Down Expand Up @@ -115,8 +118,6 @@ function init(options) {
initDbHashAndFirstRun(),
// Initialize apps
apps.init(),
// Initialize sitemaps
sitemap.init(),
// Initialize xmrpc ping
xmlrpc.listen(),
// Initialize slack ping
Expand Down
2 changes: 0 additions & 2 deletions core/test/unit/server_spec.js
Expand Up @@ -11,7 +11,6 @@ var should = require('should'),
api = require(config.paths.corePath + '/server/api'),
apps = require(config.paths.corePath + '/server/apps'),
i18n = require(config.paths.corePath + '/server/i18n'),
sitemap = require(config.paths.corePath + '/server/data/xml/sitemap'),
xmlrpc = require(config.paths.corePath + '/server/data/xml/xmlrpc'),
slack = require(config.paths.corePath + '/server/data/slack'),
scheduling = require(config.paths.corePath + '/server/scheduling'),
Expand All @@ -37,7 +36,6 @@ describe('server bootstrap', function () {
sandbox.stub(apps, 'init').returns(Promise.resolve());
sandbox.stub(slack, 'listen').returns(Promise.resolve());
sandbox.stub(xmlrpc, 'listen').returns(Promise.resolve());
sandbox.stub(sitemap, 'init').returns(Promise.resolve());
sandbox.stub(scheduling, 'init').returns(Promise.resolve());

resetMiddlewareStub = bootstrap.__set__('middleware', middlewareStub);
Expand Down

0 comments on commit 2142a9c

Please sign in to comment.