From 6c3ff86bcfcddcfcd216e23116a273c662225f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 5 Oct 2023 13:21:14 -0400 Subject: [PATCH] fix: add upgrade script for notifications --- .../3.5.0/notification_translations.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/upgrades/3.5.0/notification_translations.js diff --git a/src/upgrades/3.5.0/notification_translations.js b/src/upgrades/3.5.0/notification_translations.js new file mode 100644 index 0000000000..321243e794 --- /dev/null +++ b/src/upgrades/3.5.0/notification_translations.js @@ -0,0 +1,32 @@ +/* eslint-disable no-await-in-loop */ + +'use strict'; + +const db = require('../../database'); +const batch = require('../../batch'); + +module.exports = { + name: 'Update translation keys in notification bodyShort', + timestamp: Date.UTC(2023, 6, 27), + method: async function () { + const { progress } = this; + + await batch.processSortedSet(`notifications`, async (nids) => { + const notifData = await db.getObjects(nids.map(nid => `notifications:${nid}`)); + notifData.forEach((n) => { + if (n && n.bodyShort) { + n.bodyShort = n.bodyShort.replace(/_/g, '-'); + } + }); + + const bulkSet = notifData.map( + n => [`notifications:${n.nid}`, { bodyShort: n.bodyShort }] + ); + + await db.setObjectBulk(bulkSet); + }, { + batch: 500, + progress: progress, + }); + }, +};