Release v2.18.0: template default content
This commit is contained in:
1 parent
48e8f3eb4b
commit
24f1603b43
54 files changed
+1421
-151
No files matched your search
@@ -9,12 +9,13 @@ const { fetchAppSettings } = require('#src/data/app-settings');
|
||||
|
||||
async function getDataSourceUsageMaps(pool, common) {
|
||||
const [slides] = await pool.query('SELECT content_json FROM c_slides WHERE content_json IS NOT NULL');
|
||||
const [templateRegions] = await pool.query('SELECT default_content_json FROM c_template_regions WHERE default_content_json IS NOT NULL');
|
||||
const rssFeedIds = new Set();
|
||||
|
||||
for (let index = 0; index < slides.length; index += 1) {
|
||||
const content = typeof common.parseJsonSafe === 'function' ? common.parseJsonSafe(slides[index].content_json) : null;
|
||||
function collectUsage(json) {
|
||||
const content = typeof common.parseJsonSafe === 'function' ? common.parseJsonSafe(json) : null;
|
||||
if (!content || typeof content !== 'object') {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
(function walk(value) {
|
||||
@@ -40,6 +41,9 @@ async function getDataSourceUsageMaps(pool, common) {
|
||||
})(content);
|
||||
}
|
||||
|
||||
slides.forEach(function (slide) { collectUsage(slide.content_json); });
|
||||
templateRegions.forEach(function (region) { collectUsage(region.default_content_json); });
|
||||
|
||||
return rssFeedIds;
|
||||
}
|
||||
|
||||
@@ -119,32 +123,8 @@ module.exports = function registerRssFeedRoutes(app, deps) {
|
||||
return res.status(404).send('RSS feed not found');
|
||||
}
|
||||
|
||||
const [slides] = await pool.query('SELECT content_json FROM c_slides WHERE content_json IS NOT NULL');
|
||||
const inUse = (slides || []).some(function (row) {
|
||||
const content = typeof common.parseJsonSafe === 'function' ? common.parseJsonSafe(row.content_json) : null;
|
||||
if (!content || typeof content !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const stack = [content];
|
||||
while (stack.length) {
|
||||
const value = stack.pop();
|
||||
if (!value || typeof value !== 'object') {
|
||||
continue;
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach(function (item) { stack.push(item); });
|
||||
continue;
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(value, 'feed_id') && Number(value.feed_id) === Number(rssFeed.id)) {
|
||||
return true;
|
||||
}
|
||||
Object.keys(value).forEach(function (key) {
|
||||
stack.push(value[key]);
|
||||
});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
const usageIds = await getDataSourceUsageMaps(pool, common);
|
||||
const inUse = usageIds.has(Number(rssFeed.id));
|
||||
|
||||
const pulledItems = typeof common.fetchRssFeedItemsByFeedId === 'function'
|
||||
? await common.fetchRssFeedItemsByFeedId(pool, rssFeed.id)
|
||||
@@ -317,7 +297,7 @@ module.exports = function registerRssFeedRoutes(app, deps) {
|
||||
}
|
||||
|
||||
if (await isRssFeedInUse(pool, common, rssFeed.id)) {
|
||||
return res.redirect('/data-sources/rss-feeds?message=' + encodeURIComponent('This RSS feed is still used by one or more slides.'));
|
||||
return res.redirect('/data-sources/rss-feeds?message=' + encodeURIComponent('This RSS feed is still used by slides or template defaults.'));
|
||||
}
|
||||
|
||||
const connection = await pool.getConnection();
|
||||
@@ -337,4 +317,6 @@ module.exports = function registerRssFeedRoutes(app, deps) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
module.exports.getDataSourceUsageMaps = getDataSourceUsageMaps;
|
||||
Reference in new issue
Block a user