From 43025db6d51a49bf3e539756035d2c9e9ed96051 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 2 Aug 2011 18:56:00 +0000 Subject: [PATCH] - Change invalid creator type for item type to item type's primary creator automatically, since otherwise existing data would cause sync and save errors - Fix a couple other errors --- chrome/content/zotero/xpcom/data/item.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index cbb657397..d16ee2320 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -1002,6 +1002,15 @@ Zotero.Item.prototype.setCreator = function(orderIndex, creator, creatorTypeIDOr creatorTypeID = 1; } + // If creatorTypeID isn't valid for this type, use the primary type + if (!Zotero.CreatorTypes.isValidForItemType(creatorTypeID, this.itemTypeID)) { + var msg = "Invalid creator type " + creatorTypeID + " for item type " + this.itemTypeID + + " -- changing to primary creator"; + Zotero.debug(msg); + Components.utils.reportError(msg) + creatorTypeID = Zotero.CreatorTypes.getPrimaryIDForType(this.itemTypeID); + } + // If creator at this position hasn't changed, cancel if (this._creators[orderIndex] && this._creators[orderIndex].ref.id == creator.id && @@ -1011,11 +1020,6 @@ Zotero.Item.prototype.setCreator = function(orderIndex, creator, creatorTypeIDOr return false; } - if (!Zotero.CreatorTypes.isValidForItemType(creatorTypeID, this.itemTypeID)) { - throw ("Invalid creator type for item type in Zotero.Item.setCreator() " - + "(" + creatorTypeID + ", " + this.itemTypeID + ")"); - } - this._creators[orderIndex] = { ref: creator, creatorTypeID: creatorTypeID @@ -3840,7 +3844,7 @@ Zotero.Item.prototype.clone = function(includePrimary, newItem, unsaved) { newItem.id = this.id; newItem.libraryID = this.libraryID; newItem.key = this.key; - newItem.itemTypeID = itemTypeID; + newItem.setType(itemTypeID); for (var field in obj.primary) { switch (field) { case 'itemID':