mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
parent
ca16b197a2
commit
a2f7160499
1 changed files with 59 additions and 56 deletions
|
@ -13,6 +13,7 @@ module.exports.config = {
|
||||||
|
|
||||||
const backupFileRegex = /ghost.([\d]{4}-[\d]{2}-[\d]{2}).json$/;
|
const backupFileRegex = /ghost.([\d]{4}-[\d]{2}-[\d]{2}).json$/;
|
||||||
|
|
||||||
|
// @NOTE: spagetthi
|
||||||
module.exports.up = (options) => {
|
module.exports.up = (options) => {
|
||||||
const contentPath = config.get('paths').contentPath;
|
const contentPath = config.get('paths').contentPath;
|
||||||
const dataPath = path.join(contentPath, 'data');
|
const dataPath = path.join(contentPath, 'data');
|
||||||
|
@ -53,79 +54,81 @@ module.exports.up = (options) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const settings = backup && backup.data && backup.data.settings;
|
const settings = backup && backup.data && backup.data.settings;
|
||||||
const migrations = backup && backup.data && backup.data.migrations;
|
|
||||||
|
|
||||||
if (!settings) {
|
if (!settings) {
|
||||||
common.logging.warn('Could not read settings from backup file, skipping...');
|
common.logging.warn('Could not read settings from backup file, skipping...');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!migrations || !migrations.length) {
|
|
||||||
common.logging.warn('Skipping migration. Not affected.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: If we you have a backup file which has 2.16, but not 2.17, you are affected
|
|
||||||
// NOTE: We have corrected 2.17. If you jump form 2.16 to 2.18, you are good
|
|
||||||
const isAffected = _.find(migrations, {version: '2.16'}) &&
|
|
||||||
!_.find(migrations, {version: '2.17'});
|
|
||||||
|
|
||||||
if (!isAffected) {
|
|
||||||
common.logging.warn('Skipping migration. Not affected.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
common.logging.warn('...is affected.');
|
|
||||||
|
|
||||||
const relevantBackupSettings = settings.filter(function (entry) {
|
|
||||||
return ['is_private', 'force_i18n', 'amp'].includes(entry.key);
|
|
||||||
}).reduce(function (obj, entry) {
|
|
||||||
return Object.assign(obj, {
|
|
||||||
[entry.key]: entry
|
|
||||||
});
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
return localOptions
|
return localOptions
|
||||||
.transacting('settings')
|
.transacting('migrations')
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (!response) {
|
if (!response) {
|
||||||
common.logging.warn('Cannot find settings.');
|
common.logging.warn('Cannot find migrations.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const relevantLiveSettings = response.filter(function (entry) {
|
// NOTE: You are only affected if you migrated to 2.17
|
||||||
|
// 2.18 fixed the 2.17 migration (!)
|
||||||
|
const isAffected = _.find(response, {currentVersion: '2.17', version: '2.17'});
|
||||||
|
|
||||||
|
if (!isAffected) {
|
||||||
|
common.logging.warn('Skipping migration. Not affected.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
common.logging.warn('...is affected.');
|
||||||
|
|
||||||
|
const relevantBackupSettings = settings.filter(function (entry) {
|
||||||
return ['is_private', 'force_i18n', 'amp'].includes(entry.key);
|
return ['is_private', 'force_i18n', 'amp'].includes(entry.key);
|
||||||
});
|
}).reduce(function (obj, entry) {
|
||||||
|
return Object.assign(obj, {
|
||||||
|
[entry.key]: entry
|
||||||
|
});
|
||||||
|
}, {});
|
||||||
|
|
||||||
return Promise.each(relevantLiveSettings, (liveSetting) => {
|
return localOptions
|
||||||
const backupSetting = relevantBackupSettings[liveSetting.key];
|
.transacting('settings')
|
||||||
|
.then((response) => {
|
||||||
|
if (!response) {
|
||||||
|
common.logging.warn('Cannot find settings.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (liveSetting.value === 'false' && backupSetting.value === 'true') {
|
const relevantLiveSettings = response.filter(function (entry) {
|
||||||
common.logging.info(`Reverting setting ${liveSetting.key}`);
|
return ['is_private', 'force_i18n', 'amp'].includes(entry.key);
|
||||||
|
});
|
||||||
|
|
||||||
return localOptions
|
return Promise.each(relevantLiveSettings, (liveSetting) => {
|
||||||
.transacting('settings')
|
const backupSetting = relevantBackupSettings[liveSetting.key];
|
||||||
.where('key', liveSetting.key)
|
|
||||||
.update({
|
|
||||||
value: backupSetting.value
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// CASE: we have to update settings cache, because Ghost is able to run migrations on the same process
|
|
||||||
settingsCache.set(liveSetting.key, {
|
|
||||||
id: liveSetting.id,
|
|
||||||
key: liveSetting.key,
|
|
||||||
type: liveSetting.type,
|
|
||||||
created_at: moment(liveSetting.created_at).startOf('seconds').toDate(),
|
|
||||||
updated_at: moment().startOf('seconds').toDate(),
|
|
||||||
updated_by: liveSetting.updated_by,
|
|
||||||
created_by: liveSetting.created_by,
|
|
||||||
value: backupSetting.value === 'true'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.resolve();
|
if (liveSetting.value === 'false' && backupSetting.value === 'true') {
|
||||||
});
|
common.logging.info(`Reverting setting ${liveSetting.key}`);
|
||||||
|
|
||||||
|
return localOptions
|
||||||
|
.transacting('settings')
|
||||||
|
.where('key', liveSetting.key)
|
||||||
|
.update({
|
||||||
|
value: backupSetting.value
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
// CASE: we have to update settings cache, because Ghost is able to run migrations on the same process
|
||||||
|
settingsCache.set(liveSetting.key, {
|
||||||
|
id: liveSetting.id,
|
||||||
|
key: liveSetting.key,
|
||||||
|
type: liveSetting.type,
|
||||||
|
created_at: moment(liveSetting.created_at).startOf('seconds').toDate(),
|
||||||
|
updated_at: moment().startOf('seconds').toDate(),
|
||||||
|
updated_by: liveSetting.updated_by,
|
||||||
|
created_by: liveSetting.created_by,
|
||||||
|
value: backupSetting.value === 'true'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue