From e3acd9a5138bd2a6ead45bf981c8b4c93d4f0a4c Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 3 Sep 2008 18:04:50 +0000 Subject: [PATCH] Better cleanup of cached data after sync error Clearer error message for "Creator must be a Zotero.Creator object in Zotero.Item.setCreator()" problem (which isn't yet fixed) --- chrome/content/zotero/xpcom/data/creators.js | 22 +++++++------------- chrome/content/zotero/xpcom/data/tags.js | 10 +++++++-- chrome/content/zotero/xpcom/sync.js | 13 +++++++++--- chrome/content/zotero/xpcom/zotero.js | 3 ++- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/creators.js b/chrome/content/zotero/xpcom/data/creators.js index ae3d32005..f0e0e995e 100644 --- a/chrome/content/zotero/xpcom/data/creators.js +++ b/chrome/content/zotero/xpcom/data/creators.js @@ -36,7 +36,6 @@ Zotero.Creators = new function() { this.updateData = updateData; this.deleteData = deleteData; this.reload = reload; - this.reloadAll = reloadAll; this.erase = erase; this.purge = purge; this.unload = unload; @@ -200,20 +199,6 @@ Zotero.Creators = new function() { } - function reloadAll() { - Zotero.debug("Reloading all creators"); - _creatorDataHash = {}; - for (var id in _creatorsByID) { - _creatorsByID[id].load(); - var realID = _creatorsByID[id].id; - if (realID != id) { - Zotero.debug("Clearing cache entry for creator " + id); - delete _creatorsByID[id]; - } - } - } - - /** * Remove creator(s) from all linked items and call this.purge() * to delete creator rows @@ -300,6 +285,13 @@ Zotero.Creators = new function() { } + this.unloadAll = function () { + Zotero.debug("Unloading all creators"); + _creatorsByID = {}; + _creatorDataHash = {}; + } + + function _cleanFields(fields) { var cleanedFields = { firstName: '', diff --git a/chrome/content/zotero/xpcom/data/tags.js b/chrome/content/zotero/xpcom/data/tags.js index 6c5bb19ed..c9057a667 100644 --- a/chrome/content/zotero/xpcom/data/tags.js +++ b/chrome/content/zotero/xpcom/data/tags.js @@ -28,8 +28,8 @@ Zotero.Tags = new function() { Zotero.DataObjects.apply(this, ['tag']); this.constructor.prototype = new Zotero.DataObjects(); - var _tags = []; // indexed by tag text - var _tagsByID = []; // indexed by tagID + var _tags = {}; // indexed by tag text + var _tagsByID = {}; // indexed by tagID this.get = get; this.getName = getName; @@ -426,5 +426,11 @@ Zotero.Tags = new function() { } } } + + + this.unloadAll = function (ids) { + _tags = {}; + _tagsByID = {}; + } } diff --git a/chrome/content/zotero/xpcom/sync.js b/chrome/content/zotero/xpcom/sync.js index c74800104..ddf35417f 100644 --- a/chrome/content/zotero/xpcom/sync.js +++ b/chrome/content/zotero/xpcom/sync.js @@ -1234,6 +1234,7 @@ Zotero.Sync.Server = new function () { _syncInProgress = false; _resetAttempts(); Zotero.DB.rollbackAllTransactions(); + Zotero.reloadDataObjects(); if (_sessionID && _sessionLock) { Zotero.Sync.Server.unlock() @@ -1497,8 +1498,9 @@ Zotero.Sync.Server.Data = new function() { } if (type != 'item') { - alert('Reconciliation unimplemented for ' + types); - throw ('Reconciliation unimplemented for ' + types); + var msg = "Reconciliation unimplemented for " + types; + alert(msg); + throw(msg); } if (obj.isAttachment()) { @@ -2123,9 +2125,14 @@ Zotero.Sync.Server.Data = new function() { throw ('No creator in position ' + i); } + var creatorID = parseInt(creator.@id); + var creatorObj = Zotero.Creators.get(creatorID); + if (!creatorObj) { + throw ("Creator " + creatorID + " does not exist"); + } item.setCreator( pos, - Zotero.Creators.get(parseInt(creator.@id)), + creatorObj, creator.@creatorType.toString() ); i++; diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index f7b4a8b64..2050ab753 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -913,8 +913,9 @@ var Zotero = new function(){ function reloadDataObjects() { + Zotero.Tags.unloadAll(); Zotero.Collections.reloadAll(); - Zotero.Creators.reloadAll(); + Zotero.Creators.unloadAll(); Zotero.Items.reloadAll(); } };