Skip to content

Commit

Permalink
🐛 fix direct blog migration and permission fixture options (TryGhost#…
Browse files Browse the repository at this point in the history
…7320)

* 🐛 fix direct update

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

* 🐛 fix how we pass options to migration files

refs TryGhost#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 geekhuyang committed Nov 20, 2016
1 parent ac04839 commit 2f69cf9
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 2f69cf9

Please sign in to comment.