mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-30 06:12:03 +03:00
a5ab2ffc13
no issue 🔥 Remove unnecessary cache update 🎨 simplify updateSettingsCache() 🎨 Simplify readSettingsResult - although this is more code, it's now much clearer what happens in the two cases 🎨 Don't use readSettingResult for edit 🎨 Simplify updateSettingsCache further 🔥 Remove now unused readSettingsResult 🎨 Change populateDefault to return all 🎨 Move the findAll call out of updateSettingsCache 🔥 Remove updateSettingsCache!! 🎨 Restructure init & finish up settingsCache - move initialisation into settingsCache.init AT LAST - change settingCache to use cloneDeep, so that the object can't be modified outside of the functions - add lots of docs to settings cache 🎨 Cleanup db api endpoints 🔥 Don't populate settings in migrations
113 lines
3.0 KiB
JavaScript
113 lines
3.0 KiB
JavaScript
// # DB API
|
|
// API for DB operations
|
|
var Promise = require('bluebird'),
|
|
exporter = require('../data/export'),
|
|
importer = require('../data/importer'),
|
|
backupDatabase = require('../data/db/backup'),
|
|
models = require('../models'),
|
|
errors = require('../errors'),
|
|
utils = require('./utils'),
|
|
pipeline = require('../utils/pipeline'),
|
|
docName = 'db',
|
|
db;
|
|
|
|
/**
|
|
* ## DB API Methods
|
|
*
|
|
* **See:** [API Methods](index.js.html#api%20methods)
|
|
*/
|
|
db = {
|
|
/**
|
|
* ### Export Content
|
|
* Generate the JSON to export
|
|
*
|
|
* @public
|
|
* @param {{context}} options
|
|
* @returns {Promise} Ghost Export JSON format
|
|
*/
|
|
exportContent: function exportContent(options) {
|
|
var tasks;
|
|
|
|
options = options || {};
|
|
|
|
// Export data, otherwise send error 500
|
|
function exportContent() {
|
|
return exporter.doExport().then(function (exportedData) {
|
|
return {db: [exportedData]};
|
|
}).catch(function (err) {
|
|
return Promise.reject(new errors.GhostError({err: err}));
|
|
});
|
|
}
|
|
|
|
tasks = [
|
|
utils.handlePermissions(docName, 'exportContent'),
|
|
exportContent
|
|
];
|
|
|
|
return pipeline(tasks, options);
|
|
},
|
|
/**
|
|
* ### Import Content
|
|
* Import posts, tags etc from a JSON blob
|
|
*
|
|
* @public
|
|
* @param {{context}} options
|
|
* @returns {Promise} Success
|
|
*/
|
|
importContent: function importContent(options) {
|
|
var tasks;
|
|
options = options || {};
|
|
|
|
function importContent(options) {
|
|
return importer.importFromFile(options)
|
|
.return({db: []});
|
|
}
|
|
|
|
tasks = [
|
|
utils.handlePermissions(docName, 'importContent'),
|
|
importContent
|
|
];
|
|
|
|
return pipeline(tasks, options);
|
|
},
|
|
/**
|
|
* ### Delete All Content
|
|
* Remove all posts and tags
|
|
*
|
|
* @public
|
|
* @param {{context}} options
|
|
* @returns {Promise} Success
|
|
*/
|
|
deleteAllContent: function deleteAllContent(options) {
|
|
var tasks,
|
|
queryOpts = {columns: 'id', context: {internal: true}};
|
|
|
|
options = options || {};
|
|
|
|
function deleteContent() {
|
|
var collections = [
|
|
models.Subscriber.findAll(queryOpts),
|
|
models.Post.findAll(queryOpts),
|
|
models.Tag.findAll(queryOpts)
|
|
];
|
|
|
|
return Promise.each(collections, function then(Collection) {
|
|
return Collection.invokeThen('destroy');
|
|
}).return({db: []})
|
|
.catch(function (err) {
|
|
throw new errors.GhostError({err: err});
|
|
});
|
|
}
|
|
|
|
tasks = [
|
|
utils.handlePermissions(docName, 'deleteAllContent'),
|
|
backupDatabase,
|
|
deleteContent
|
|
];
|
|
|
|
return pipeline(tasks, options);
|
|
}
|
|
};
|
|
|
|
module.exports = db;
|