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:
parent
7959aeed55
commit
744e5e57a0
1 changed files with 60 additions and 0 deletions
|
@ -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() {}
|
||||
);
|
Loading…
Reference in a new issue