mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Cleaned up members isPaid
flag in settings table (#11651)
no issue - The flag has not been used and can be removed, to make the `members_subscription_settings` JSON record in `settings` table easier to read. - It used to indicate Stripe configuration being present. Currently that is checked by looking up if Stripe config's `public_token` and `secret_token` values are present (example - https://github.com/TryGhost/Ghost/blob/3.11.0/core/frontend/helpers/ghost_head.js#L54)
This commit is contained in:
parent
531ef01c48
commit
6a9b53fcad
2 changed files with 94 additions and 1 deletions
|
@ -0,0 +1,93 @@
|
||||||
|
const common = require('../../../../lib/common');
|
||||||
|
const debug = require('ghost-ignition').debug('migrations');
|
||||||
|
|
||||||
|
module.exports.config = {
|
||||||
|
transaction: true
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.up = (options) => {
|
||||||
|
const settingsKey = 'members_subscription_settings';
|
||||||
|
|
||||||
|
return options
|
||||||
|
.transacting('settings')
|
||||||
|
.where('key', settingsKey)
|
||||||
|
.select('value')
|
||||||
|
.first()
|
||||||
|
.then((subscriptionSettingsEntry) => {
|
||||||
|
debug(subscriptionSettingsEntry);
|
||||||
|
if (!subscriptionSettingsEntry) {
|
||||||
|
common.logging.warn(`Cannot find ${settingsKey} settings.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let subscriptionSettings = JSON.parse(subscriptionSettingsEntry.value);
|
||||||
|
|
||||||
|
debug('before cleanup');
|
||||||
|
debug(JSON.stringify(subscriptionSettings, null, 2));
|
||||||
|
|
||||||
|
const hasIsPaid = Object.prototype.hasOwnProperty.call(subscriptionSettings, 'isPaid');
|
||||||
|
|
||||||
|
if (hasIsPaid) {
|
||||||
|
debug('Removing legacy isPaid flag from members settings');
|
||||||
|
delete subscriptionSettings.isPaid;
|
||||||
|
|
||||||
|
debug('after cleanup');
|
||||||
|
debug(JSON.stringify(subscriptionSettings, null, 2));
|
||||||
|
|
||||||
|
return options
|
||||||
|
.transacting('settings')
|
||||||
|
.where('key', settingsKey)
|
||||||
|
.update({
|
||||||
|
value: JSON.stringify(subscriptionSettings)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.down = (options) => {
|
||||||
|
const settingsKey = 'members_subscription_settings';
|
||||||
|
|
||||||
|
return options
|
||||||
|
.transacting('settings')
|
||||||
|
.where('key', settingsKey)
|
||||||
|
.select('value')
|
||||||
|
.first()
|
||||||
|
.then((subscriptionSettingsEntry) => {
|
||||||
|
debug(subscriptionSettingsEntry);
|
||||||
|
if (!subscriptionSettingsEntry) {
|
||||||
|
common.logging.warn(`Cannot find ${settingsKey} settings.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let subscriptionSettings = JSON.parse(subscriptionSettingsEntry.value);
|
||||||
|
|
||||||
|
debug('before cleanup');
|
||||||
|
debug(JSON.stringify(subscriptionSettings, null, 2));
|
||||||
|
|
||||||
|
let isPaid = false;
|
||||||
|
|
||||||
|
const stripePaymentProcessor = subscriptionSettings.paymentProcessors.find(
|
||||||
|
paymentProcessor => paymentProcessor.adapter === 'stripe'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (stripePaymentProcessor && stripePaymentProcessor.config.public_token && stripePaymentProcessor.config.secret_token) {
|
||||||
|
isPaid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
subscriptionSettings.isPaid = isPaid;
|
||||||
|
|
||||||
|
debug('after cleanup');
|
||||||
|
debug(JSON.stringify(subscriptionSettings, null, 2));
|
||||||
|
|
||||||
|
return options
|
||||||
|
.transacting('settings')
|
||||||
|
.where('key', settingsKey)
|
||||||
|
.update({
|
||||||
|
value: JSON.stringify(subscriptionSettings)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.config = {
|
||||||
|
transaction: true
|
||||||
|
};
|
|
@ -207,7 +207,7 @@
|
||||||
"defaultValue": "public"
|
"defaultValue": "public"
|
||||||
},
|
},
|
||||||
"members_subscription_settings": {
|
"members_subscription_settings": {
|
||||||
"defaultValue": "{\"isPaid\":false,\"fromAddress\":\"noreply\",\"allowSelfSignup\":true,\"paymentProcessors\":[{\"adapter\":\"stripe\",\"config\":{\"secret_token\":\"\",\"public_token\":\"\",\"product\":{\"name\":\"Ghost Subscription\"},\"plans\":[{\"name\":\"Monthly\",\"currency\":\"usd\",\"interval\":\"month\",\"amount\":\"\"},{\"name\":\"Yearly\",\"currency\":\"usd\",\"interval\":\"year\",\"amount\":\"\"}]}}]}"
|
"defaultValue": "{\"fromAddress\":\"noreply\",\"allowSelfSignup\":true,\"paymentProcessors\":[{\"adapter\":\"stripe\",\"config\":{\"secret_token\":\"\",\"public_token\":\"\",\"product\":{\"name\":\"Ghost Subscription\"},\"plans\":[{\"name\":\"Monthly\",\"currency\":\"usd\",\"interval\":\"month\",\"amount\":\"\"},{\"name\":\"Yearly\",\"currency\":\"usd\",\"interval\":\"year\",\"amount\":\"\"}]}}]}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bulk_email": {
|
"bulk_email": {
|
||||||
|
|
Loading…
Add table
Reference in a new issue