From 8627bee5417582a8c1c93d90fbbca13ba16db96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 9 Jun 2020 10:39:55 -0400 Subject: [PATCH] fix: #8386, use backgroundImage everywhere --- src/categories/data.js | 4 ---- .../1.14.0/fix_category_image_field.js | 23 +++++++++++++++++++ src/views/admin/manage/category.tpl | 6 ++--- 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 src/upgrades/1.14.0/fix_category_image_field.js diff --git a/src/categories/data.js b/src/categories/data.js index e9d5d8827c..55052801d2 100644 --- a/src/categories/data.js +++ b/src/categories/data.js @@ -81,10 +81,6 @@ function modifyCategory(category, fields) { category.totalTopicCount = category.topic_count; } - if (category.image) { - category.backgroundImage = category.image; - } - if (category.description) { category.description = validator.escape(String(category.description)); category.descriptionParsed = category.descriptionParsed || category.description; diff --git a/src/upgrades/1.14.0/fix_category_image_field.js b/src/upgrades/1.14.0/fix_category_image_field.js new file mode 100644 index 0000000000..10c2e6025d --- /dev/null +++ b/src/upgrades/1.14.0/fix_category_image_field.js @@ -0,0 +1,23 @@ +'use strict'; + +const db = require('../../database'); + +module.exports = { + name: 'Remove duplicate image field for categories', + timestamp: Date.UTC(2020, 5, 9), + method: async () => { + const batch = require('../../batch'); + await batch.processSortedSet('categories:cid', async function (cids) { + let categoryData = await db.getObjects(cids.map(c => 'category:' + c)); + categoryData = categoryData.filter(c => c && (c.image || c.backgroundImage)); + if (categoryData.length) { + await Promise.all(categoryData.map(async (data) => { + if (data.image && !data.backgroundImage) { + await db.setObjectField('category:' + data.cid, 'backgroundImage', data.image); + } + await db.deleteObjectField('category:' + data.cid, 'image', data.image); + })); + } + }, { batch: 500 }); + }, +}; diff --git a/src/views/admin/manage/category.tpl b/src/views/admin/manage/category.tpl index 178b55a605..776bb0e1de 100644 --- a/src/views/admin/manage/category.tpl +++ b/src/views/admin/manage/category.tpl @@ -122,14 +122,14 @@ [[admin/manage/categories:upload-image]] - +
- +
@@ -138,7 +138,7 @@ [[admin/manage/categories:category-image]]
- +