0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Remove findAll from models that has findPage

closes #4577
- removed findAll from Post and User
- refactored deleteAllContent and data importer
This commit is contained in:
Delgermurun 2015-10-02 18:01:35 +08:00
parent f7015600b8
commit a501711e71
4 changed files with 10 additions and 38 deletions

View file

@ -23,13 +23,13 @@ DataImporter.prototype.loadRoles = function () {
DataImporter.prototype.loadUsers = function () {
var users = {all: {}},
options = _.extend({}, {include: ['roles']}, internal);
options = _.extend({}, {include: ['roles'], limit: 'all'}, internal);
return models.User.findAll(options).then(function (_users) {
_users.forEach(function (user) {
users.all[user.get('email')] = {realId: user.get('id')};
if (user.related('roles').toJSON(options)[0] && user.related('roles').toJSON(options)[0].name === 'Owner') {
users.owner = user.toJSON(options);
return models.User.findPage(options).then(function (data) {
data.users.forEach(function (user) {
users.all[user.email] = {realId: user.id};
if (user.roles[0] && user.roles[0].name === 'Owner') {
users.owner = user;
}
});

View file

@ -44,13 +44,13 @@ models = {
deleteAllContent: function deleteAllContent() {
var self = this;
return self.Post.findAll().then(function then(posts) {
return Promise.all(_.map(posts.toJSON(), function mapper(post) {
return self.Post.findPage({limit: 'all'}).then(function then(data) {
return Promise.all(_.map(data.posts, function mapper(post) {
return self.Post.destroy({id: post.id});
}));
}).then(function () {
return self.Tag.findAll().then(function then(tags) {
return Promise.all(_.map(tags.toJSON(), function mapper(tag) {
return self.Tag.findPage({limit: 'all'}).then(function then(data) {
return Promise.all(_.map(data.tags, function mapper(tag) {
return self.Tag.destroy({id: tag.id});
}));
});

View file

@ -399,7 +399,6 @@ Post = ghostBookshelf.Model.extend({
// whitelists for the `options` hash argument on methods, by method name.
// these are the only options that can be passed to Bookshelf / Knex.
validOptions = {
findAll: ['withRelated'],
findOne: ['importing', 'withRelated'],
findPage: ['page', 'limit', 'columns', 'status', 'staticPages', 'featured'],
add: ['importing']
@ -431,20 +430,6 @@ Post = ghostBookshelf.Model.extend({
// ## Model Data Functions
/**
* ### Find All
*
* @param {Object} options
* @returns {*}
*/
findAll: function findAll(options) {
options = options || {};
// fetch relations passed to options.include
options.withRelated = _.union(options.withRelated, options.include);
return ghostBookshelf.Model.findAll.call(this, options);
},
/**
* ### Find One
* @extends ghostBookshelf.Model.findOne to handle post status

View file

@ -228,7 +228,6 @@ User = ghostBookshelf.Model.extend({
// these are the only options that can be passed to Bookshelf / Knex.
validOptions = {
findOne: ['withRelated', 'status'],
findAll: ['withRelated'],
setup: ['id'],
edit: ['withRelated', 'id'],
findPage: ['page', 'limit', 'columns', 'status']
@ -241,18 +240,6 @@ User = ghostBookshelf.Model.extend({
return options;
},
/**
* ### Find All
*
* @param {Object} options
* @returns {*}
*/
findAll: function findAll(options) {
options = options || {};
options.withRelated = _.union(options.withRelated, options.include);
return ghostBookshelf.Model.findAll.call(this, options);
},
/**
* ### Find One
* @extends ghostBookshelf.Model.findOne to include roles