Skip to content

Commit

Permalink
CSV Import: Redo the logic for repeating timestamp
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
reist committed Aug 7, 2017
1 parent 9361071 commit 1440fe3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/rocketchat-importer-csv/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -310,7 +317,6 @@ Importer.CSV = class ImporterCSV extends Importer.Base {
};

RocketChat.sendMessage(creator, msgObj, room, true);
roomCounter += 1;
}

super.addCountCompleted(1);
Expand Down

0 comments on commit 1440fe3

Please sign in to comment.