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)
This commit is contained in:
Dan Stillman 2008-09-03 18:04:50 +00:00
parent 088c057837
commit e3acd9a513
4 changed files with 27 additions and 21 deletions

View file

@ -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: '',

View file

@ -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 = {};
}
}

View file

@ -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++;

View file

@ -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();
}
};