From 82326075595683ac85ea62fa5018022127ba560d Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Tue, 31 Mar 2020 19:46:59 -0300 Subject: [PATCH 1/4] Removed inquiries related to closed room. --- server/startup/migrations/index.js | 1 + server/startup/migrations/v180.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 server/startup/migrations/v180.js diff --git a/server/startup/migrations/index.js b/server/startup/migrations/index.js index 6ad1177c8965..da1f016bf8f2 100644 --- a/server/startup/migrations/index.js +++ b/server/startup/migrations/index.js @@ -177,4 +177,5 @@ import './v176'; import './v177'; import './v178'; import './v179'; +import './v180'; import './xrun'; diff --git a/server/startup/migrations/v180.js b/server/startup/migrations/v180.js new file mode 100644 index 000000000000..1a5bc0cd32dd --- /dev/null +++ b/server/startup/migrations/v180.js @@ -0,0 +1,17 @@ +import { Migrations } from '../../../app/migrations/server'; +import { LivechatRooms, LivechatInquiry } from '../../../app/models/server'; + +Migrations.add({ + version: 180, + up() { + // Remove Old Omnichannel Inquiries related to rooms already closed + LivechatInquiry.find({ status: 'queued' }).forEach((inquiry) => { + const { rid } = inquiry; + + const room = LivechatRooms.findOneById(rid); + if (!room || room.closedAt) { + LivechatInquiry.removeByRoomId(rid); + } + }); + }, +}); From 7557b5ca29c6c18ce00fff819fa32be6f704bc6a Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Tue, 31 Mar 2020 21:46:47 -0300 Subject: [PATCH 2/4] Remove old and closed Omnichannel Inquiries. --- server/startup/migrations/v180.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/startup/migrations/v180.js b/server/startup/migrations/v180.js index 1a5bc0cd32dd..ef08f2716c83 100644 --- a/server/startup/migrations/v180.js +++ b/server/startup/migrations/v180.js @@ -5,8 +5,11 @@ Migrations.add({ version: 180, up() { // Remove Old Omnichannel Inquiries related to rooms already closed - LivechatInquiry.find({ status: 'queued' }).forEach((inquiry) => { - const { rid } = inquiry; + LivechatInquiry.find().forEach((inquiry) => { + const { rid, status } = inquiry; + if (status === 'closed') { + return LivechatInquiry.removeByRoomId(rid); + } const room = LivechatRooms.findOneById(rid); if (!room || room.closedAt) { From c3dd106e4cc8e819c54a14c0f8d317720e5f47d0 Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Wed, 1 Apr 2020 00:25:11 -0300 Subject: [PATCH 3/4] Return only the necessary field when finding. --- server/startup/migrations/v180.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/startup/migrations/v180.js b/server/startup/migrations/v180.js index ef08f2716c83..05a73067637c 100644 --- a/server/startup/migrations/v180.js +++ b/server/startup/migrations/v180.js @@ -11,7 +11,7 @@ Migrations.add({ return LivechatInquiry.removeByRoomId(rid); } - const room = LivechatRooms.findOneById(rid); + const room = LivechatRooms.findOneById(rid, { fields: { closedAt: 1 } }); if (!room || room.closedAt) { LivechatInquiry.removeByRoomId(rid); } From abbf546d6965d3337014ce8de78edff135d29b99 Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Wed, 1 Apr 2020 00:30:46 -0300 Subject: [PATCH 4/4] Fix findOne parameter. --- server/startup/migrations/v180.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/startup/migrations/v180.js b/server/startup/migrations/v180.js index 05a73067637c..b7c845caa21f 100644 --- a/server/startup/migrations/v180.js +++ b/server/startup/migrations/v180.js @@ -11,7 +11,7 @@ Migrations.add({ return LivechatInquiry.removeByRoomId(rid); } - const room = LivechatRooms.findOneById(rid, { fields: { closedAt: 1 } }); + const room = LivechatRooms.findOneById(rid, { closedAt: 1 }); if (!room || room.closedAt) { LivechatInquiry.removeByRoomId(rid); }