Added migration to update Default Tier name

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

This ensures that we set the default tier's name to the title of the
site - which looks a lot better than "Default Product".
This commit is contained in:
Fabien "egg" O'Carroll 2022-02-01 13:15:04 +02:00
parent 594df729e1
commit 8915d15a1d

View File

@ -31,6 +31,7 @@ module.exports = class StripeMigrations {
await this.populateDefaultProductYearlyPriceId(); await this.populateDefaultProductYearlyPriceId();
await this.revertPortalPlansSetting(); await this.revertPortalPlansSetting();
await this.removeInvalidSubscriptions(); await this.removeInvalidSubscriptions();
await this.setDefaultProductName();
} }
async populateProductsAndPrices(options) { async populateProductsAndPrices(options) {
@ -543,4 +544,32 @@ module.exports = class StripeMigrations {
logging.info(`No invalid subscriptions, skipping migration`); logging.info(`No invalid subscriptions, skipping migration`);
} }
} }
async setDefaultProductName(options) {
if (!options) {
return this.models.Product.transaction((transacting) => {
return this.setDefaultProductName({transacting});
});
}
const {data} = await this.models.Product.findPage({
...options,
limit: 1,
filter: 'type:paid'
});
const defaultProduct = data[0] && data[0].toJSON();
if (defaultProduct && defaultProduct.name === 'Default Product') {
const siteTitle = await this.models.Settings.findOne({key: 'title'}, options);
if (siteTitle) {
await this.models.Product.edit({
name: siteTitle.get('value')
}, {
...options,
id: defaultProduct.id
});
}
}
}
}; };