mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Cleaned up broken complimentary plan (#11650)
refs https://github.com/TryGhost/Ghost/issues/11648
- Removes Stripe plan entries from settings that are not formatted correctly.
- Incorrect formatting was caused by a bug in 3.10.0 Admin-Client where it wasn't able to find complimentary plan. Related fix for this here - 9e7a6b801a
This commit is contained in:
parent
70076f8c19
commit
df056416bd
1 changed files with 68 additions and 0 deletions
|
@ -0,0 +1,68 @@
|
|||
const _ = require('lodash');
|
||||
const Promise = require('bluebird');
|
||||
const common = require('../../../../lib/common');
|
||||
const debug = require('ghost-ignition').debug('migrations');
|
||||
|
||||
module.exports.config = {
|
||||
transaction: true
|
||||
};
|
||||
|
||||
module.exports.up = (options) => {
|
||||
let localOptions = _.merge({
|
||||
context: {internal: true}
|
||||
}, options);
|
||||
const settingsKey = 'members_subscription_settings';
|
||||
|
||||
return localOptions
|
||||
.transacting('settings')
|
||||
.then((response) => {
|
||||
if (!response) {
|
||||
common.logging.warn('Cannot find settings.');
|
||||
return;
|
||||
}
|
||||
|
||||
let subscriptionSettingsEntry = response.find((entry) => {
|
||||
return entry.key === settingsKey;
|
||||
});
|
||||
|
||||
if (!subscriptionSettingsEntry) {
|
||||
common.logging.warn('Cannot find members subscription settings.');
|
||||
return;
|
||||
}
|
||||
|
||||
let subscriptionSettings = JSON.parse(subscriptionSettingsEntry.value);
|
||||
|
||||
debug('before cleanup');
|
||||
debug(JSON.stringify(subscriptionSettings, null, 2));
|
||||
|
||||
const stripePaymentProcessor = subscriptionSettings.paymentProcessors.find(
|
||||
paymentProcessor => paymentProcessor.adapter === 'stripe'
|
||||
);
|
||||
|
||||
// Remove "broken" complimentary plans that were introduced with 3.10.0, they didn't have
|
||||
// interval property defined unlike regular plans
|
||||
if (stripePaymentProcessor && stripePaymentProcessor.config.public_token && stripePaymentProcessor.config.secret_token) {
|
||||
stripePaymentProcessor.config.plans = stripePaymentProcessor.config.plans.filter((plan) => {
|
||||
return plan.interval !== undefined;
|
||||
});
|
||||
}
|
||||
|
||||
debug('after cleanup');
|
||||
debug(JSON.stringify(subscriptionSettings, null, 2));
|
||||
|
||||
return localOptions
|
||||
.transacting('settings')
|
||||
.where('key', settingsKey)
|
||||
.update({
|
||||
value: JSON.stringify(subscriptionSettings)
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// `up` is only run to fix a problem that is introduced with 3.10.0,
|
||||
// it doesn't make sense to "reintroduced" broken state with down migration
|
||||
module.exports.down = () => Promise.resolve();
|
||||
|
||||
module.exports.config = {
|
||||
transaction: true
|
||||
};
|
Loading…
Add table
Reference in a new issue