🐛 Reactivate theme on override + cache clear (#7368)

closes #7350

- When the active theme is overridden, ensure that the activateTheme middleware gets called by removing the `req.app.activeTheme` value.
- Additionally, ensure that the full cache is invalidated
This commit is contained in:
Hannah Wolfe 2016-09-14 11:18:52 +01:00 committed by Katharina Irrgang
parent 98a17d5116
commit 4287e0e78b

View File

@ -43,6 +43,10 @@ init = function init() {
return settings.updateSettingsCache();
};
function isActiveThemeOverride(method, endpoint, result) {
return method === 'POST' && endpoint === 'themes' && result.themes && result.themes[0] && result.themes[0].active === true;
}
/**
* ### Cache Invalidation Header
* Calculate the header string for the X-Cache-Invalidate: header.
@ -67,7 +71,12 @@ cacheInvalidationHeader = function cacheInvalidationHeader(req, result) {
hasStatusChanged,
wasPublishedUpdated;
if (['POST', 'PUT', 'DELETE'].indexOf(method) > -1) {
if (isActiveThemeOverride(method, endpoint, result)) {
// Special case for if we're overwriting an active theme
// @TODO: remove this crazy DIRTY HORRIBLE HACK
req.app.set('activeTheme', null);
return INVALIDATE_ALL;
} else if (['POST', 'PUT', 'DELETE'].indexOf(method) > -1) {
if (endpoint === 'schedules' && subdir === 'posts') {
return INVALIDATE_ALL;
}