mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-17 13:31:39 +03:00
be37070fb6
migration from usage of config() to just an object of config. no relevant issue - Change 'loadConfig' task to 'ensureConfig' to more accurately reflect what it is actually doing. Its sole purpose is to make sure a `config.js` file exists, and as such the name now reflects that purpose. - Update config/index.js to export the ghostConfig object directly so that it can be accessed from other modules - Update all references of config(). to config. This was a blind global find all and replace, treat it as such. - Fixes to tests to support new config access method - Allow each test to still work when invoked invidually
64 lines
2.0 KiB
JavaScript
64 lines
2.0 KiB
JavaScript
var _ = require('lodash'),
|
|
when = require('when'),
|
|
|
|
versioning = require('../versioning'),
|
|
config = require('../../config'),
|
|
utils = require('../utils'),
|
|
serverUtils = require('../../utils'),
|
|
errors = require('../../errors'),
|
|
settings = require('../../api/settings'),
|
|
|
|
excludedTables = ['accesstokens', 'refreshtokens', 'clients'],
|
|
exporter,
|
|
exportFileName;
|
|
|
|
exportFileName = function () {
|
|
var datetime = (new Date()).toJSON().substring(0, 10),
|
|
title = '';
|
|
|
|
return settings.read({key: 'title', context: {internal: true}}).then(function (result) {
|
|
if (result) {
|
|
title = serverUtils.safeString(result.settings[0].value) + '.';
|
|
}
|
|
return title + 'ghost.' + datetime + '.json';
|
|
}).catch(function (err) {
|
|
errors.logError(err);
|
|
return 'ghost.' + datetime + '.json';
|
|
});
|
|
};
|
|
|
|
exporter = function () {
|
|
return when.join(versioning.getDatabaseVersion(), utils.getTables()).then(function (results) {
|
|
var version = results[0],
|
|
tables = results[1],
|
|
selectOps = _.map(tables, function (name) {
|
|
if (excludedTables.indexOf(name) < 0) {
|
|
return config.database.knex(name).select();
|
|
}
|
|
});
|
|
|
|
return when.all(selectOps).then(function (tableData) {
|
|
var exportData = {
|
|
meta: {
|
|
exported_on: new Date().getTime(),
|
|
version: version
|
|
},
|
|
data: {
|
|
// Filled below
|
|
}
|
|
};
|
|
|
|
_.each(tables, function (name, i) {
|
|
exportData.data[name] = tableData[i];
|
|
});
|
|
|
|
return when.resolve(exportData);
|
|
}).catch(function (err) {
|
|
errors.logAndThrowError(err, 'Error exporting data', '');
|
|
});
|
|
});
|
|
};
|
|
|
|
module.exports = exporter;
|
|
module.exports.fileName = exportFileName;
|