From 0e2073b251eaea993018c15523377067ea5ccfc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Fri, 30 Jul 2021 14:28:14 +0300 Subject: [PATCH] Revert removal of Utilities.Internal.itemToExportFormat() (since c929055) --- chrome/content/zotero/xpcom/utilities | 2 +- .../zotero/xpcom/utilities_internal.js | 138 +++++++++++++++++- 2 files changed, 136 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/utilities b/chrome/content/zotero/xpcom/utilities index b89bab4ad7..33feecf24e 160000 --- a/chrome/content/zotero/xpcom/utilities +++ b/chrome/content/zotero/xpcom/utilities @@ -1 +1 @@ -Subproject commit b89bab4ad7b5e118f323c3fd6bad4258681a4e65 +Subproject commit 33feecf24ed5780790f4678de4e5ad738f048f06 diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index 0465c36cd1..374445a1a7 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -986,9 +986,141 @@ Zotero.Utilities.Internal = { }, - itemToExportFormat: function () { - Zotero.debug(`Zotero.Utilities.Internal.itemToExportFormat() is deprecated -- use Zotero.Utilities.Item.itemToExportFormat() instead`); - return Zotero.Utilities.Item.itemToExportFormat.apply(Zotero.Utilities, arguments); + /** + * Converts Zotero.Item to a format expected by translators + * This is mostly the Zotero web API item JSON format, but with an attachments + * and notes arrays and optional compatibility mappings for older translators. + * + * @param {Zotero.Item} zoteroItem + * @param {Boolean} legacy Add mappings for legacy (pre-4.0.27) translators + * @return {Object} + */ + itemToExportFormat: function (zoteroItem, legacy, skipChildItems) { + function addCompatibilityMappings(item, zoteroItem) { + item.uniqueFields = {}; + + // Meaningless local item ID, but some older export translators depend on it + item.itemID = zoteroItem.id; + item.key = zoteroItem.key; // CSV translator exports this + + // "version" is expected to be a field for "computerProgram", which is now + // called "versionNumber" + delete item.version; + if (item.versionNumber) { + item.version = item.uniqueFields.version = item.versionNumber; + delete item.versionNumber; + } + + // SQL instead of ISO-8601 + item.dateAdded = zoteroItem.dateAdded; + item.dateModified = zoteroItem.dateModified; + if (item.accessDate) { + item.accessDate = zoteroItem.getField('accessDate'); + } + + // Map base fields + for (let field in item) { + let id = Zotero.ItemFields.getID(field); + if (!id || !Zotero.ItemFields.isValidForType(id, zoteroItem.itemTypeID)) { + continue; + } + + let baseField = Zotero.ItemFields.getName( + Zotero.ItemFields.getBaseIDFromTypeAndField(item.itemType, field) + ); + + if (!baseField || baseField == field) { + item.uniqueFields[field] = item[field]; + } else { + item[baseField] = item[field]; + item.uniqueFields[baseField] = item[field]; + } + } + + // Add various fields for compatibility with translators pre-4.0.27 + item.itemID = zoteroItem.id; + item.libraryID = zoteroItem.libraryID == 1 ? null : zoteroItem.libraryID; + + // Creators + if (item.creators) { + for (let i=0; i