From 008f86fc2973b97a3d60a40534efcb875edec7fa Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Fri, 12 Jun 2020 18:05:57 +0100 Subject: [PATCH] Added `?force_rerender=true` param to posts edit endpoint no issue - there are various situations where we adapt/fix/improve our mobiledoc->html output over time but we didn't have a way of updating old content without manually editing the mobiledoc and saving, or running an expensive migration to re-render all old content - this adds a `?force_rerender=true` query param to the `PUT .../admin/posts/:id/` endpoint that allows the `html` field to be re-generated without modifying the `mobiledoc` field contents --- core/server/api/canary/posts.js | 1 + core/server/models/post.js | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/server/api/canary/posts.js b/core/server/api/canary/posts.js index 245c9729cb..7b77986171 100644 --- a/core/server/api/canary/posts.js +++ b/core/server/api/canary/posts.js @@ -126,6 +126,7 @@ module.exports = { 'id', 'source', 'send_email_when_published', + 'force_rerender', // NOTE: only for internal context 'forUpdate', 'transacting' diff --git a/core/server/models/post.js b/core/server/models/post.js index db17666c4b..c8e0f42865 100644 --- a/core/server/models/post.js +++ b/core/server/models/post.js @@ -405,8 +405,13 @@ Post = ghostBookshelf.Model.extend({ }); // CASE: mobiledoc has changed, generate html + // CASE: ?force_rerender=true passed via Admin API // CASE: html is null, but mobiledoc exists (only important for migrations & importing) - if (this.hasChanged('mobiledoc') || (!this.get('html') && (options.migrating || options.importing))) { + if ( + this.hasChanged('mobiledoc') + || options.force_rerender + || (!this.get('html') && (options.migrating || options.importing)) + ) { try { this.set('html', mobiledocLib.mobiledocHtmlRenderer.render(JSON.parse(this.get('mobiledoc')))); } catch (err) { @@ -781,7 +786,7 @@ Post = ghostBookshelf.Model.extend({ findPage: ['status'], findAll: ['columns', 'filter'], destroy: ['destroyAll', 'destroyBy'], - edit: ['filter', 'send_email_when_published'] + edit: ['filter', 'send_email_when_published', 'force_rerender'] }; // The post model additionally supports having a formats option