0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Fixed missing portal product data (#14115)

closes  https://github.com/TryGhost/Team/issues/1311

For some sites, the `portal_products` array was created without any value and due to a possible bug in older version of Ghost, it also didn't get filled on Stripe connect with default product. This causes a side-effect of sites not showing the prices in Portal when tiers beta is enabled or is out as GA. This change populates the missing product data in `portal_product` for sites that have a single tier (haven't enabled tiers beta), as they right now don't have an option to hide the tier.
This commit is contained in:
Rishabh Garg 2022-02-04 19:57:38 +05:30 committed by GitHub
parent 7959aeed55
commit 744e5e57a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,60 @@
const {createTransactionalMigration} = require('../../utils');
const logging = require('@tryghost/logging');
module.exports = createTransactionalMigration(
async function up(knex) {
const products = await knex
.select('id')
.where({
type: 'paid'
})
.from('products');
if (products.length === 0) {
logging.warn(`Skipping updating portal_products, no product exists`);
return;
}
if (products.length > 1) {
logging.warn(`Skipping updating portal_products, tiers beta is enabled`);
return;
}
const portalProductsSetting = await knex('settings')
.where('key', 'portal_products')
.select('value')
.first();
if (!portalProductsSetting) {
logging.warn(`Missing portal_products setting`);
return;
}
try {
const currPortalProductsValue = JSON.parse(portalProductsSetting.value);
if (currPortalProductsValue.length > 0) {
logging.warn(`Ignoring - portal_products setting is not empty, - ${currPortalProductsValue}`);
return;
}
const defaultProduct = products[0];
const portalProductsValue = [defaultProduct.id];
logging.info(`Setting portal_products setting to have product - ${defaultProduct.id}`);
const now = knex.raw('CURRENT_TIMESTAMP');
await knex('settings')
.where('key', 'portal_products')
.update({
value: JSON.stringify(portalProductsValue),
updated_at: now
});
} catch (e) {
logging.warn(`Ignoring, unable to parse portal_products setting value - ${portalProductsSetting.value}`);
logging.warn(e);
}
},
// no-op - we don't want to return to invalid state
async function down() {}
);