Better logging for Extra migration

This commit is contained in:
Dan Stillman 2020-03-17 11:57:18 -04:00
parent d8d07362ba
commit c4aad9a041

View file

@ -4625,35 +4625,51 @@ Zotero.Item.prototype.migrateExtraFields = function () {
return false; return false;
} }
var { itemType, fields, creators, extra } = Zotero.Utilities.Internal.extractExtraFields( var originalExtra = this.getField('extra');
this.getField('extra'), this
); var log = function () {
if (itemType) { Zotero.debug("Original Extra:\n\n" + originalExtra);
this.setType(Zotero.ItemTypes.getID(itemType)); if (itemType) {
Zotero.debug("Item Type: " + itemType);
}
if (fields.size) {
Zotero.debug("Fields:\n\n" + Array.from(fields.entries()).map(x => `${x[0]}: ${x[1]}`).join("\n"));
}
if (creators.length) {
Zotero.debug("Creators:");
Zotero.debug(creators);
}
if (extra) {
Zotero.debug("Remaining Extra:\n\n" + extra);
}
};
try {
var { itemType, fields, creators, extra } = Zotero.Utilities.Internal.extractExtraFields(
originalExtra, this
);
if (itemType) {
this.setType(Zotero.ItemTypes.getID(itemType));
}
for (let [field, value] of fields) {
this.setField(field, value);
}
if (creators.length) {
this.setCreators([...this.getCreators(), ...creators]);
}
this.setField('extra', extra);
if (!this.hasChanged()) {
return false;
}
} }
for (let [field, value] of fields) { catch (e) {
this.setField(field, value); Zotero.logError("Error migrating Extra fields for item " + this.libraryKey);
} log();
if (creators.length) { throw e;
this.setCreators([...this.getCreators(), ...creators]);
}
this.setField('extra', extra);
if (!this.hasChanged()) {
return false;
} }
Zotero.debug("Migrating Extra fields for item " + this.libraryKey); Zotero.debug("Migrating Extra fields for item " + this.libraryKey);
if (itemType) { log();
Zotero.debug("Item Type: " + itemType);
}
if (fields.size) {
Zotero.debug("Fields:\n\n" + Array.from(fields.entries()).map(x => `${x[0]}: ${x[1]}`).join("\n"));
}
if (creators.length) {
Zotero.debug("Creators:");
Zotero.debug(creators);
}
Zotero.debug("Remaining Extra:\n\n" + extra);
return true; return true;
} }