From 1440fe38d396946285b2cd1486b9c2d793704d47 Mon Sep 17 00:00:00 2001 From: Boris Peterbarg Date: Wed, 2 Aug 2017 18:49:04 +0300 Subject: [PATCH] CSV Import: Redo the logic for repeating timestamp This way, it will re-import old imports just fine. For new imports, the order of timestamps in the CSV files will have to be the same, always. So, either using the same dumps or enforcing order on the CSV dump is required. --- packages/rocketchat-importer-csv/server.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/rocketchat-importer-csv/server.js b/packages/rocketchat-importer-csv/server.js index 32b647d2b955..3597f1df6616 100644 --- a/packages/rocketchat-importer-csv/server.js +++ b/packages/rocketchat-importer-csv/server.js @@ -286,7 +286,7 @@ Importer.CSV = class ImporterCSV extends Importer.Base { const room = RocketChat.models.Rooms.findOneById(csvChannel.rocketId, { fields: { usernames: 1, t: 1, name: 1 } }); Meteor.runAsUser(startedByUserId, () => { - let roomCounter = 0; + const timestamps = {}; for (const [msgGroupData, msgs] of messagesMap.entries()) { super.updateRecord({ 'messagesstatus': `${ ch }/${ msgGroupData }.${ msgs.messages.length }` }); for (const msg of msgs.messages) { @@ -298,8 +298,15 @@ Importer.CSV = class ImporterCSV extends Importer.Base { const creator = this.getUserFromUsername(msg.username); if (creator) { + let suffix = ''; + if (timestamps[msg.ts] === undefined) { + timestamps[msg.ts] = 1; + } else { + suffix = `-${ timestamps[msg.ts] }`; + timestamps[msg.ts] += 1; + } const msgObj = { - _id: `csv-${ csvChannel.id }-${ roomCounter }-${ msg.ts }`, + _id: `csv-${ csvChannel.id }-${ msg.ts }${ suffix }`, ts: new Date(parseInt(msg.ts)), msg: msg.text, rid: room._id, @@ -310,7 +317,6 @@ Importer.CSV = class ImporterCSV extends Importer.Base { }; RocketChat.sendMessage(creator, msgObj, room, true); - roomCounter += 1; } super.addCountCompleted(1);