mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-02 07:43:11 +03:00
🐛 export database read settings from database (#8103)
* 🐛 export database read settings from database
no issue
- the backup script uses the export database lib and is broken if knex-migrator is called via shell, the settings cache is not loaded
- i have changed the export database lib to read the settings key directly from the db
* use get('value')
This commit is contained in:
parent
9aec9c6a63
commit
27e659a21e
@ -6,7 +6,7 @@ var _ = require('lodash'),
|
||||
ghostVersion = require('../../utils/ghost-version'),
|
||||
errors = require('../../errors'),
|
||||
logging = require('../../logging'),
|
||||
settings = require('../../api/settings'),
|
||||
models = require('../../models'),
|
||||
i18n = require('../../i18n'),
|
||||
excludedTables = ['accesstokens', 'refreshtokens', 'clients', 'client_trusted_domains'],
|
||||
modelOptions = {context: {internal: true}},
|
||||
@ -23,10 +23,11 @@ exportFileName = function exportFileName() {
|
||||
var datetime = (new Date()).toJSON().substring(0, 10),
|
||||
title = '';
|
||||
|
||||
return settings.read(_.extend({}, {key: 'title'}, modelOptions)).then(function (result) {
|
||||
return models.Settings.findOne(_.merge({key: 'title'}, modelOptions)).then(function (result) {
|
||||
if (result) {
|
||||
title = serverUtils.safeString(result.settings[0].value) + '.';
|
||||
title = serverUtils.safeString(result.get('value')) + '.';
|
||||
}
|
||||
|
||||
return title + 'ghost.' + datetime + '.json';
|
||||
}).catch(function (err) {
|
||||
logging.error(new errors.GhostError({err: err}));
|
||||
|
@ -1,18 +1,22 @@
|
||||
var should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
rewire = require('rewire'),
|
||||
Promise = require('bluebird'),
|
||||
db = require('../../server/data/db'),
|
||||
errors = require('../../server/errors'),
|
||||
exporter = rewire('../../server/data/export'),
|
||||
schema = require('../../server/data/schema'),
|
||||
settings = require('../../server/api/settings'),
|
||||
var should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
rewire = require('rewire'),
|
||||
Promise = require('bluebird'),
|
||||
db = require('../../server/data/db'),
|
||||
errors = require('../../server/errors'),
|
||||
exporter = rewire('../../server/data/export'),
|
||||
schema = require('../../server/data/schema'),
|
||||
models = require('../../server/models'),
|
||||
schemaTables = Object.keys(schema.tables),
|
||||
sandbox = sinon.sandbox.create();
|
||||
|
||||
describe('Exporter', function () {
|
||||
var tablesStub, queryMock, knexMock, knexStub;
|
||||
|
||||
before(function () {
|
||||
models.init();
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
sandbox.restore();
|
||||
knexStub.restore();
|
||||
@ -33,7 +37,11 @@ describe('Exporter', function () {
|
||||
knexMock = sandbox.stub().returns(queryMock);
|
||||
|
||||
// this MUST use sinon, not sandbox, see sinonjs/sinon#781
|
||||
knexStub = sinon.stub(db, 'knex', {get: function () { return knexMock; }});
|
||||
knexStub = sinon.stub(db, 'knex', {
|
||||
get: function () {
|
||||
return knexMock;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should try to export all the correct tables', function (done) {
|
||||
@ -99,8 +107,12 @@ describe('Exporter', function () {
|
||||
|
||||
describe('exportFileName', function () {
|
||||
it('should return a correctly structured filename', function (done) {
|
||||
var settingsStub = sandbox.stub(settings, 'read').returns(
|
||||
new Promise.resolve({settings: [{value: 'testblog'}]})
|
||||
var settingsStub = sandbox.stub(models.Settings, 'findOne').returns(
|
||||
new Promise.resolve({
|
||||
get: function () {
|
||||
return 'testblog';
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
exporter.fileName().then(function (result) {
|
||||
@ -113,7 +125,7 @@ describe('Exporter', function () {
|
||||
});
|
||||
|
||||
it('should return a correctly structured filename if settings is empty', function (done) {
|
||||
var settingsStub = sandbox.stub(settings, 'read').returns(
|
||||
var settingsStub = sandbox.stub(models.Settings, 'findOne').returns(
|
||||
new Promise.resolve()
|
||||
);
|
||||
|
||||
@ -127,7 +139,7 @@ describe('Exporter', function () {
|
||||
});
|
||||
|
||||
it('should return a correctly structured filename if settings errors', function (done) {
|
||||
var settingsStub = sandbox.stub(settings, 'read').returns(
|
||||
var settingsStub = sandbox.stub(models.Settings, 'findOne').returns(
|
||||
new Promise.reject()
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user