Fix connector translator caching from repo and standalone

This commit is contained in:
Adomas Venčkauskas 2016-12-19 11:38:56 +02:00
parent 2f65c7d29c
commit 8e083c688a
2 changed files with 12 additions and 10 deletions

View file

@ -150,7 +150,8 @@ Zotero.Repo = new function() {
if(!result && tryRepoOnFailure) {
_updateFromRepo(reset, callback);
} else {
_handleResponse(result, reset);
// Standalone always returns all translators without .deleted property
_handleResponse(result, true);
if(callback) callback(!!result);
}
});

View file

@ -222,18 +222,19 @@ Zotero.Translators = new function() {
* the specified translators.
*/
this.update = function(newMetadata, reset) {
if(!_initialized) Zotero.Translators.init();
if(!newMetadata.length) return;
if (!_initialized) Zotero.Translators.init();
if (!newMetadata.length) return;
var serializedTranslators = [];
if(!reset) {
var existingTranslatorIDs = new Set();
var serializedTranslators = [];
if (reset) {
serializedTranslators = newMetadata.map((t) => new Zotero.Translator(t));
}
else {
var hasChanged = false;
// Update translators with new metadata
for(var i in newMetadata) {
var newTranslator = newMetadata[i];
existingTranslatorIDs.add(newTranslator.translatorID);
if(_translators.hasOwnProperty(newTranslator.translatorID)) {
var oldTranslator = _translators[newTranslator.translatorID];
@ -257,11 +258,11 @@ Zotero.Translators = new function() {
}
}
let deletedTranslators = Object.keys(_translators).filter(id => !existingTranslatorIDs.has(id));
let deletedTranslators = Object.keys(_translators).filter(id => _translators[id].deleted);
if (deletedTranslators.length) {
hasChanged = true;
for (let id of deletedTranslators) {
Zotero.debug(`Translators: Removing ${_translators[ID].label}`);
Zotero.debug(`Translators: Removing ${_translators[id].label}`);
delete _translators[id];
}
}
@ -326,7 +327,7 @@ Zotero.Translators.CodeGetter.prototype.getCodeFor = Zotero.Promise.method(funct
// include test cases)
|| (Zotero.Repo && translator.codeSource === Zotero.Repo.SOURCE_REPO)))) {
// get code
return translator.getCode();
return translator.getCode().catch((e) => Zotero.debug(`Failed to retrieve code for ${translator.translatorID}`));
}
});