mirror of
https://github.com/zotero/zotero.git
synced 2026-09-29 01:41:24 +00:00
Item#fromJSON(): Don't process any Extra rows in strict mode
And enable migration of Extra rows to valid fields in non-strict mode, but since that's only used by translators now, that probably won't do anything Fixes #3422
This commit is contained in:
parent
8642091d8e
commit
ec280c5bdf
1 changed files with 26 additions and 20 deletions
|
|
@ -5124,6 +5124,7 @@ Zotero.Item.prototype._eraseData = Zotero.Promise.coroutine(function* (env) {
|
|||
*/
|
||||
Zotero.Item.prototype.fromJSON = function (json, options = {}) {
|
||||
var strict = !!options.strict;
|
||||
var migrateExtra = !strict;
|
||||
|
||||
if (!json.itemType && !this._itemTypeID) {
|
||||
throw new Error("itemType property not provided");
|
||||
|
|
@ -5139,29 +5140,34 @@ Zotero.Item.prototype.fromJSON = function (json, options = {}) {
|
|||
|
||||
var isValidForType = {};
|
||||
var setFields = new Set();
|
||||
var { itemType, fields: extraFields, creators: extraCreators, extra } =
|
||||
Zotero.Utilities.Internal.extractExtraFields(
|
||||
json.extra || '',
|
||||
this,
|
||||
Object.keys(json)
|
||||
// TEMP until we move creator lines to real creators
|
||||
.concat('creators')
|
||||
);
|
||||
// If a different item type was parsed out of Extra, use that instead
|
||||
if (itemType && json.itemType != itemType) {
|
||||
itemTypeID = Zotero.ItemTypes.getID(itemType);
|
||||
this.setType(itemTypeID);
|
||||
|
||||
var extraFields = new Map();
|
||||
var extraCreators = [];
|
||||
var extra = json.extra || '';
|
||||
// Transfer valid fields from Extra to regular fields
|
||||
if (migrateExtra) {
|
||||
let itemType;
|
||||
({ itemType, fields: extraFields, creators: extraCreators, extra } =
|
||||
Zotero.Utilities.Internal.extractExtraFields(
|
||||
extra,
|
||||
this,
|
||||
Object.keys(json)
|
||||
// TEMP until we move creator lines to real creators
|
||||
.concat('creators')
|
||||
));
|
||||
// If a different item type was parsed out of Extra, use that instead
|
||||
if (itemType && json.itemType != itemType) {
|
||||
itemTypeID = Zotero.ItemTypes.getID(itemType);
|
||||
this.setType(itemTypeID);
|
||||
}
|
||||
for (let [field, value] of extraFields) {
|
||||
this.setField(field, value);
|
||||
setFields.add(field);
|
||||
extraFields.delete(field);
|
||||
}
|
||||
}
|
||||
var invalidFieldLogLines = new Map();
|
||||
|
||||
// Transfer valid fields from Extra to regular fields
|
||||
// Currently disabled
|
||||
/*for (let [field, value] of extraFields) {
|
||||
this.setField(field, value);
|
||||
setFields.add(field);
|
||||
extraFields.delete(field);
|
||||
}*/
|
||||
|
||||
for (let field in json) {
|
||||
let val = json[field];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue