mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
deps: bluebird@3.1.2
closes #6361 - Updated bluebird dependency to latest 3.1.2. - Updated update check to handle promises not resolving to arrays. - Reviewed all other promise code and it looks good. - Updated code using settle to use the new reflect function.
This commit is contained in:
parent
152d74b39e
commit
3db9913191
6 changed files with 58 additions and 53 deletions
|
@ -52,11 +52,13 @@ DataImporter.prototype.doUserImport = function (t, tableData, owner, users, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
// Import users, deduplicating with already present users
|
// Import users, deduplicating with already present users
|
||||||
userOps = utils.importUsers(tableData.users, users, t);
|
userOps = utils.importUsers(tableData.users, users, t).map(function (userImport) {
|
||||||
|
return userImport.reflect();
|
||||||
|
});
|
||||||
|
|
||||||
return Promise.settle(userOps).then(function (descriptors) {
|
return Promise.all(userOps).then(function (descriptors) {
|
||||||
descriptors.forEach(function (d) {
|
descriptors.forEach(function (d) {
|
||||||
if (d.isRejected()) {
|
if (!d.isFulfilled()) {
|
||||||
errors = errors.concat(d.reason());
|
errors = errors.concat(d.reason());
|
||||||
} else {
|
} else {
|
||||||
imported.push(d.value().toJSON(internal));
|
imported.push(d.value().toJSON(internal));
|
||||||
|
@ -133,7 +135,7 @@ DataImporter.prototype.doImport = function (data) {
|
||||||
}
|
}
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
importResults.forEach(function (p) {
|
importResults.forEach(function (p) {
|
||||||
if (p.isRejected()) {
|
if (!p.isFulfilled()) {
|
||||||
errors = errors.concat(p.reason());
|
errors = errors.concat(p.reason());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -170,15 +170,16 @@ validate = function validate(data) {
|
||||||
|
|
||||||
_.each(_.keys(data.data), function (tableName) {
|
_.each(_.keys(data.data), function (tableName) {
|
||||||
_.each(data.data[tableName], function (importValues) {
|
_.each(data.data[tableName], function (importValues) {
|
||||||
validateOps.push(validation.validateSchema(tableName, importValues));
|
validateOps.push(validation.
|
||||||
|
validateSchema(tableName, importValues).reflect());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.settle(validateOps).then(function (descriptors) {
|
return Promise.all(validateOps).then(function (descriptors) {
|
||||||
var errorList = [];
|
var errorList = [];
|
||||||
|
|
||||||
_.each(descriptors, function (d) {
|
_.each(descriptors, function (d) {
|
||||||
if (d.isRejected()) {
|
if (!d.isFulfilled()) {
|
||||||
errorList = errorList.concat(d.reason());
|
errorList = errorList.concat(d.reason());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -204,10 +204,10 @@ utils = {
|
||||||
}
|
}
|
||||||
|
|
||||||
return _tag;
|
return _tag;
|
||||||
}));
|
}).reflect());
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.settle(ops);
|
return Promise.all(ops);
|
||||||
},
|
},
|
||||||
|
|
||||||
importPosts: function importPosts(tableData, transaction) {
|
importPosts: function importPosts(tableData, transaction) {
|
||||||
|
@ -232,11 +232,11 @@ utils = {
|
||||||
ops.push(models.Post.add(post, _.extend({}, internal, {transacting: transaction, importing: true}))
|
ops.push(models.Post.add(post, _.extend({}, internal, {transacting: transaction, importing: true}))
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
return Promise.reject({raw: error, model: 'post', data: post});
|
return Promise.reject({raw: error, model: 'post', data: post});
|
||||||
})
|
}).reflect()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.settle(ops);
|
return Promise.all(ops);
|
||||||
},
|
},
|
||||||
|
|
||||||
importUsers: function importUsers(tableData, existingUsers, transaction) {
|
importUsers: function importUsers(tableData, existingUsers, transaction) {
|
||||||
|
@ -292,9 +292,9 @@ utils = {
|
||||||
if (!(error instanceof errors.NotFoundError)) {
|
if (!(error instanceof errors.NotFoundError)) {
|
||||||
return Promise.reject({raw: error, model: 'setting', data: tableData});
|
return Promise.reject({raw: error, model: 'setting', data: tableData});
|
||||||
}
|
}
|
||||||
}));
|
}).reflect());
|
||||||
|
|
||||||
return Promise.settle(ops);
|
return Promise.all(ops);
|
||||||
},
|
},
|
||||||
|
|
||||||
/** For later **/
|
/** For later **/
|
||||||
|
@ -317,10 +317,10 @@ utils = {
|
||||||
}
|
}
|
||||||
|
|
||||||
return _app;
|
return _app;
|
||||||
}));
|
}).reflect());
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.settle(ops);
|
return Promise.all(ops);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -53,39 +53,41 @@ function updateCheckError(error) {
|
||||||
|
|
||||||
function updateCheckData() {
|
function updateCheckData() {
|
||||||
var data = {},
|
var data = {},
|
||||||
ops = [],
|
|
||||||
mailConfig = config.mail;
|
mailConfig = config.mail;
|
||||||
|
|
||||||
ops.push(api.settings.read(_.extend({key: 'dbHash'}, internal)).catch(errors.rejectError));
|
|
||||||
ops.push(api.settings.read(_.extend({key: 'activeTheme'}, internal)).catch(errors.rejectError));
|
|
||||||
ops.push(api.settings.read(_.extend({key: 'activeApps'}, internal))
|
|
||||||
.then(function (response) {
|
|
||||||
var apps = response.settings[0];
|
|
||||||
try {
|
|
||||||
apps = JSON.parse(apps.value);
|
|
||||||
} catch (e) {
|
|
||||||
return errors.rejectError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return _.reduce(apps, function (memo, item) { return memo === '' ? memo + item : memo + ', ' + item; }, '');
|
|
||||||
}).catch(errors.rejectError));
|
|
||||||
ops.push(api.posts.browse().catch(errors.rejectError));
|
|
||||||
ops.push(api.users.browse(internal).catch(errors.rejectError));
|
|
||||||
ops.push(Promise.promisify(exec)('npm -v').catch(errors.rejectError));
|
|
||||||
|
|
||||||
data.ghost_version = currentVersion;
|
data.ghost_version = currentVersion;
|
||||||
data.node_version = process.versions.node;
|
data.node_version = process.versions.node;
|
||||||
data.env = process.env.NODE_ENV;
|
data.env = process.env.NODE_ENV;
|
||||||
data.database_type = config.database.client;
|
data.database_type = config.database.client;
|
||||||
data.email_transport = mailConfig && (mailConfig.options && mailConfig.options.service ? mailConfig.options.service : mailConfig.transport);
|
data.email_transport = mailConfig &&
|
||||||
|
(mailConfig.options && mailConfig.options.service ?
|
||||||
|
mailConfig.options.service :
|
||||||
|
mailConfig.transport);
|
||||||
|
|
||||||
return Promise.settle(ops).then(function (descriptors) {
|
return Promise.props({
|
||||||
var hash = descriptors[0].value().settings[0],
|
hash: api.settings.read(_.extend({key: 'dbHash'}, internal)).catch(errors.rejectError).reflect(),
|
||||||
theme = descriptors[1].value().settings[0],
|
theme: api.settings.read(_.extend({key: 'activeTheme'}, internal)).catch(errors.rejectError).reflect(),
|
||||||
apps = descriptors[2].value(),
|
apps: api.settings.read(_.extend({key: 'activeApps'}, internal))
|
||||||
posts = descriptors[3].value(),
|
.then(function (response) {
|
||||||
users = descriptors[4].value(),
|
var apps = response.settings[0];
|
||||||
npm = descriptors[5].value(),
|
try {
|
||||||
|
apps = JSON.parse(apps.value);
|
||||||
|
} catch (e) {
|
||||||
|
return errors.rejectError(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _.reduce(apps, function (memo, item) { return memo === '' ? memo + item : memo + ', ' + item; }, '');
|
||||||
|
}).catch(errors.rejectError).reflect(),
|
||||||
|
posts: api.posts.browse().catch(errors.rejectError).reflect(),
|
||||||
|
users: api.users.browse(internal).catch(errors.rejectError).reflect(),
|
||||||
|
npm: Promise.promisify(exec)('npm -v').catch(errors.rejectError).reflect()
|
||||||
|
}).then(function (descriptors) {
|
||||||
|
var hash = descriptors.hash.value().settings[0],
|
||||||
|
theme = descriptors.theme.value().settings[0],
|
||||||
|
apps = descriptors.apps.value(),
|
||||||
|
posts = descriptors.posts.value(),
|
||||||
|
users = descriptors.users.value(),
|
||||||
|
npm = descriptors.npm.value(),
|
||||||
blogUrl = url.parse(config.url),
|
blogUrl = url.parse(config.url),
|
||||||
blogId = blogUrl.hostname + blogUrl.pathname.replace(/\//, '') + hash.value;
|
blogId = blogUrl.hostname + blogUrl.pathname.replace(/\//, '') + hash.value;
|
||||||
|
|
||||||
|
@ -95,7 +97,7 @@ function updateCheckData() {
|
||||||
data.post_count = posts && posts.meta && posts.meta.pagination ? posts.meta.pagination.total : 0;
|
data.post_count = posts && posts.meta && posts.meta.pagination ? posts.meta.pagination.total : 0;
|
||||||
data.user_count = users && users.users && users.users.length ? users.users.length : 0;
|
data.user_count = users && users.users && users.users.length ? users.users.length : 0;
|
||||||
data.blog_created_at = users && users.users && users.users[0] && users.users[0].created_at ? moment(users.users[0].created_at).unix() : '';
|
data.blog_created_at = users && users.users && users.users[0] && users.users[0].created_at ? moment(users.users[0].created_at).unix() : '';
|
||||||
data.npm_version = _.isArray(npm) && npm[0] ? npm[0].toString().replace(/\n/, '') : '';
|
data.npm_version = npm.trim();
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}).catch(updateCheckError);
|
}).catch(updateCheckError);
|
||||||
|
@ -161,16 +163,16 @@ function updateCheckResponse(response) {
|
||||||
api.settings.edit(
|
api.settings.edit(
|
||||||
{settings: [{key: 'nextUpdateCheck', value: response.next_check}]},
|
{settings: [{key: 'nextUpdateCheck', value: response.next_check}]},
|
||||||
internal
|
internal
|
||||||
).catch(errors.rejectError),
|
).catch(errors.rejectError).reflect(),
|
||||||
api.settings.edit(
|
api.settings.edit(
|
||||||
{settings: [{key: 'displayUpdateNotification', value: response.version}]},
|
{settings: [{key: 'displayUpdateNotification', value: response.version}]},
|
||||||
internal
|
internal
|
||||||
).catch(errors.rejectError)
|
).catch(errors.rejectError).reflect()
|
||||||
);
|
);
|
||||||
|
|
||||||
return Promise.settle(ops).then(function then(descriptors) {
|
return Promise.map(ops).then(function then(descriptors) {
|
||||||
descriptors.forEach(function forEach(d) {
|
descriptors.forEach(function forEach(d) {
|
||||||
if (d.isRejected()) {
|
if (!d.isFulfilled()) {
|
||||||
errors.rejectError(d.reason());
|
errors.rejectError(d.reason());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -104,14 +104,14 @@ describe('Mail', function () {
|
||||||
it('should fail to send messages when given insufficient data', function (done) {
|
it('should fail to send messages when given insufficient data', function (done) {
|
||||||
mailer = new GhostMail();
|
mailer = new GhostMail();
|
||||||
|
|
||||||
Promise.settle([
|
Promise.all([
|
||||||
mailer.send(),
|
mailer.send().reflect(),
|
||||||
mailer.send({}),
|
mailer.send({}).reflect(),
|
||||||
mailer.send({subject: '123'}),
|
mailer.send({subject: '123'}).reflect(),
|
||||||
mailer.send({subject: '', html: '123'})
|
mailer.send({subject: '', html: '123'}).reflect()
|
||||||
]).then(function (descriptors) {
|
]).then(function (descriptors) {
|
||||||
descriptors.forEach(function (d) {
|
descriptors.forEach(function (d) {
|
||||||
d.isRejected().should.be.true();
|
d.isFulfilled().should.be.false();
|
||||||
d.reason().should.be.an.instanceOf(Error);
|
d.reason().should.be.an.instanceOf(Error);
|
||||||
d.reason().message.should.eql('Error: Incomplete message data.');
|
d.reason().message.should.eql('Error: Incomplete message data.');
|
||||||
});
|
});
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bcryptjs": "2.3.0",
|
"bcryptjs": "2.3.0",
|
||||||
"bluebird": "2.10.2",
|
"bluebird": "3.1.2",
|
||||||
"body-parser": "1.14.2",
|
"body-parser": "1.14.2",
|
||||||
"bookshelf": "0.9.1",
|
"bookshelf": "0.9.1",
|
||||||
"busboy": "0.2.12",
|
"busboy": "0.2.12",
|
||||||
|
|
Loading…
Add table
Reference in a new issue