From 90a70f7c31a08c0deef2abb0c1a2c7e2686822d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Fri, 14 Dec 2018 14:11:42 +0200 Subject: [PATCH] Fix a /saveItems session management race condition bug --- chrome/content/zotero/xpcom/connector/server_connector.js | 7 ++++--- chrome/content/zotero/xpcom/translation/translate_item.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/connector/server_connector.js b/chrome/content/zotero/xpcom/connector/server_connector.js index dd891125ed..c80293b25a 100644 --- a/chrome/content/zotero/xpcom/connector/server_connector.js +++ b/chrome/content/zotero/xpcom/connector/server_connector.js @@ -742,9 +742,10 @@ Zotero.Server.Connector.SaveItems.prototype = { session, targetID, requestData, - function (topLevelItems) { + function (jsonItems, items) { + session.addItems(items); // Only return the properties the connector needs - topLevelItems = topLevelItems.map((item) => { + jsonItems = jsonItems.map((item) => { let o = { id: item.id, title: item.title, @@ -764,7 +765,7 @@ Zotero.Server.Connector.SaveItems.prototype = { }; return o; }); - resolve([201, "application/json", JSON.stringify({items: topLevelItems})]); + resolve([201, "application/json", JSON.stringify({items: jsonItems})]); } ) // Add items to session once all attachments have been saved diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index c9fe751858..afafa0380f 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -179,7 +179,7 @@ Zotero.Translate.ItemSaver.prototype = { }.bind(this)); if (itemsDoneCallback) { - itemsDoneCallback(items.map(item => jsonByItem.get(item))); + itemsDoneCallback(items.map(item => jsonByItem.get(item)), items); } // Save standalone attachments