Address file import bugs

I don't know why why, but wbp.saveDocument() destroys the
document object which is passed into it. This means that further access
of the document is impossible and raises errors, which we were not
handling properly and not returning on attachment saving.

I've added error handling and changed removed code which tries to access
the document after the Zotero.Utilities.Internal.saveDocument() call.

Addresses https://forums.zotero.org/discussion/64745/5-0-beta-apparently-stuck-at-saving-to
This commit is contained in:
Adomas Venčkauskas 2017-04-07 14:35:49 +03:00
parent 406f50a3fd
commit 5818935a32

View file

@ -277,8 +277,14 @@ Zotero.Attachments = new function(){
saveOptions saveOptions
}) })
.then(function (attachmentItem) { .then(function (attachmentItem) {
Zotero.Browser.deleteHiddenBrowser(browser);
deferred.resolve(attachmentItem); deferred.resolve(attachmentItem);
})
.catch(function(e) {
Zotero.logError(e);
deferred.reject();
})
.finally(function() {
Zotero.Browser.deleteHiddenBrowser(browser);
}); });
}, },
undefined, undefined,
@ -586,7 +592,7 @@ Zotero.Attachments = new function(){
} }
if (contentType === 'text/html' || contentType === 'application/xhtml+xml') { if (contentType === 'text/html' || contentType === 'application/xhtml+xml') {
Zotero.debug('Saving document with saveURI()'); Zotero.debug('Saving document with saveDocument()');
yield Zotero.Utilities.Internal.saveDocument(document, tmpFile.path); yield Zotero.Utilities.Internal.saveDocument(document, tmpFile.path);
} }
else { else {
@ -670,9 +676,10 @@ Zotero.Attachments = new function(){
}, 1000); }, 1000);
} }
else if (Zotero.MIME.isTextType(contentType)) { else if (Zotero.MIME.isTextType(contentType)) {
// Index document immediately, so that browser object can't // wbp.saveDocument consumes the document context (in Zotero.Utilities.Internal.saveDocument)
// be removed before indexing completes // Seems like a mozilla bug, but nothing on bugtracker.
yield Zotero.Fulltext.indexDocument(document, attachmentItem.id); // Either way, we don't rely on Zotero.Fulltext.indexDocument here anymore
yield Zotero.Fulltext.indexItems(attachmentItem.id, true, true);
} }
return attachmentItem; return attachmentItem;