Fix export translation
This reverts Zotero.Translate.ItemGetter.prototype.nextItem() to being synchronous post-deasyncification. This will need to be made to work asynchronously in the future if _attachmentToArray(), which is called by nextItem, is changed to use async file access (which might be required at some point). Addresses #734, [Async DB] Import/export fails
This commit is contained in:
parent
b1eb2b6de5
commit
51b286528c
|
@ -717,7 +717,7 @@ Zotero.Translate.ItemGetter.prototype = {
|
||||||
/**
|
/**
|
||||||
* Converts an attachment to array format and copies it to the export folder if desired
|
* Converts an attachment to array format and copies it to the export folder if desired
|
||||||
*/
|
*/
|
||||||
"_attachmentToArray":Zotero.Promise.coroutine(function* (attachment) {
|
"_attachmentToArray": function (attachment) {
|
||||||
var attachmentArray = Zotero.Utilities.Internal.itemToExportFormat(attachment, this.legacy);
|
var attachmentArray = Zotero.Utilities.Internal.itemToExportFormat(attachment, this.legacy);
|
||||||
var linkMode = attachment.attachmentLinkMode;
|
var linkMode = attachment.attachmentLinkMode;
|
||||||
if(linkMode != Zotero.Attachments.LINK_MODE_LINKED_URL) {
|
if(linkMode != Zotero.Attachments.LINK_MODE_LINKED_URL) {
|
||||||
|
@ -849,17 +849,17 @@ Zotero.Translate.ItemGetter.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
return attachmentArray;
|
return attachmentArray;
|
||||||
}),
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the next available item
|
* Retrieves the next available item
|
||||||
*/
|
*/
|
||||||
"nextItem":Zotero.Promise.coroutine(function* () {
|
"nextItem": function () {
|
||||||
while(this._itemsLeft.length != 0) {
|
while(this._itemsLeft.length != 0) {
|
||||||
var returnItem = this._itemsLeft.shift();
|
var returnItem = this._itemsLeft.shift();
|
||||||
// export file data for single files
|
// export file data for single files
|
||||||
if(returnItem.isAttachment()) { // an independent attachment
|
if(returnItem.isAttachment()) { // an independent attachment
|
||||||
var returnItemArray = yield this._attachmentToArray(returnItem);
|
var returnItemArray = this._attachmentToArray(returnItem);
|
||||||
if(returnItemArray) return returnItemArray;
|
if(returnItemArray) return returnItemArray;
|
||||||
} else {
|
} else {
|
||||||
var returnItemArray = Zotero.Utilities.Internal.itemToExportFormat(returnItem, this.legacy);
|
var returnItemArray = Zotero.Utilities.Internal.itemToExportFormat(returnItem, this.legacy);
|
||||||
|
@ -869,7 +869,7 @@ Zotero.Translate.ItemGetter.prototype = {
|
||||||
var attachments = returnItem.getAttachments();
|
var attachments = returnItem.getAttachments();
|
||||||
for each(var attachmentID in attachments) {
|
for each(var attachmentID in attachments) {
|
||||||
var attachment = Zotero.Items.get(attachmentID);
|
var attachment = Zotero.Items.get(attachmentID);
|
||||||
var attachmentInfo = yield this._attachmentToArray(attachment);
|
var attachmentInfo = this._attachmentToArray(attachment);
|
||||||
|
|
||||||
if(attachmentInfo) {
|
if(attachmentInfo) {
|
||||||
returnItemArray.attachments.push(attachmentInfo);
|
returnItemArray.attachments.push(attachmentInfo);
|
||||||
|
@ -880,7 +880,7 @@ Zotero.Translate.ItemGetter.prototype = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}),
|
},
|
||||||
|
|
||||||
"nextCollection":function() {
|
"nextCollection":function() {
|
||||||
if(!this._collectionsLeft || this._collectionsLeft.length == 0) return false;
|
if(!this._collectionsLeft || this._collectionsLeft.length == 0) return false;
|
||||||
|
|
|
@ -574,7 +574,7 @@ describe("Zotero.Translate.ItemGetter", function() {
|
||||||
describe("nextItem", function() {
|
describe("nextItem", function() {
|
||||||
it('should return false for an empty database', Zotero.Promise.coroutine(function* () {
|
it('should return false for an empty database', Zotero.Promise.coroutine(function* () {
|
||||||
let getter = new Zotero.Translate.ItemGetter();
|
let getter = new Zotero.Translate.ItemGetter();
|
||||||
assert.isFalse(yield getter.nextItem());
|
assert.isFalse(getter.nextItem());
|
||||||
}));
|
}));
|
||||||
it('should return items in order they are supplied', Zotero.Promise.coroutine(function* () {
|
it('should return items in order they are supplied', Zotero.Promise.coroutine(function* () {
|
||||||
let getter = new Zotero.Translate.ItemGetter();
|
let getter = new Zotero.Translate.ItemGetter();
|
||||||
|
@ -592,9 +592,9 @@ describe("Zotero.Translate.ItemGetter", function() {
|
||||||
|
|
||||||
getter._itemsLeft = items;
|
getter._itemsLeft = items;
|
||||||
|
|
||||||
assert.equal((yield getter.nextItem()).uri, itemURIs[0], 'first item comes out first');
|
assert.equal((getter.nextItem()).uri, itemURIs[0], 'first item comes out first');
|
||||||
assert.equal((yield getter.nextItem()).uri, itemURIs[1], 'second item comes out second');
|
assert.equal((getter.nextItem()).uri, itemURIs[1], 'second item comes out second');
|
||||||
assert.isFalse((yield getter.nextItem()), 'end of item queue');
|
assert.isFalse((getter.nextItem()), 'end of item queue');
|
||||||
}));
|
}));
|
||||||
it('should return items with tags in expected format', Zotero.Promise.coroutine(function* () {
|
it('should return items with tags in expected format', Zotero.Promise.coroutine(function* () {
|
||||||
let getter = new Zotero.Translate.ItemGetter();
|
let getter = new Zotero.Translate.ItemGetter();
|
||||||
|
@ -622,7 +622,7 @@ describe("Zotero.Translate.ItemGetter", function() {
|
||||||
let suffix = legacyMode[i] ? ' in legacy mode' : '';
|
let suffix = legacyMode[i] ? ' in legacy mode' : '';
|
||||||
|
|
||||||
// itemWithAutomaticTag
|
// itemWithAutomaticTag
|
||||||
let translatorItem = yield getter.nextItem();
|
let translatorItem = getter.nextItem();
|
||||||
assert.isArray(translatorItem.tags, 'item contains automatic tags in an array' + suffix);
|
assert.isArray(translatorItem.tags, 'item contains automatic tags in an array' + suffix);
|
||||||
assert.isObject(translatorItem.tags[0], 'automatic tag is an object' + suffix);
|
assert.isObject(translatorItem.tags[0], 'automatic tag is an object' + suffix);
|
||||||
assert.equal(translatorItem.tags[0].tag, 'automatic tag', 'automatic tag name provided as "tag" property' + suffix);
|
assert.equal(translatorItem.tags[0].tag, 'automatic tag', 'automatic tag name provided as "tag" property' + suffix);
|
||||||
|
@ -633,14 +633,14 @@ describe("Zotero.Translate.ItemGetter", function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// itemWithManualTag
|
// itemWithManualTag
|
||||||
translatorItem = yield getter.nextItem();
|
translatorItem = getter.nextItem();
|
||||||
assert.isArray(translatorItem.tags, 'item contains manual tags in an array' + suffix);
|
assert.isArray(translatorItem.tags, 'item contains manual tags in an array' + suffix);
|
||||||
assert.isObject(translatorItem.tags[0], 'manual tag is an object' + suffix);
|
assert.isObject(translatorItem.tags[0], 'manual tag is an object' + suffix);
|
||||||
assert.equal(translatorItem.tags[0].tag, 'manual tag', 'manual tag name provided as "tag" property' + suffix);
|
assert.equal(translatorItem.tags[0].tag, 'manual tag', 'manual tag name provided as "tag" property' + suffix);
|
||||||
assert.equal(translatorItem.tags[0].type, 1, 'manual tag "type" is 1' + suffix);
|
assert.equal(translatorItem.tags[0].type, 1, 'manual tag "type" is 1' + suffix);
|
||||||
|
|
||||||
// itemWithMultipleTags
|
// itemWithMultipleTags
|
||||||
translatorItem = yield getter.nextItem();
|
translatorItem = getter.nextItem();
|
||||||
assert.isArray(translatorItem.tags, 'item contains multiple tags in an array' + suffix);
|
assert.isArray(translatorItem.tags, 'item contains multiple tags in an array' + suffix);
|
||||||
assert.lengthOf(translatorItem.tags, 2, 'expected number of tags returned' + suffix);
|
assert.lengthOf(translatorItem.tags, 2, 'expected number of tags returned' + suffix);
|
||||||
}
|
}
|
||||||
|
@ -680,16 +680,16 @@ describe("Zotero.Translate.ItemGetter", function() {
|
||||||
yield collections[2].addItem(items[3].id);
|
yield collections[2].addItem(items[3].id);
|
||||||
});
|
});
|
||||||
|
|
||||||
let translatorItem = yield getter.nextItem();
|
let translatorItem = getter.nextItem();
|
||||||
assert.isArray(translatorItem.collections, 'item in library root has a collections array');
|
assert.isArray(translatorItem.collections, 'item in library root has a collections array');
|
||||||
assert.equal(translatorItem.collections.length, 0, 'item in library root does not list any collections');
|
assert.equal(translatorItem.collections.length, 0, 'item in library root does not list any collections');
|
||||||
|
|
||||||
translatorItem = yield getter.nextItem();
|
translatorItem = getter.nextItem();
|
||||||
assert.isArray(translatorItem.collections, 'item in a single collection has a collections array');
|
assert.isArray(translatorItem.collections, 'item in a single collection has a collections array');
|
||||||
assert.equal(translatorItem.collections.length, 1, 'item in a single collection lists one collection');
|
assert.equal(translatorItem.collections.length, 1, 'item in a single collection lists one collection');
|
||||||
assert.equal(translatorItem.collections[0], collections[0].key, 'item in a single collection identifies correct collection');
|
assert.equal(translatorItem.collections[0], collections[0].key, 'item in a single collection identifies correct collection');
|
||||||
|
|
||||||
translatorItem = yield getter.nextItem();
|
translatorItem = getter.nextItem();
|
||||||
assert.isArray(translatorItem.collections, 'item in two collections has a collections array');
|
assert.isArray(translatorItem.collections, 'item in two collections has a collections array');
|
||||||
assert.equal(translatorItem.collections.length, 2, 'item in two collections lists two collections');
|
assert.equal(translatorItem.collections.length, 2, 'item in two collections lists two collections');
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
|
@ -698,7 +698,7 @@ describe("Zotero.Translate.ItemGetter", function() {
|
||||||
'item in two collections identifies correct collections'
|
'item in two collections identifies correct collections'
|
||||||
);
|
);
|
||||||
|
|
||||||
translatorItem = yield getter.nextItem();
|
translatorItem = getter.nextItem();
|
||||||
assert.isArray(translatorItem.collections, 'item in a nested collection has a collections array');
|
assert.isArray(translatorItem.collections, 'item in a nested collection has a collections array');
|
||||||
assert.equal(translatorItem.collections.length, 1, 'item in a single nested collection lists one collection');
|
assert.equal(translatorItem.collections.length, 1, 'item in a single nested collection lists one collection');
|
||||||
assert.equal(translatorItem.collections[0], collections[2].key, 'item in a single collection identifies correct collection');
|
assert.equal(translatorItem.collections[0], collections[2].key, 'item in a single collection identifies correct collection');
|
||||||
|
@ -728,25 +728,25 @@ describe("Zotero.Translate.ItemGetter", function() {
|
||||||
|
|
||||||
// getter._itemsLeft = items.slice();
|
// getter._itemsLeft = items.slice();
|
||||||
|
|
||||||
// let translatorItem = yield getter.nextItem();
|
// let translatorItem = getter.nextItem();
|
||||||
// assert.isObject(translatorItem.relations, 'item with no relations has a relations object');
|
// assert.isObject(translatorItem.relations, 'item with no relations has a relations object');
|
||||||
// assert.equal(Object.keys(translatorItem.relations).length, 0, 'item with no relations does not list any relations');
|
// assert.equal(Object.keys(translatorItem.relations).length, 0, 'item with no relations does not list any relations');
|
||||||
|
|
||||||
// translatorItem = yield getter.nextItem();
|
// translatorItem = getter.nextItem();
|
||||||
// assert.isObject(translatorItem.relations, 'item that is the subject of a single relation has a relations object');
|
// assert.isObject(translatorItem.relations, 'item that is the subject of a single relation has a relations object');
|
||||||
// assert.equal(Object.keys(translatorItem.relations).length, 1, 'item that is the subject of a single relation list one relations predicate');
|
// assert.equal(Object.keys(translatorItem.relations).length, 1, 'item that is the subject of a single relation list one relations predicate');
|
||||||
// assert.isDefined(translatorItem.relations['dc:relation'], 'item that is the subject of a single relation uses "dc:relation" as the predicate');
|
// assert.isDefined(translatorItem.relations['dc:relation'], 'item that is the subject of a single relation uses "dc:relation" as the predicate');
|
||||||
// assert.isString(translatorItem.relations['dc:relation'], 'item that is the subject of a single relation lists "dc:relation" object as a string');
|
// assert.isString(translatorItem.relations['dc:relation'], 'item that is the subject of a single relation lists "dc:relation" object as a string');
|
||||||
// assert.equal(translatorItem.relations['dc:relation'], Zotero.URI.getItemURI(items[2]), 'item that is the subject of a single relation identifies correct object URI');
|
// assert.equal(translatorItem.relations['dc:relation'], Zotero.URI.getItemURI(items[2]), 'item that is the subject of a single relation identifies correct object URI');
|
||||||
|
|
||||||
// translatorItem = yield getter.nextItem();
|
// translatorItem = getter.nextItem();
|
||||||
// assert.isObject(translatorItem.relations, 'item that is the object of a single relation has a relations object');
|
// assert.isObject(translatorItem.relations, 'item that is the object of a single relation has a relations object');
|
||||||
// assert.equal(Object.keys(translatorItem.relations).length, 1, 'item that is the object of a single relation list one relations predicate');
|
// assert.equal(Object.keys(translatorItem.relations).length, 1, 'item that is the object of a single relation list one relations predicate');
|
||||||
// assert.isDefined(translatorItem.relations['dc:relation'], 'item that is the object of a single relation uses "dc:relation" as the predicate');
|
// assert.isDefined(translatorItem.relations['dc:relation'], 'item that is the object of a single relation uses "dc:relation" as the predicate');
|
||||||
// assert.isString(translatorItem.relations['dc:relation'], 'item that is the object of a single relation lists "dc:relation" object as a string');
|
// assert.isString(translatorItem.relations['dc:relation'], 'item that is the object of a single relation lists "dc:relation" object as a string');
|
||||||
// assert.equal(translatorItem.relations['dc:relation'], Zotero.URI.getItemURI(items[1]), 'item that is the object of a single relation identifies correct subject URI');
|
// assert.equal(translatorItem.relations['dc:relation'], Zotero.URI.getItemURI(items[1]), 'item that is the object of a single relation identifies correct subject URI');
|
||||||
|
|
||||||
// translatorItem = yield getter.nextItem();
|
// translatorItem = getter.nextItem();
|
||||||
// assert.isObject(translatorItem.relations, 'item that is the subject of two relations has a relations object');
|
// assert.isObject(translatorItem.relations, 'item that is the subject of two relations has a relations object');
|
||||||
// assert.equal(Object.keys(translatorItem.relations).length, 1, 'item that is the subject of two relations list one relations predicate');
|
// assert.equal(Object.keys(translatorItem.relations).length, 1, 'item that is the subject of two relations list one relations predicate');
|
||||||
// assert.isDefined(translatorItem.relations['dc:relation'], 'item that is the subject of two relations uses "dc:relation" as the predicate');
|
// assert.isDefined(translatorItem.relations['dc:relation'], 'item that is the subject of two relations uses "dc:relation" as the predicate');
|
||||||
|
@ -757,7 +757,7 @@ describe("Zotero.Translate.ItemGetter", function() {
|
||||||
// 'item that is the subject of two relations identifies correct object URIs'
|
// 'item that is the subject of two relations identifies correct object URIs'
|
||||||
// );
|
// );
|
||||||
|
|
||||||
// translatorItem = yield getter.nextItem();
|
// translatorItem = getter.nextItem();
|
||||||
// assert.isObject(translatorItem.relations, 'item that is the object of one relation from item with two relations has a relations object');
|
// assert.isObject(translatorItem.relations, 'item that is the object of one relation from item with two relations has a relations object');
|
||||||
// assert.equal(Object.keys(translatorItem.relations).length, 1, 'item that is the object of one relation from item with two relations list one relations predicate');
|
// assert.equal(Object.keys(translatorItem.relations).length, 1, 'item that is the object of one relation from item with two relations list one relations predicate');
|
||||||
// assert.isDefined(translatorItem.relations['dc:relation'], 'item that is the object of one relation from item with two relations uses "dc:relation" as the predicate');
|
// assert.isDefined(translatorItem.relations['dc:relation'], 'item that is the object of one relation from item with two relations uses "dc:relation" as the predicate');
|
||||||
|
@ -791,7 +791,7 @@ describe("Zotero.Translate.ItemGetter", function() {
|
||||||
let legacy = getter.legacy = legacyMode[i];
|
let legacy = getter.legacy = legacyMode[i];
|
||||||
let suffix = legacy ? ' in legacy mode' : '';
|
let suffix = legacy ? ' in legacy mode' : '';
|
||||||
|
|
||||||
let translatorNote = yield getter.nextItem();
|
let translatorNote = getter.nextItem();
|
||||||
assert.isDefined(translatorNote, 'returns standalone note' + suffix);
|
assert.isDefined(translatorNote, 'returns standalone note' + suffix);
|
||||||
assert.equal(translatorNote.itemType, 'note', 'itemType is correct' + suffix);
|
assert.equal(translatorNote.itemType, 'note', 'itemType is correct' + suffix);
|
||||||
assert.equal(translatorNote.note, 'Note', 'note is correct' + suffix);
|
assert.equal(translatorNote.note, 'Note', 'note is correct' + suffix);
|
||||||
|
@ -881,7 +881,7 @@ describe("Zotero.Translate.ItemGetter", function() {
|
||||||
let legacy = getter.legacy = legacyMode[i];
|
let legacy = getter.legacy = legacyMode[i];
|
||||||
let suffix = legacy ? ' in legacy mode' : '';
|
let suffix = legacy ? ' in legacy mode' : '';
|
||||||
|
|
||||||
let translatorItem = yield getter.nextItem();
|
let translatorItem = getter.nextItem();
|
||||||
assert.isArray(translatorItem.notes, 'item with no notes contains notes array' + suffix);
|
assert.isArray(translatorItem.notes, 'item with no notes contains notes array' + suffix);
|
||||||
assert.equal(translatorItem.notes.length, 0, 'item with no notes contains empty notes array' + suffix);
|
assert.equal(translatorItem.notes.length, 0, 'item with no notes contains empty notes array' + suffix);
|
||||||
|
|
||||||
|
@ -892,7 +892,7 @@ describe("Zotero.Translate.ItemGetter", function() {
|
||||||
getter._itemsLeft = [item];
|
getter._itemsLeft = [item];
|
||||||
getter.legacy = legacy;
|
getter.legacy = legacy;
|
||||||
|
|
||||||
translatorItem = yield getter.nextItem();
|
translatorItem = getter.nextItem();
|
||||||
assert.isArray(translatorItem.notes, 'item with no notes contains notes array' + suffix);
|
assert.isArray(translatorItem.notes, 'item with no notes contains notes array' + suffix);
|
||||||
assert.equal(translatorItem.notes.length, 1, 'item with one note contains array with one note' + suffix);
|
assert.equal(translatorItem.notes.length, 1, 'item with one note contains array with one note' + suffix);
|
||||||
|
|
||||||
|
@ -1007,7 +1007,7 @@ describe("Zotero.Translate.ItemGetter", function() {
|
||||||
// since tests are mostly the same
|
// since tests are mostly the same
|
||||||
let translatorAttachments = [], translatorItem;
|
let translatorAttachments = [], translatorItem;
|
||||||
let itemsLeft = items.length, attachmentsLeft = attachments.length;
|
let itemsLeft = items.length, attachmentsLeft = attachments.length;
|
||||||
while (translatorItem = yield getter.nextItem()) {
|
while (translatorItem = getter.nextItem()) {
|
||||||
assert.isString(translatorItem.itemType, 'itemType is set' + suffix);
|
assert.isString(translatorItem.itemType, 'itemType is set' + suffix);
|
||||||
|
|
||||||
// Standalone attachments
|
// Standalone attachments
|
||||||
|
|
Loading…
Reference in New Issue
Block a user