0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Synced Tiers welcome_page_urls with Settings

refs https://github.com/TryGhost/Team/issues/1168

Because Tiers is still behind a flag - any users which are not using
Tiers will still be editing their settings, and when they switch to
Tiers - the redirects will not necessarily be correct, unless we keep
the Tier columns up to date with any settings changes.
This commit is contained in:
Fabien "egg" O'Carroll 2022-01-30 17:05:09 +02:00 committed by Fabien 'egg' O'Carroll
parent 0e866aaa1e
commit 3d9e4b4c6c

View file

@ -16,6 +16,7 @@ const models = require('../../models');
const {GhostMailer} = require('../mail');
const jobsService = require('../jobs');
const VerificationTrigger = require('@tryghost/verification-trigger');
const events = require('../../lib/common/events');
const messages = {
noLiveKeysInDevelopment: 'Cannot use live stripe keys in development. Please restart in production mode.',
@ -76,6 +77,32 @@ module.exports = {
const createMembersApiInstance = require('./api');
const env = config.get('env');
events.on('settings.edited', async function (settingModel) {
if (labsService.isSet('multipleProducts')) {
return;
}
const key = settingModel.get('key');
const value = settingModel.get('value');
if (key === 'members_free_signup_redirect') {
try {
await models.Product.forge().query().update('welcome_page_url', value).where('type', 'free');
} catch (err) {
logging.error(err);
}
return;
}
if (key === 'members_paid_signup_redirect') {
try {
await models.Product.forge().query().update('welcome_page_url', value).where('type', 'paid');
} catch (err) {
logging.error(err);
}
return;
}
});
// @TODO Move to stripe service
if (env !== 'production') {
if (stripeService.api.configured && stripeService.api.mode === 'live') {