fx-compat: DB.executeTransaction() no longer takes generator functions
This commit is contained in:
parent
ccbc785499
commit
03242e8984
41 changed files with 319 additions and 320 deletions
|
@ -223,15 +223,15 @@
|
|||
ps.alert(null, "", "You cannot relate items in different libraries.");
|
||||
return;
|
||||
}
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
for (let relItem of relItems) {
|
||||
if (this.item.addRelatedItem(relItem)) {
|
||||
yield this.item.save({
|
||||
await this.item.save({
|
||||
skipDateModifiedUpdate: true
|
||||
});
|
||||
}
|
||||
if (relItem.addRelatedItem(this.item)) {
|
||||
yield relItem.save({
|
||||
await relItem.save({
|
||||
skipDateModifiedUpdate: true
|
||||
});
|
||||
}
|
||||
|
@ -246,14 +246,14 @@
|
|||
return Zotero.spawn(function* () {
|
||||
var item = yield Zotero.Items.getAsync(id);
|
||||
if (item) {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
if (this.item.removeRelatedItem(item)) {
|
||||
yield this.item.save({
|
||||
await this.item.save({
|
||||
skipDateModifiedUpdate: true
|
||||
});
|
||||
}
|
||||
if (item.removeRelatedItem(this.item)) {
|
||||
yield item.save({
|
||||
await item.save({
|
||||
skipDateModifiedUpdate: true
|
||||
});
|
||||
}
|
||||
|
|
|
@ -576,7 +576,7 @@ Zotero.TagSelector = class TagSelectorContainer extends React.PureComponent {
|
|||
// Remove tags on Cmd-drag/Shift-drag
|
||||
var remove = (Zotero.isMac && event.metaKey) || (!Zotero.isMac && event.shiftKey);
|
||||
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
return Zotero.DB.executeTransaction(async function () {
|
||||
ids = ids.split(',');
|
||||
var items = Zotero.Items.get(ids);
|
||||
var value = elem.textContent;
|
||||
|
@ -589,7 +589,7 @@ Zotero.TagSelector = class TagSelectorContainer extends React.PureComponent {
|
|||
else {
|
||||
item.addTag(value);
|
||||
}
|
||||
yield item.save();
|
||||
await item.save();
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
|
|
|
@ -850,7 +850,7 @@ Zotero_Preferences.Attachment_Base_Directory = {
|
|||
Object.keys(newAttachmentPaths),
|
||||
100,
|
||||
function (chunk) {
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
return Zotero.DB.executeTransaction(async function () {
|
||||
for (let id of chunk) {
|
||||
let attachment = Zotero.Items.get(id);
|
||||
if (newAttachmentPaths[id]) {
|
||||
|
@ -859,7 +859,7 @@ Zotero_Preferences.Attachment_Base_Directory = {
|
|||
else {
|
||||
attachment.attachmentPath = attachment.getFilePath();
|
||||
}
|
||||
yield attachment.save({
|
||||
await attachment.save({
|
||||
skipDateModifiedUpdate: true
|
||||
});
|
||||
}
|
||||
|
@ -927,11 +927,11 @@ Zotero_Preferences.Attachment_Base_Directory = {
|
|||
relativeAttachmentIDs,
|
||||
100,
|
||||
function (chunk) {
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
return Zotero.DB.executeTransaction(async function () {
|
||||
for (let id of chunk) {
|
||||
let attachment = yield Zotero.Items.getAsync(id);
|
||||
let attachment = await Zotero.Items.getAsync(id);
|
||||
attachment.attachmentPath = attachment.getFilePath();
|
||||
yield attachment.save({
|
||||
await attachment.save({
|
||||
skipDateModifiedUpdate: true
|
||||
});
|
||||
}
|
||||
|
|
|
@ -722,10 +722,10 @@ Zotero_Preferences.Sync = {
|
|||
switch (index) {
|
||||
case 0:
|
||||
let libraries = Zotero.Libraries.getAll().filter(library => library.syncable);
|
||||
await Zotero.DB.executeTransaction(function* () {
|
||||
await Zotero.DB.executeTransaction(async function () {
|
||||
for (let library of libraries) {
|
||||
library.libraryVersion = -1;
|
||||
yield library.save();
|
||||
await library.save();
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
|
|
@ -84,7 +84,7 @@ Zotero.Attachments = new function(){
|
|||
|
||||
var attachmentItem, itemID, newFile, contentType, destDir;
|
||||
try {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
// Create a new attachment
|
||||
attachmentItem = new Zotero.Item('attachment');
|
||||
if (parentItemID) {
|
||||
|
@ -101,34 +101,34 @@ Zotero.Attachments = new function(){
|
|||
if (collections) {
|
||||
attachmentItem.setCollections(collections);
|
||||
}
|
||||
yield attachmentItem.save(saveOptions);
|
||||
await attachmentItem.save(saveOptions);
|
||||
|
||||
// Create directory for attachment files within storage directory
|
||||
destDir = yield this.createDirectoryForItem(attachmentItem);
|
||||
destDir = await this.createDirectoryForItem(attachmentItem);
|
||||
|
||||
// Point to copied file
|
||||
newFile = OS.Path.join(destDir, newName);
|
||||
|
||||
// Copy or move file to unique filename, which automatically shortens long filenames
|
||||
if (options.moveFile) {
|
||||
const newFilePath = yield Zotero.File.moveToUnique(file.path, newFile);
|
||||
const newFilePath = await Zotero.File.moveToUnique(file.path, newFile);
|
||||
newFile = Zotero.File.pathToFile(newFilePath);
|
||||
}
|
||||
else {
|
||||
newFile = Zotero.File.copyToUnique(file, newFile);
|
||||
}
|
||||
|
||||
yield Zotero.File.setNormalFilePermissions(newFile.path);
|
||||
await Zotero.File.setNormalFilePermissions(newFile.path);
|
||||
|
||||
if (!contentType) {
|
||||
contentType = yield Zotero.MIME.getMIMETypeFromFile(newFile);
|
||||
contentType = await Zotero.MIME.getMIMETypeFromFile(newFile);
|
||||
}
|
||||
attachmentItem.attachmentContentType = contentType;
|
||||
if (charset) {
|
||||
attachmentItem.attachmentCharset = charset;
|
||||
}
|
||||
attachmentItem.attachmentPath = newFile.path;
|
||||
yield attachmentItem.save(saveOptions);
|
||||
await attachmentItem.save(saveOptions);
|
||||
}.bind(this));
|
||||
try {
|
||||
yield _postProcessFile(attachmentItem, newFile, contentType);
|
||||
|
@ -296,7 +296,7 @@ Zotero.Attachments = new function(){
|
|||
|
||||
var attachmentItem, itemID, destDir, newPath;
|
||||
try {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
// Create a new attachment
|
||||
attachmentItem = new Zotero.Item('attachment');
|
||||
let {libraryID, key: parentKey} = Zotero.Items.getLibraryAndKeyFromID(parentItemID);
|
||||
|
@ -312,20 +312,20 @@ Zotero.Attachments = new function(){
|
|||
// DEBUG: this should probably insert access date too so as to
|
||||
// create a proper item, but at the moment this is only called by
|
||||
// translate.js, which sets the metadata fields itself
|
||||
itemID = yield attachmentItem.save(saveOptions);
|
||||
itemID = await attachmentItem.save(saveOptions);
|
||||
|
||||
var storageDir = Zotero.getStorageDirectory();
|
||||
destDir = this.getStorageDirectory(attachmentItem);
|
||||
yield OS.File.removeDir(destDir.path);
|
||||
await OS.File.removeDir(destDir.path);
|
||||
newPath = OS.Path.join(destDir.path, fileName);
|
||||
// Copy single file to new directory
|
||||
if (options.singleFile) {
|
||||
yield this.createDirectoryForItem(attachmentItem);
|
||||
await this.createDirectoryForItem(attachmentItem);
|
||||
if (options.moveFile) {
|
||||
yield OS.File.move(file.path, newPath);
|
||||
await OS.File.move(file.path, newPath);
|
||||
}
|
||||
else {
|
||||
yield OS.File.copy(file.path, newPath);
|
||||
await OS.File.copy(file.path, newPath);
|
||||
}
|
||||
}
|
||||
// Copy entire parent directory (for HTML snapshots)
|
||||
|
@ -928,7 +928,7 @@ Zotero.Attachments = new function(){
|
|||
|
||||
var attachmentItem;
|
||||
var destDir;
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
// Create a new attachment
|
||||
attachmentItem = new Zotero.Item('attachment');
|
||||
if (libraryID) {
|
||||
|
@ -950,12 +950,12 @@ Zotero.Attachments = new function(){
|
|||
attachmentItem.setCollections(collections);
|
||||
}
|
||||
attachmentItem.attachmentPath = 'storage:' + fileName;
|
||||
var itemID = yield attachmentItem.save(saveOptions);
|
||||
var itemID = await attachmentItem.save(saveOptions);
|
||||
|
||||
Zotero.Fulltext.queueItem(attachmentItem);
|
||||
|
||||
destDir = this.getStorageDirectory(attachmentItem).path;
|
||||
yield OS.File.move(tmpDir, destDir);
|
||||
await OS.File.move(tmpDir, destDir);
|
||||
}.bind(this));
|
||||
}
|
||||
catch (e) {
|
||||
|
@ -2876,7 +2876,7 @@ Zotero.Attachments = new function(){
|
|||
var collections = options.collections;
|
||||
var saveOptions = options.saveOptions;
|
||||
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
return Zotero.DB.executeTransaction(async function () {
|
||||
var attachmentItem = new Zotero.Item('attachment');
|
||||
if (parentItemID) {
|
||||
let {libraryID: parentLibraryID, key: parentKey} =
|
||||
|
@ -2904,7 +2904,7 @@ Zotero.Attachments = new function(){
|
|||
if (collections) {
|
||||
attachmentItem.setCollections(collections);
|
||||
}
|
||||
yield attachmentItem.save(saveOptions);
|
||||
await attachmentItem.save(saveOptions);
|
||||
|
||||
return attachmentItem;
|
||||
}.bind(this));
|
||||
|
|
|
@ -936,10 +936,10 @@ Zotero.DataObject.prototype.save = Zotero.Promise.coroutine(function* (options =
|
|||
// Create transaction
|
||||
let result
|
||||
if (env.options.tx) {
|
||||
result = yield Zotero.DB.executeTransaction(function* () {
|
||||
result = yield Zotero.DB.executeTransaction(async function () {
|
||||
Zotero.DataObject.prototype._saveData.call(this, env);
|
||||
yield this._saveData(env);
|
||||
yield Zotero.DataObject.prototype._finalizeSave.call(this, env);
|
||||
await this._saveData(env);
|
||||
await Zotero.DataObject.prototype._finalizeSave.call(this, env);
|
||||
return this._finalizeSave(env);
|
||||
}.bind(this), env.transactionOptions);
|
||||
}
|
||||
|
@ -1261,9 +1261,9 @@ Zotero.DataObject.prototype.erase = Zotero.Promise.coroutine(function* (options
|
|||
Zotero.debug('Deleting ' + this.objectType + ' ' + this.id);
|
||||
|
||||
if (env.options.tx) {
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
yield this._eraseData(env);
|
||||
yield this._finalizeErase(env);
|
||||
return Zotero.DB.executeTransaction(async function () {
|
||||
await this._eraseData(env);
|
||||
await this._finalizeErase(env);
|
||||
}.bind(this))
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -1110,13 +1110,13 @@ Zotero.DataObjects.prototype.getPrimaryDataSQLPart = function (part) {
|
|||
*/
|
||||
Zotero.DataObjects.prototype.erase = Zotero.Promise.coroutine(function* (ids, options = {}) {
|
||||
ids = Zotero.flattenArguments(ids);
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
let obj = yield this.getAsync(ids[i]);
|
||||
let obj = await this.getAsync(ids[i]);
|
||||
if (!obj) {
|
||||
continue;
|
||||
}
|
||||
yield obj.erase(options);
|
||||
await obj.erase(options);
|
||||
if (options.onProgress) {
|
||||
options.onProgress(i + 1, ids.length);
|
||||
}
|
||||
|
|
|
@ -487,10 +487,10 @@ Zotero.Feed.prototype._updateFeed = Zotero.Promise.coroutine(function* () {
|
|||
this._set('_feedLastCheckError', e.message || 'Error processing feed');
|
||||
}
|
||||
if (toSave.length) {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
// Save in reverse order
|
||||
for (let i=toSave.length-1; i>=0; i--) {
|
||||
yield toSave[i].save();
|
||||
await toSave[i].save();
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -145,9 +145,9 @@ Zotero.Feeds = new function() {
|
|||
newFeeds.push(feed);
|
||||
}
|
||||
// This could potentially be a massive list, so we save in a transaction.
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
for (let feed of newFeeds) {
|
||||
yield feed.save({
|
||||
await feed.save({
|
||||
skipSelect: true
|
||||
});
|
||||
}
|
||||
|
|
|
@ -460,11 +460,11 @@ Zotero.Items = function() {
|
|||
);
|
||||
|
||||
if (notesToUpdate.length) {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
for (let i = 0; i < notesToUpdate.length; i++) {
|
||||
let row = notesToUpdate[i];
|
||||
let sql = "UPDATE itemNotes SET note=? WHERE itemID=?";
|
||||
yield Zotero.DB.queryAsync(sql, [row[1], row[0]]);
|
||||
await Zotero.DB.queryAsync(sql, [row[1], row[0]]);
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
|
@ -947,16 +947,16 @@ Zotero.Items = function() {
|
|||
this.merge = function (item, otherItems) {
|
||||
Zotero.debug("Merging items");
|
||||
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
return Zotero.DB.executeTransaction(async function () {
|
||||
var replPred = Zotero.Relations.replacedItemPredicate;
|
||||
var toSave = {};
|
||||
toSave[item.id] = item;
|
||||
|
||||
var earliestDateAdded = item.dateAdded;
|
||||
|
||||
let remapAttachmentKeys = yield this._mergePDFAttachments(item, otherItems);
|
||||
yield this._mergeWebAttachments(item, otherItems);
|
||||
yield this._mergeOtherAttachments(item, otherItems);
|
||||
let remapAttachmentKeys = await this._mergePDFAttachments(item, otherItems);
|
||||
await this._mergeWebAttachments(item, otherItems);
|
||||
await this._mergeOtherAttachments(item, otherItems);
|
||||
|
||||
for (let otherItem of otherItems) {
|
||||
if (otherItem.libraryID !== item.libraryID) {
|
||||
|
@ -971,7 +971,7 @@ Zotero.Items = function() {
|
|||
// Move notes to master
|
||||
var noteIDs = otherItem.getNotes(true);
|
||||
for (let id of noteIDs) {
|
||||
var note = yield this.getAsync(id);
|
||||
var note = await this.getAsync(id);
|
||||
note.parentItemID = item.id;
|
||||
Zotero.Notes.replaceItemKey(note, otherItem.key, item.key);
|
||||
Zotero.Notes.replaceAllItemKeys(note, remapAttachmentKeys);
|
||||
|
@ -979,9 +979,8 @@ Zotero.Items = function() {
|
|||
}
|
||||
|
||||
// Move relations to master
|
||||
yield this._moveRelations(otherItem, item);
|
||||
await this._moveRelations(otherItem, item);
|
||||
|
||||
// All other operations are additive only and do not affect the
|
||||
// old item, which will be put in the trash
|
||||
|
||||
// Add collections to master
|
||||
|
@ -1016,10 +1015,10 @@ Zotero.Items = function() {
|
|||
|
||||
// Hack to remove master item from duplicates view without recalculating duplicates
|
||||
// Pass force = true so observers will be notified before this transaction is committed
|
||||
yield Zotero.Notifier.trigger('removeDuplicatesMaster', 'item', item.id, null, true);
|
||||
await Zotero.Notifier.trigger('removeDuplicatesMaster', 'item', item.id, null, true);
|
||||
|
||||
for (let i in toSave) {
|
||||
yield toSave[i].save();
|
||||
await toSave[i].save();
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
|
@ -1416,7 +1415,7 @@ Zotero.Items = function() {
|
|||
|
||||
|
||||
this.trashTx = function (ids) {
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
return Zotero.DB.executeTransaction(async function () {
|
||||
return this.trash(ids);
|
||||
}.bind(this));
|
||||
}
|
||||
|
@ -1542,7 +1541,7 @@ Zotero.Items = function() {
|
|||
this.addToPublications = function (items, options = {}) {
|
||||
if (!items.length) return;
|
||||
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
return Zotero.DB.executeTransaction(async function () {
|
||||
var timestamp = Zotero.DB.transactionTimestamp;
|
||||
|
||||
var allItems = [...items];
|
||||
|
@ -1586,7 +1585,7 @@ Zotero.Items = function() {
|
|||
}
|
||||
}
|
||||
|
||||
yield Zotero.Utilities.Internal.forEachChunkAsync(allItems, 250, Zotero.Promise.coroutine(function* (chunk) {
|
||||
await Zotero.Utilities.Internal.forEachChunkAsync(allItems, 250, Zotero.Promise.coroutine(function* (chunk) {
|
||||
for (let item of chunk) {
|
||||
item.setPublications(true);
|
||||
item.synced = false;
|
||||
|
@ -1606,7 +1605,7 @@ Zotero.Items = function() {
|
|||
|
||||
|
||||
this.removeFromPublications = function (items) {
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
return Zotero.DB.executeTransaction(async function () {
|
||||
let allItems = [];
|
||||
for (let item of items) {
|
||||
if (!item.inPublications) {
|
||||
|
@ -1627,7 +1626,7 @@ Zotero.Items = function() {
|
|||
});
|
||||
|
||||
var timestamp = Zotero.DB.transactionTimestamp;
|
||||
yield Zotero.Utilities.Internal.forEachChunkAsync(allItems, 250, Zotero.Promise.coroutine(function* (chunk) {
|
||||
await Zotero.Utilities.Internal.forEachChunkAsync(allItems, 250, Zotero.Promise.coroutine(function* (chunk) {
|
||||
let idStr = chunk.map(item => item.id).join(", ");
|
||||
yield Zotero.DB.queryAsync(
|
||||
`UPDATE items SET synced=0, clientDateModified=? WHERE itemID IN (${idStr})`,
|
||||
|
|
|
@ -462,9 +462,9 @@ Zotero.Library.prototype.save = Zotero.Promise.coroutine(function* (options) {
|
|||
|
||||
// Create transaction
|
||||
if (env.options.tx) {
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
yield this._saveData(env);
|
||||
yield this._finalizeSave(env);
|
||||
return Zotero.DB.executeTransaction(async function () {
|
||||
await this._saveData(env);
|
||||
await this._finalizeSave(env);
|
||||
}.bind(this), env.transactionOptions);
|
||||
}
|
||||
// Use existing transaction
|
||||
|
@ -598,9 +598,9 @@ Zotero.Library.prototype.erase = Zotero.Promise.coroutine(function* (options) {
|
|||
env.notifierData = {};
|
||||
|
||||
if (env.options.tx) {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield this._eraseData(env);
|
||||
yield this._finalizeErase(env);
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
await this._eraseData(env);
|
||||
await this._finalizeErase(env);
|
||||
}.bind(this), env.transactionOptions);
|
||||
} else {
|
||||
Zotero.DB.requireTransaction();
|
||||
|
|
|
@ -247,11 +247,11 @@ Zotero.Tags = new function() {
|
|||
// we can assign it to the new name
|
||||
var oldColorData = this.getColor(libraryID, oldName);
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
var oldItemIDs = yield this.getTagItems(libraryID, oldTagID);
|
||||
var newTagID = yield this.create(newName);
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
var oldItemIDs = await this.getTagItems(libraryID, oldTagID);
|
||||
var newTagID = await this.create(newName);
|
||||
|
||||
yield Zotero.Utilities.Internal.forEachChunkAsync(
|
||||
await Zotero.Utilities.Internal.forEachChunkAsync(
|
||||
oldItemIDs,
|
||||
Zotero.DB.MAX_BOUND_PARAMETERS - 2,
|
||||
Zotero.Promise.coroutine(function* (chunk) {
|
||||
|
@ -291,16 +291,16 @@ Zotero.Tags = new function() {
|
|||
notifierData
|
||||
);
|
||||
|
||||
yield this.purge(oldTagID);
|
||||
await this.purge(oldTagID);
|
||||
}.bind(this));
|
||||
|
||||
if (oldColorData) {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
// Remove color from old tag
|
||||
yield this.setColor(libraryID, oldName);
|
||||
await this.setColor(libraryID, oldName);
|
||||
|
||||
// Add color to new tag
|
||||
yield this.setColor(
|
||||
await this.setColor(
|
||||
libraryID,
|
||||
newName,
|
||||
oldColorData.color,
|
||||
|
@ -335,7 +335,7 @@ Zotero.Tags = new function() {
|
|||
tagIDs,
|
||||
100,
|
||||
async function (chunk) {
|
||||
await Zotero.DB.executeTransaction(function* () {
|
||||
await Zotero.DB.executeTransaction(async function () {
|
||||
var rowIDs = [];
|
||||
var itemIDs = [];
|
||||
var uniqueTags = new Set();
|
||||
|
@ -351,7 +351,7 @@ Zotero.Tags = new function() {
|
|||
sql += 'AND type IN (' + types.join(', ') + ') ';
|
||||
}
|
||||
sql += 'ORDER BY tagID, type';
|
||||
var rows = yield Zotero.DB.queryAsync(sql, [libraryID, ...chunk]);
|
||||
var rows = await Zotero.DB.queryAsync(sql, [libraryID, ...chunk]);
|
||||
for (let { rowID, tagID, itemID, type } of rows) {
|
||||
uniqueTags.add(tagID);
|
||||
|
||||
|
@ -374,7 +374,7 @@ Zotero.Tags = new function() {
|
|||
// If we're deleting the tag and not just a specific type, also clear any
|
||||
// tag color
|
||||
if (colors.has(name) && !types) {
|
||||
yield this.setColor(libraryID, name, false);
|
||||
await this.setColor(libraryID, name, false);
|
||||
}
|
||||
}
|
||||
if (itemIDs.length) {
|
||||
|
@ -382,12 +382,12 @@ Zotero.Tags = new function() {
|
|||
}
|
||||
|
||||
sql = "DELETE FROM itemTags WHERE ROWID IN (" + rowIDs.join(", ") + ")";
|
||||
yield Zotero.DB.queryAsync(sql, false, { noCache: true });
|
||||
await Zotero.DB.queryAsync(sql, false, { noCache: true });
|
||||
|
||||
yield this.purge(chunk);
|
||||
await this.purge(chunk);
|
||||
|
||||
// Update internal timestamps on all items that had these tags
|
||||
yield Zotero.Utilities.Internal.forEachChunkAsync(
|
||||
await Zotero.Utilities.Internal.forEachChunkAsync(
|
||||
Zotero.Utilities.arrayUnique(itemIDs),
|
||||
Zotero.DB.MAX_BOUND_PARAMETERS - 1,
|
||||
async function (chunk) {
|
||||
|
|
|
@ -281,9 +281,9 @@ Zotero.Fulltext = Zotero.FullText = new function(){
|
|||
yield Zotero.DB.waitForTransaction('indexString()');
|
||||
}
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
this.clearItemWords(itemID, true);
|
||||
yield indexWords(itemID, words, stats, version, synced);
|
||||
await indexWords(itemID, words, stats, version, synced);
|
||||
|
||||
/*
|
||||
var sql = "REPLACE INTO fulltextContent (itemID, textContent) VALUES (?,?)";
|
||||
|
@ -698,8 +698,8 @@ Zotero.Fulltext = Zotero.FullText = new function(){
|
|||
+ `${libraryKey} (contentType: ${contentType})`, 2);
|
||||
|
||||
// Delete rows for items that weren't supposed to be indexed
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield this.clearItemWords(itemID);
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
await this.clearItemWords(itemID);
|
||||
}.bind(this));
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -388,16 +388,16 @@ Zotero.Proxy.prototype.save = Zotero.Promise.coroutine(function* (transparent) {
|
|||
this.compileRegexp();
|
||||
|
||||
if(transparent) {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
if(this.proxyID) {
|
||||
yield Zotero.DB.queryAsync(
|
||||
await Zotero.DB.queryAsync(
|
||||
"UPDATE proxies SET multiHost = ?, autoAssociate = ?, scheme = ? WHERE proxyID = ?",
|
||||
[this.multiHost ? 1 : 0, this.autoAssociate ? 1 : 0, this.scheme, this.proxyID]
|
||||
);
|
||||
yield Zotero.DB.queryAsync("DELETE FROM proxyHosts WHERE proxyID = ?", [this.proxyID]);
|
||||
await Zotero.DB.queryAsync("DELETE FROM proxyHosts WHERE proxyID = ?", [this.proxyID]);
|
||||
} else {
|
||||
let id = Zotero.ID.get('proxies');
|
||||
yield Zotero.DB.queryAsync(
|
||||
await Zotero.DB.queryAsync(
|
||||
"INSERT INTO proxies (proxyID, multiHost, autoAssociate, scheme) VALUES (?, ?, ?, ?)",
|
||||
[id, this.multiHost ? 1 : 0, this.autoAssociate ? 1 : 0, this.scheme]
|
||||
);
|
||||
|
@ -408,7 +408,7 @@ Zotero.Proxy.prototype.save = Zotero.Promise.coroutine(function* (transparent) {
|
|||
var host;
|
||||
for(var i in this.hosts) {
|
||||
host = this.hosts[i] = this.hosts[i].toLowerCase();
|
||||
yield Zotero.DB.queryAsync(
|
||||
await Zotero.DB.queryAsync(
|
||||
"INSERT INTO proxyHosts (proxyID, hostname) VALUES (?, ?)",
|
||||
[this.proxyID, host]
|
||||
);
|
||||
|
@ -441,9 +441,9 @@ Zotero.Proxy.prototype.erase = Zotero.Promise.coroutine(function* () {
|
|||
Zotero.Proxies.remove(this);
|
||||
|
||||
if(this.proxyID) {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.queryAsync("DELETE FROM proxyHosts WHERE proxyID = ?", [this.proxyID]);
|
||||
yield Zotero.DB.queryAsync("DELETE FROM proxies WHERE proxyID = ?", [this.proxyID]);
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
await Zotero.DB.queryAsync("DELETE FROM proxyHosts WHERE proxyID = ?", [this.proxyID]);
|
||||
await Zotero.DB.queryAsync("DELETE FROM proxies WHERE proxyID = ?", [this.proxyID]);
|
||||
}.bind(this));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -733,8 +733,8 @@ Zotero.Schema = new function(){
|
|||
|
||||
var itemTypeID = Zotero.ID.get('customItemTypes');
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.queryAsync("INSERT INTO customItemTypes VALUES (?, 'nsfReviewer', 'NSF Reviewer', 1, 'chrome://zotero/skin/report_user.png')", itemTypeID);
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
await Zotero.DB.queryAsync("INSERT INTO customItemTypes VALUES (?, 'nsfReviewer', 'NSF Reviewer', 1, 'chrome://zotero/skin/report_user.png')", itemTypeID);
|
||||
|
||||
var fields = [
|
||||
['name', 'Name'],
|
||||
|
@ -754,11 +754,11 @@ Zotero.Schema = new function(){
|
|||
var fieldID = Zotero.ItemFields.getID(fields[i][0]);
|
||||
if (!fieldID) {
|
||||
var fieldID = Zotero.ID.get('customFields');
|
||||
yield Zotero.DB.queryAsync("INSERT INTO customFields VALUES (?, ?, ?)", [fieldID, fields[i][0], fields[i][1]]);
|
||||
yield Zotero.DB.queryAsync("INSERT INTO customItemTypeFields VALUES (?, NULL, ?, 1, ?)", [itemTypeID, fieldID, i+1]);
|
||||
await Zotero.DB.queryAsync("INSERT INTO customFields VALUES (?, ?, ?)", [fieldID, fields[i][0], fields[i][1]]);
|
||||
await Zotero.DB.queryAsync("INSERT INTO customItemTypeFields VALUES (?, NULL, ?, 1, ?)", [itemTypeID, fieldID, i+1]);
|
||||
}
|
||||
else {
|
||||
yield Zotero.DB.queryAsync("INSERT INTO customItemTypeFields VALUES (?, ?, NULL, 1, ?)", [itemTypeID, fieldID, i+1]);
|
||||
await Zotero.DB.queryAsync("INSERT INTO customItemTypeFields VALUES (?, ?, NULL, 1, ?)", [itemTypeID, fieldID, i+1]);
|
||||
}
|
||||
|
||||
switch (fields[i][0]) {
|
||||
|
@ -779,11 +779,11 @@ Zotero.Schema = new function(){
|
|||
}
|
||||
|
||||
if (baseFieldID) {
|
||||
yield Zotero.DB.queryAsync("INSERT INTO customBaseFieldMappings VALUES (?, ?, ?)", [itemTypeID, baseFieldID, fieldID]);
|
||||
await Zotero.DB.queryAsync("INSERT INTO customBaseFieldMappings VALUES (?, ?, ?)", [itemTypeID, baseFieldID, fieldID]);
|
||||
}
|
||||
}
|
||||
|
||||
yield _reloadSchema();
|
||||
await _reloadSchema();
|
||||
}, { disableForeignKeys: true });
|
||||
|
||||
var s = new Zotero.Search;
|
||||
|
@ -814,25 +814,25 @@ Zotero.Schema = new function(){
|
|||
}
|
||||
|
||||
Zotero.debug("Uninstalling nsfReviewer item type");
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.queryAsync("DELETE FROM customItemTypeFields WHERE customItemTypeID=?", itemTypeID - Zotero.ItemTypes.customIDOffset);
|
||||
yield Zotero.DB.queryAsync("DELETE FROM customBaseFieldMappings WHERE customItemTypeID=?", itemTypeID - Zotero.ItemTypes.customIDOffset);
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
await Zotero.DB.queryAsync("DELETE FROM customItemTypeFields WHERE customItemTypeID=?", itemTypeID - Zotero.ItemTypes.customIDOffset);
|
||||
await Zotero.DB.queryAsync("DELETE FROM customBaseFieldMappings WHERE customItemTypeID=?", itemTypeID - Zotero.ItemTypes.customIDOffset);
|
||||
var fields = Zotero.ItemFields.getItemTypeFields(itemTypeID);
|
||||
for (let fieldID of fields) {
|
||||
if (Zotero.ItemFields.isCustom(fieldID)) {
|
||||
yield Zotero.DB.queryAsync("DELETE FROM customFields WHERE customFieldID=?", fieldID - Zotero.ItemTypes.customIDOffset);
|
||||
await Zotero.DB.queryAsync("DELETE FROM customFields WHERE customFieldID=?", fieldID - Zotero.ItemTypes.customIDOffset);
|
||||
}
|
||||
}
|
||||
yield Zotero.DB.queryAsync("DELETE FROM customItemTypes WHERE customItemTypeID=?", itemTypeID - Zotero.ItemTypes.customIDOffset);
|
||||
await Zotero.DB.queryAsync("DELETE FROM customItemTypes WHERE customItemTypeID=?", itemTypeID - Zotero.ItemTypes.customIDOffset);
|
||||
|
||||
var searches = Zotero.Searches.getByLibrary(Zotero.Libraries.userLibraryID);
|
||||
for (let search of searches) {
|
||||
if (search.name == 'Overdue NSF Reviewers') {
|
||||
yield search.erase();
|
||||
await search.erase();
|
||||
}
|
||||
}
|
||||
|
||||
yield _reloadSchema();
|
||||
await _reloadSchema();
|
||||
}.bind(this), { disableForeignKeys: true });
|
||||
|
||||
ps.alert(null, "Zotero Item Type Removed", "The 'NSF Reviewer' item type has been uninstalled.");
|
||||
|
|
|
@ -301,9 +301,9 @@ Zotero.Sync.Storage.Local = {
|
|||
}
|
||||
// Update sync states in bulk
|
||||
if (changed) {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
for (let state in statesToSet) {
|
||||
yield this.updateSyncStates(statesToSet[state], parseInt(state));
|
||||
await this.updateSyncStates(statesToSet[state], parseInt(state));
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
|
@ -1052,7 +1052,7 @@ Zotero.Sync.Storage.Local = {
|
|||
return false;
|
||||
}
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
for (let i = 0; i < conflicts.length; i++) {
|
||||
let conflict = conflicts[i];
|
||||
// TEMP
|
||||
|
@ -1080,7 +1080,7 @@ Zotero.Sync.Storage.Local = {
|
|||
syncState = this.SYNC_STATE_FORCE_DOWNLOAD;
|
||||
}
|
||||
item.attachmentSyncState = syncState;
|
||||
yield item.save({ skipAll: true });
|
||||
await item.save({ skipAll: true });
|
||||
}
|
||||
}.bind(this));
|
||||
return true;
|
||||
|
|
|
@ -952,7 +952,7 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
|
|||
toPurge,
|
||||
Zotero.DB.MAX_BOUND_PARAMETERS - 1,
|
||||
function (chunk) {
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
return Zotero.DB.executeTransaction(async function () {
|
||||
var sql = "DELETE FROM storageDeleteLog WHERE libraryID=? AND key IN ("
|
||||
+ chunk.map(() => '?').join() + ")";
|
||||
return Zotero.DB.queryAsync(sql, [libraryID].concat(chunk));
|
||||
|
|
|
@ -815,15 +815,15 @@ Zotero.Sync.Storage.Mode.ZFS.prototype = {
|
|||
*/
|
||||
_updateItemFileInfo: Zotero.Promise.coroutine(function* (item, params) {
|
||||
// Mark as in-sync
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
// Store file mod time and hash
|
||||
item.attachmentSyncedModificationTime = params.mtime;
|
||||
item.attachmentSyncedHash = params.md5;
|
||||
item.attachmentSyncState = "in_sync";
|
||||
yield item.save({ skipAll: true });
|
||||
await item.save({ skipAll: true });
|
||||
|
||||
// Update sync cache with new file metadata and version from server
|
||||
var json = yield Zotero.Sync.Data.Local.getCacheObject(
|
||||
var json = await Zotero.Sync.Data.Local.getCacheObject(
|
||||
'item', item.libraryID, item.key, item.version
|
||||
);
|
||||
if (json) {
|
||||
|
@ -831,10 +831,10 @@ Zotero.Sync.Storage.Mode.ZFS.prototype = {
|
|||
json.data.version = params.version;
|
||||
json.data.mtime = params.mtime;
|
||||
json.data.md5 = params.md5;
|
||||
yield Zotero.Sync.Data.Local.saveCacheObject('item', item.libraryID, json);
|
||||
await Zotero.Sync.Data.Local.saveCacheObject('item', item.libraryID, json);
|
||||
}
|
||||
// Update item with new version from server
|
||||
yield Zotero.Items.updateVersion([item.id], params.version);
|
||||
await Zotero.Items.updateVersion([item.id], params.version);
|
||||
|
||||
// TODO: Can filename, contentType, and charset change the attachment item?
|
||||
});
|
||||
|
@ -1001,9 +1001,9 @@ Zotero.Sync.Storage.Mode.ZFS.prototype = {
|
|||
}
|
||||
|
||||
if (same) {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.Sync.Storage.setSyncedModificationTime(item.id, fmtime);
|
||||
yield Zotero.Sync.Storage.setSyncState(
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
await Zotero.Sync.Storage.setSyncedModificationTime(item.id, fmtime);
|
||||
await Zotero.Sync.Storage.setSyncState(
|
||||
item.id, Zotero.Sync.Storage.Local.SYNC_STATE_IN_SYNC
|
||||
);
|
||||
});
|
||||
|
|
|
@ -794,8 +794,8 @@ Zotero.Sync.Data.Engine.prototype._restoreRestoredCollectionItems = async functi
|
|||
Zotero.debug(`Restoring ${addToCollection.length} `
|
||||
+ `${Zotero.Utilities.pluralize(addToCollection.length, ['item', 'items'])} `
|
||||
+ `to restored collection ${collection.libraryKey}`);
|
||||
await Zotero.DB.executeTransaction(function* () {
|
||||
yield collection.addItems(addToCollection);
|
||||
await Zotero.DB.executeTransaction(async function () {
|
||||
await collection.addItems(addToCollection);
|
||||
}.bind(this));
|
||||
}
|
||||
if (addToQueue.length) {
|
||||
|
@ -927,7 +927,7 @@ Zotero.Sync.Data.Engine.prototype._downloadDeletions = Zotero.Promise.coroutine(
|
|||
mergeData,
|
||||
batchSize,
|
||||
function (chunk) {
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
return Zotero.DB.executeTransaction(async function () {
|
||||
for (let json of chunk) {
|
||||
let data = json.data;
|
||||
if (!data.deleted) continue;
|
||||
|
@ -937,7 +937,7 @@ Zotero.Sync.Data.Engine.prototype._downloadDeletions = Zotero.Promise.coroutine(
|
|||
+ " didn't exist after conflict resolution");
|
||||
continue;
|
||||
}
|
||||
yield obj.erase({
|
||||
await obj.erase({
|
||||
skipEditCheck: true
|
||||
});
|
||||
}
|
||||
|
@ -951,9 +951,9 @@ Zotero.Sync.Data.Engine.prototype._downloadDeletions = Zotero.Promise.coroutine(
|
|||
toDelete,
|
||||
batchSize,
|
||||
function (chunk) {
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
return Zotero.DB.executeTransaction(async function () {
|
||||
for (let obj of chunk) {
|
||||
yield obj.erase({
|
||||
await obj.erase({
|
||||
skipEditCheck: true,
|
||||
skipDeleteLog: true
|
||||
});
|
||||
|
@ -1324,9 +1324,9 @@ Zotero.Sync.Data.Engine.prototype._uploadObjects = Zotero.Promise.coroutine(func
|
|||
yield Zotero.Sync.Data.Local.saveCacheObjects(
|
||||
objectType, this.libraryID, toCache
|
||||
);
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
for (let i = 0; i < toSave.length; i++) {
|
||||
yield toSave[i].save({
|
||||
await toSave[i].save({
|
||||
skipSelect: true,
|
||||
skipSyncedUpdate: true,
|
||||
// We want to minimize the times when server writes actually result in local
|
||||
|
@ -1338,7 +1338,7 @@ Zotero.Sync.Data.Engine.prototype._uploadObjects = Zotero.Promise.coroutine(func
|
|||
this.library.storageVersion = libraryVersion;
|
||||
}
|
||||
this.library.libraryVersion = libraryVersion;
|
||||
yield this.library.save();
|
||||
await this.library.save();
|
||||
objectsClass.updateVersion(updateVersionIDs, libraryVersion);
|
||||
objectsClass.updateSynced(updateSyncedIDs, true);
|
||||
}.bind(this));
|
||||
|
@ -1514,14 +1514,14 @@ Zotero.Sync.Data.Engine.prototype._updateGroupItemUsers = async function () {
|
|||
|
||||
|
||||
Zotero.Sync.Data.Engine.prototype._getJSONForObject = function (objectType, id, options = {}) {
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
return Zotero.DB.executeTransaction(async function () {
|
||||
var objectsClass = Zotero.DataObjectUtilities.getObjectsClassForObjectType(objectType);
|
||||
var obj = objectsClass.get(id);
|
||||
var cacheObj = false;
|
||||
// If the object has been synced before, get the pristine version from the cache so we can
|
||||
// use PATCH mode and include only fields that have changed
|
||||
if (obj.version) {
|
||||
cacheObj = yield Zotero.Sync.Data.Local.getCacheObject(
|
||||
cacheObj = await Zotero.Sync.Data.Local.getCacheObject(
|
||||
objectType, obj.libraryID, obj.key, obj.version
|
||||
);
|
||||
}
|
||||
|
@ -1671,7 +1671,7 @@ Zotero.Sync.Data.Engine.prototype._upgradeCheck = Zotero.Promise.coroutine(funct
|
|||
|
||||
// Update versions on local objects modified remotely before last classic sync time,
|
||||
// to indicate that they don't need to receive remote updates
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
for (let objectType in currentVersions) {
|
||||
let objectTypePlural = Zotero.DataObjectUtilities.getObjectTypePlural(objectType);
|
||||
let objectsClass = Zotero.DataObjectUtilities.getObjectsClassForObjectType(objectType);
|
||||
|
@ -1692,17 +1692,17 @@ Zotero.Sync.Data.Engine.prototype._upgradeCheck = Zotero.Promise.coroutine(funct
|
|||
versionObjects[version].push(id);
|
||||
}
|
||||
for (let version in versionObjects) {
|
||||
yield objectsClass.updateVersion(versionObjects[version], version);
|
||||
await objectsClass.updateVersion(versionObjects[version], version);
|
||||
}
|
||||
}
|
||||
|
||||
// Mark library as requiring full sync
|
||||
this.library.libraryVersion = -1;
|
||||
yield this.library.save();
|
||||
await this.library.save();
|
||||
|
||||
// If this is the last classic sync library, delete old timestamps
|
||||
if (!(yield Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM libraries WHERE version=0"))) {
|
||||
yield Zotero.DB.queryAsync(
|
||||
if (!(await Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM libraries WHERE version=0"))) {
|
||||
await Zotero.DB.queryAsync(
|
||||
"DELETE FROM version WHERE schema IN ('lastlocalsync', 'lastremotesync')"
|
||||
);
|
||||
}
|
||||
|
@ -1856,21 +1856,21 @@ Zotero.Sync.Data.Engine.prototype._restoreToServer = async function () {
|
|||
// Flag engine as restore-to-server mode so it uses library version only
|
||||
this._restoringToServer = true;
|
||||
|
||||
await Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.Sync.Data.Local.clearCacheForLibrary(this.libraryID);
|
||||
yield Zotero.Sync.Data.Local.clearQueueForLibrary(this.libraryID);
|
||||
yield Zotero.Sync.Data.Local.clearDeleteLogForLibrary(this.libraryID);
|
||||
await Zotero.DB.executeTransaction(async function () {
|
||||
await Zotero.Sync.Data.Local.clearCacheForLibrary(this.libraryID);
|
||||
await Zotero.Sync.Data.Local.clearQueueForLibrary(this.libraryID);
|
||||
await Zotero.Sync.Data.Local.clearDeleteLogForLibrary(this.libraryID);
|
||||
|
||||
// Mark all local settings as unsynced
|
||||
yield Zotero.SyncedSettings.markAllAsUnsynced(this.libraryID);
|
||||
await Zotero.SyncedSettings.markAllAsUnsynced(this.libraryID);
|
||||
|
||||
// Mark all objects as unsynced
|
||||
for (let objectType of Zotero.DataObjectUtilities.getTypesForLibrary(this.libraryID)) {
|
||||
let objectsClass = Zotero.DataObjectUtilities.getObjectsClassForObjectType(objectType);
|
||||
// Reset version on all objects and mark as unsynced
|
||||
let ids = yield objectsClass.getAllIDs(this.libraryID)
|
||||
yield objectsClass.updateVersion(ids, 0);
|
||||
yield objectsClass.updateSynced(ids, false);
|
||||
let ids = await objectsClass.getAllIDs(this.libraryID)
|
||||
await objectsClass.updateVersion(ids, 0);
|
||||
await objectsClass.updateSynced(ids, false);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
|
|
|
@ -76,12 +76,12 @@ Zotero.Sync.EventListeners.ChangeListener = new function () {
|
|||
});
|
||||
|
||||
if (storageSets.length) {
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.queryAsync(
|
||||
return Zotero.DB.executeTransaction(async function () {
|
||||
await Zotero.DB.queryAsync(
|
||||
syncSQL + Array(syncSets.length / 3).fill('(?, ?, ?)').join(', '),
|
||||
syncSets
|
||||
);
|
||||
yield Zotero.DB.queryAsync(
|
||||
await Zotero.DB.queryAsync(
|
||||
storageSQL + Array(storageSets.length / 2).fill('(?, ?)').join(', '),
|
||||
storageSets
|
||||
);
|
||||
|
|
|
@ -159,20 +159,20 @@ Zotero.Sync.Data.FullTextEngine.prototype._upload = Zotero.Promise.coroutine(fun
|
|||
libraryVersion,
|
||||
jsonArray
|
||||
));
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
for (let state of ['successful', 'unchanged']) {
|
||||
for (let index in results[state]) {
|
||||
let key = results[state][index].key;
|
||||
let itemID = Zotero.Items.getIDFromLibraryAndKey(this.libraryID, key);
|
||||
yield Zotero.FullText.setItemSynced(itemID, libraryVersion);
|
||||
await Zotero.FullText.setItemSynced(itemID, libraryVersion);
|
||||
}
|
||||
}
|
||||
// Set both the library version and the full-text library version. The latter is necessary
|
||||
// because full-text sync can be turned off at any time, so we have to keep track of the
|
||||
// last version we've seen for full-text in case the main library version has advanced since.
|
||||
yield Zotero.FullText.setLibraryVersion(this.libraryID, libraryVersion);
|
||||
await Zotero.FullText.setLibraryVersion(this.libraryID, libraryVersion);
|
||||
this.library.libraryVersion = libraryVersion;
|
||||
yield this.library.save();
|
||||
await this.library.save();
|
||||
}.bind(this));
|
||||
|
||||
for (let index in results.failed) {
|
||||
|
|
|
@ -898,8 +898,8 @@ Zotero.Sync.Data.Local = {
|
|||
// Errors have to be thrown in order to roll back the transaction, so catch those here
|
||||
// and continue
|
||||
try {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
let obj = yield objectsClass.getByLibraryAndKeyAsync(
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
let obj = await objectsClass.getByLibraryAndKeyAsync(
|
||||
libraryID, objectKey, { noCache: true }
|
||||
);
|
||||
let restored = false;
|
||||
|
@ -923,7 +923,7 @@ Zotero.Sync.Data.Local = {
|
|||
Zotero.debug("Local " + objectType + " " + obj.libraryKey
|
||||
+ " has been modified since last sync", 4);
|
||||
|
||||
let cachedJSON = yield this.getCacheObject(
|
||||
let cachedJSON = await this.getCacheObject(
|
||||
objectType, obj.libraryID, obj.key, obj.version
|
||||
);
|
||||
let result = this._reconcileChanges(
|
||||
|
@ -947,7 +947,7 @@ Zotero.Sync.Data.Local = {
|
|||
if (result.localChanged) {
|
||||
saveOptions.saveAsUnsynced = true;
|
||||
}
|
||||
let saveResults = yield this._saveObjectFromJSON(
|
||||
let saveResults = await this._saveObjectFromJSON(
|
||||
obj,
|
||||
jsonObject,
|
||||
saveOptions
|
||||
|
@ -1028,7 +1028,7 @@ Zotero.Sync.Data.Local = {
|
|||
saveOptions.isNewObject = true;
|
||||
|
||||
// Check if object has been deleted locally
|
||||
let dateDeleted = yield this.getDateDeleted(
|
||||
let dateDeleted = await this.getDateDeleted(
|
||||
objectType, libraryID, objectKey
|
||||
);
|
||||
if (dateDeleted) {
|
||||
|
@ -1064,7 +1064,7 @@ Zotero.Sync.Data.Local = {
|
|||
case 'search':
|
||||
Zotero.debug(`${ObjectType} ${objectKey} was modified remotely `
|
||||
+ '-- restoring');
|
||||
yield this.removeObjectsFromDeleteLog(
|
||||
await this.removeObjectsFromDeleteLog(
|
||||
objectType,
|
||||
libraryID,
|
||||
[objectKey]
|
||||
|
@ -1081,13 +1081,13 @@ Zotero.Sync.Data.Local = {
|
|||
obj = new Zotero[ObjectType];
|
||||
obj.libraryID = libraryID;
|
||||
obj.key = objectKey;
|
||||
yield obj.loadPrimaryData();
|
||||
await obj.loadPrimaryData();
|
||||
|
||||
// Don't cache new items immediately, which skips reloading after save
|
||||
saveOptions.skipCache = true;
|
||||
}
|
||||
|
||||
let saveResults = yield this._saveObjectFromJSON(obj, jsonObject, saveOptions);
|
||||
let saveResults = await this._saveObjectFromJSON(obj, jsonObject, saveOptions);
|
||||
if (restored) {
|
||||
saveResults.restored = true;
|
||||
}
|
||||
|
@ -1341,8 +1341,8 @@ Zotero.Sync.Data.Local = {
|
|||
// Errors have to be thrown in order to roll back the transaction, so catch
|
||||
// those here and continue
|
||||
try {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
let obj = yield objectsClass.getByLibraryAndKeyAsync(
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
let obj = await objectsClass.getByLibraryAndKeyAsync(
|
||||
libraryID, json.key, { noCache: true }
|
||||
);
|
||||
// Update object with merge data
|
||||
|
@ -1350,7 +1350,7 @@ Zotero.Sync.Data.Local = {
|
|||
// Delete local object
|
||||
if (json.deleted) {
|
||||
try {
|
||||
yield obj.erase({
|
||||
await obj.erase({
|
||||
notifierQueue
|
||||
});
|
||||
}
|
||||
|
@ -1385,14 +1385,14 @@ Zotero.Sync.Data.Local = {
|
|||
obj = new Zotero[ObjectType];
|
||||
obj.libraryID = libraryID;
|
||||
obj.key = json.key;
|
||||
yield obj.loadPrimaryData();
|
||||
await obj.loadPrimaryData();
|
||||
|
||||
// Don't cache new items immediately,
|
||||
// which skips reloading after save
|
||||
saveOptions.skipCache = true;
|
||||
}
|
||||
|
||||
let saveResults = yield this._saveObjectFromJSON(obj, json, saveOptions);
|
||||
let saveResults = await this._saveObjectFromJSON(obj, json, saveOptions);
|
||||
results.push(saveResults);
|
||||
if (!saveResults.processed) {
|
||||
throw saveResults.error;
|
||||
|
|
|
@ -1238,16 +1238,16 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
|||
case 'split':
|
||||
for (let libraryID of editableLibraries) {
|
||||
let itemIDs = yield Zotero.Tags.getTagItems(libraryID, oldTagID);
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
for (let itemID of itemIDs) {
|
||||
let item = yield Zotero.Items.getAsync(itemID);
|
||||
let item = await Zotero.Items.getAsync(itemID);
|
||||
for (let tag of dataOut.result.tags) {
|
||||
item.addTag(tag);
|
||||
}
|
||||
item.removeTag(oldTag);
|
||||
yield item.save();
|
||||
await item.save();
|
||||
}
|
||||
yield Zotero.Tags.purge(oldTagID);
|
||||
await Zotero.Tags.purge(oldTagID);
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
@ -1255,11 +1255,11 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
|||
case 'edit':
|
||||
for (let libraryID of editableLibraries) {
|
||||
let itemIDs = yield Zotero.Tags.getTagItems(libraryID, oldTagID);
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
for (let itemID of itemIDs) {
|
||||
let item = yield Zotero.Items.getAsync(itemID);
|
||||
let item = await Zotero.Items.getAsync(itemID);
|
||||
item.replaceTag(oldTag, dataOut.result.tag);
|
||||
yield item.save();
|
||||
await item.save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -407,7 +407,7 @@ Zotero.Translate.ItemSaver.prototype = {
|
|||
var parentIDs = collections.map(c => null);
|
||||
var topLevelCollections = [];
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
while(collectionsToProcess.length) {
|
||||
var collection = collectionsToProcess.shift();
|
||||
var parentID = parentIDs.shift();
|
||||
|
@ -422,7 +422,7 @@ Zotero.Translate.ItemSaver.prototype = {
|
|||
newCollection.parentID = rootCollectionID;
|
||||
topLevelCollections.push(newCollection)
|
||||
}
|
||||
yield newCollection.save(this._saveOptions);
|
||||
await newCollection.save(this._saveOptions);
|
||||
|
||||
var toAdd = [];
|
||||
|
||||
|
@ -444,7 +444,7 @@ Zotero.Translate.ItemSaver.prototype = {
|
|||
|
||||
if(toAdd.length) {
|
||||
Zotero.debug("Translate: Adding " + toAdd, 5);
|
||||
yield newCollection.addItems(toAdd);
|
||||
await newCollection.addItems(toAdd);
|
||||
}
|
||||
}
|
||||
}.bind(this));
|
||||
|
|
|
@ -1675,18 +1675,18 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
|
|||
this.purgeDataObjects = Zotero.Promise.coroutine(function* () {
|
||||
var d = new Date();
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
return Zotero.Creators.purge();
|
||||
});
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
return Zotero.Tags.purge();
|
||||
});
|
||||
yield Zotero.Fulltext.purgeUnusedWords();
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
return Zotero.Items.purge();
|
||||
});
|
||||
// DEBUG: this might not need to be permanent
|
||||
//yield Zotero.DB.executeTransaction(function* () {
|
||||
//yield Zotero.DB.executeTransaction(async function () {
|
||||
// return Zotero.Relations.purge();
|
||||
//});
|
||||
|
||||
|
|
|
@ -973,16 +973,16 @@ var ZoteroPane = new function()
|
|||
}
|
||||
|
||||
let itemID;
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
var item = new Zotero.Item(typeID);
|
||||
item.libraryID = libraryID;
|
||||
for (var i in data) {
|
||||
item.setField(i, data[i]);
|
||||
}
|
||||
itemID = yield item.save();
|
||||
itemID = await item.save();
|
||||
|
||||
if (collectionTreeRow && collectionTreeRow.isCollection()) {
|
||||
yield collectionTreeRow.ref.addItem(itemID);
|
||||
await collectionTreeRow.ref.addItem(itemID);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1757,21 +1757,21 @@ var ZoteroPane = new function()
|
|||
|
||||
var newItem;
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
newItem = item.clone();
|
||||
// If in a collection, add new item to it
|
||||
if (self.getCollectionTreeRow().isCollection() && newItem.isTopLevelItem()) {
|
||||
newItem.setCollections([self.getCollectionTreeRow().ref.id]);
|
||||
}
|
||||
yield newItem.save();
|
||||
await newItem.save();
|
||||
if (item.isNote() && Zotero.Libraries.get(newItem.libraryID).filesEditable) {
|
||||
yield Zotero.Notes.copyEmbeddedImages(item, newItem);
|
||||
await Zotero.Notes.copyEmbeddedImages(item, newItem);
|
||||
}
|
||||
for (let relItemKey of item.relatedItems) {
|
||||
try {
|
||||
let relItem = yield Zotero.Items.getByLibraryAndKeyAsync(item.libraryID, relItemKey);
|
||||
let relItem = await Zotero.Items.getByLibraryAndKeyAsync(item.libraryID, relItemKey);
|
||||
if (relItem.addRelatedItem(newItem)) {
|
||||
yield relItem.save({
|
||||
await relItem.save({
|
||||
skipDateModifiedUpdate: true
|
||||
});
|
||||
}
|
||||
|
|
|
@ -756,12 +756,12 @@ function generateAllTypesAndFieldsData() {
|
|||
* The field values should be in the form exactly as they would appear in Zotero
|
||||
*/
|
||||
function populateDBWithSampleData(data) {
|
||||
return Zotero.DB.executeTransaction(function* () {
|
||||
return Zotero.DB.executeTransaction(async function () {
|
||||
for (let itemName in data) {
|
||||
let item = data[itemName];
|
||||
let zItem = new Zotero.Item;
|
||||
zItem.fromJSON(item);
|
||||
item.id = yield zItem.save();
|
||||
item.id = await zItem.save();
|
||||
}
|
||||
|
||||
return data;
|
||||
|
|
|
@ -363,11 +363,11 @@ describe("Zotero.CollectionTree", function() {
|
|||
|
||||
it("should add multiple collections", function* () {
|
||||
var col1, col2;
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
col1 = createUnsavedDataObject('collection');
|
||||
col2 = createUnsavedDataObject('collection');
|
||||
yield col1.save();
|
||||
yield col2.save();
|
||||
await col1.save();
|
||||
await col2.save();
|
||||
});
|
||||
|
||||
var aRow = cv.getRowIndexByID("C" + col1.id);
|
||||
|
|
|
@ -8,8 +8,8 @@ describe("Zotero.Creators", function() {
|
|||
lastName: "Last"
|
||||
};
|
||||
var creatorID;
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
creatorID = yield Zotero.Creators.getIDFromData(data1, true);
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
creatorID = await Zotero.Creators.getIDFromData(data1, true);
|
||||
});
|
||||
assert.typeOf(creatorID, 'number');
|
||||
var data2 = Zotero.Creators.get(creatorID);
|
||||
|
|
|
@ -71,13 +71,13 @@ describe("Zotero.DataObjectUtilities", function() {
|
|||
describe("fields", function () {
|
||||
it("should not show empty items as different", function* () {
|
||||
var id1, id2, json1, json2;
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
var item = new Zotero.Item('book');
|
||||
id1 = yield item.save();
|
||||
id1 = await item.save();
|
||||
json1 = item.toJSON();
|
||||
|
||||
var item = new Zotero.Item('book');
|
||||
id2 = yield item.save();
|
||||
id2 = await item.save();
|
||||
json2 = item.toJSON();
|
||||
});
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@ describe("Zotero.DataObjects", function () {
|
|||
it("should return a libraryID and key within a transaction", function* () {
|
||||
for (let type of types) {
|
||||
let objectsClass = Zotero.DataObjectUtilities.getObjectsClassForObjectType(type);
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
let obj = createUnsavedDataObject(type);
|
||||
yield obj.save();
|
||||
await obj.save();
|
||||
|
||||
var {libraryID, key} = objectsClass.getLibraryAndKeyFromID(obj.id);
|
||||
assert.equal(libraryID, Zotero.Libraries.userLibraryID);
|
||||
|
@ -32,7 +32,7 @@ describe("Zotero.DataObjects", function () {
|
|||
assert.typeOf(key, 'string');
|
||||
assert.equal(key, obj.key);
|
||||
|
||||
yield obj.erase();
|
||||
await obj.erase();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -42,9 +42,9 @@ describe("Zotero.DataObjects", function () {
|
|||
let objectsClass = Zotero.DataObjectUtilities.getObjectsClassForObjectType(type);
|
||||
var obj;
|
||||
try {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
obj = createUnsavedDataObject(type);
|
||||
yield obj.save();
|
||||
await obj.save();
|
||||
throw 'Aborting transaction -- ignore';
|
||||
});
|
||||
}
|
||||
|
|
|
@ -192,21 +192,21 @@ describe("Zotero.DB", function() {
|
|||
reject2 = reject;
|
||||
});
|
||||
|
||||
Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.Promise.delay(250);
|
||||
var num = yield Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM " + tmpTable);
|
||||
Zotero.DB.executeTransaction(async function () {
|
||||
await Zotero.Promise.delay(250);
|
||||
var num = await Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM " + tmpTable);
|
||||
assert.equal(num, 0);
|
||||
yield Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (1)");
|
||||
await Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (1)");
|
||||
assert.ok(Zotero.DB.inTransaction());
|
||||
})
|
||||
.then(resolve1)
|
||||
.catch(reject1);
|
||||
|
||||
Zotero.DB.executeTransaction(function* () {
|
||||
var num = yield Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM " + tmpTable);
|
||||
Zotero.DB.executeTransaction(async function () {
|
||||
var num = await Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM " + tmpTable);
|
||||
assert.equal(num, 1);
|
||||
yield Zotero.Promise.delay(500);
|
||||
yield Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (2)");
|
||||
await Zotero.Promise.delay(500);
|
||||
await Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (2)");
|
||||
assert.ok(Zotero.DB.inTransaction());
|
||||
})
|
||||
.then(resolve2)
|
||||
|
@ -231,30 +231,30 @@ describe("Zotero.DB", function() {
|
|||
});
|
||||
|
||||
// Start a transaction and have it delay
|
||||
Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.Promise.delay(100);
|
||||
var num = yield Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM " + tmpTable);
|
||||
Zotero.DB.executeTransaction(async function () {
|
||||
await Zotero.Promise.delay(100);
|
||||
var num = await Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM " + tmpTable);
|
||||
assert.equal(num, 0);
|
||||
yield Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (1)");
|
||||
await Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (1)");
|
||||
assert.ok(Zotero.DB.inTransaction());
|
||||
})
|
||||
.then(resolve1)
|
||||
.catch(reject1);
|
||||
|
||||
// Start two more transactions, which should wait on the first
|
||||
Zotero.DB.executeTransaction(function* () {
|
||||
var num = yield Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM " + tmpTable);
|
||||
Zotero.DB.executeTransaction(async function () {
|
||||
var num = await Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM " + tmpTable);
|
||||
assert.equal(num, 1);
|
||||
yield Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (2)");
|
||||
await Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (2)");
|
||||
assert.ok(Zotero.DB.inTransaction());
|
||||
})
|
||||
.then(resolve2)
|
||||
.catch(reject2);
|
||||
|
||||
Zotero.DB.executeTransaction(function* () {
|
||||
var num = yield Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM " + tmpTable);
|
||||
Zotero.DB.executeTransaction(async function () {
|
||||
var num = await Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM " + tmpTable);
|
||||
assert.equal(num, 2);
|
||||
yield Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (3)");
|
||||
await Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (3)");
|
||||
// But make sure the second queued transaction doesn't start at the same time,
|
||||
// such that the first queued transaction gets closed while the second is still
|
||||
// running
|
||||
|
@ -269,8 +269,8 @@ describe("Zotero.DB", function() {
|
|||
it("should roll back on error", function* () {
|
||||
yield Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (1)");
|
||||
try {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (2)");
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
await Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (2)");
|
||||
throw 'Aborting transaction -- ignore';
|
||||
});
|
||||
}
|
||||
|
@ -290,8 +290,8 @@ describe("Zotero.DB", function() {
|
|||
var callbackRan = false;
|
||||
try {
|
||||
yield Zotero.DB.executeTransaction(
|
||||
function* () {
|
||||
yield Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (1)");
|
||||
async function () {
|
||||
await Zotero.DB.queryAsync("INSERT INTO " + tmpTable + " VALUES (1)");
|
||||
throw 'Aborting transaction -- ignore';
|
||||
},
|
||||
{
|
||||
|
@ -331,9 +331,9 @@ describe("Zotero.DB", function() {
|
|||
var callback1Ran = false;
|
||||
var callback2Ran = false;
|
||||
try {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(
|
||||
function* () {},
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
await Zotero.DB.executeTransaction(
|
||||
async function () {},
|
||||
{
|
||||
waitTimeout: 100,
|
||||
onRollback: function () {
|
||||
|
|
|
@ -7,7 +7,7 @@ describe("Zotero.Groups", function () {
|
|||
}
|
||||
finally {
|
||||
if (group) {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
return group.erase();
|
||||
})
|
||||
}
|
||||
|
|
|
@ -139,19 +139,19 @@ describe("Item pane", function () {
|
|||
var item;
|
||||
var note1;
|
||||
var note2;
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
item = createUnsavedDataObject('item');
|
||||
yield item.save();
|
||||
await item.save();
|
||||
|
||||
note1 = new Zotero.Item('note');
|
||||
note1.parentID = item.id;
|
||||
note1.setNote('A');
|
||||
yield note1.save();
|
||||
await note1.save();
|
||||
|
||||
note2 = new Zotero.Item('note');
|
||||
note2.parentID = item.id;
|
||||
note2.setNote('B');
|
||||
yield note2.save();
|
||||
await note2.save();
|
||||
});
|
||||
|
||||
var tabs = doc.getElementById('zotero-editpane-tabs');
|
||||
|
@ -179,19 +179,19 @@ describe("Item pane", function () {
|
|||
var item;
|
||||
var note1;
|
||||
var note2;
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
item = createUnsavedDataObject('item');
|
||||
yield item.save();
|
||||
await item.save();
|
||||
|
||||
note1 = new Zotero.Item('note');
|
||||
note1.parentID = item.id;
|
||||
note1.setNote('A');
|
||||
yield note1.save();
|
||||
await note1.save();
|
||||
|
||||
note2 = new Zotero.Item('note');
|
||||
note2.parentID = item.id;
|
||||
note2.setNote('B');
|
||||
yield note2.save();
|
||||
await note2.save();
|
||||
});
|
||||
|
||||
var tabs = doc.getElementById('zotero-editpane-tabs');
|
||||
|
@ -220,19 +220,19 @@ describe("Item pane", function () {
|
|||
var item;
|
||||
var note1;
|
||||
var note2;
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
item = createUnsavedDataObject('item');
|
||||
yield item.save();
|
||||
await item.save();
|
||||
|
||||
note1 = new Zotero.Item('note');
|
||||
note1.parentID = item.id;
|
||||
note1.setNote('A');
|
||||
yield note1.save();
|
||||
await note1.save();
|
||||
|
||||
note2 = new Zotero.Item('note');
|
||||
note2.parentID = item.id;
|
||||
note2.setNote('B');
|
||||
yield note2.save();
|
||||
await note2.save();
|
||||
});
|
||||
|
||||
var tabs = doc.getElementById('zotero-editpane-tabs');
|
||||
|
|
|
@ -2237,13 +2237,13 @@ describe("Zotero.Item", function () {
|
|||
var item4 = yield createDataObject('item');
|
||||
|
||||
var relateItems = Zotero.Promise.coroutine(function* (i1, i2) {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
i1.addRelatedItem(i2);
|
||||
yield i1.save({
|
||||
await i1.save({
|
||||
skipDateModifiedUpdate: true
|
||||
});
|
||||
i2.addRelatedItem(i1);
|
||||
yield i2.save({
|
||||
await i2.save({
|
||||
skipDateModifiedUpdate: true
|
||||
});
|
||||
});
|
||||
|
|
|
@ -373,8 +373,8 @@ describe("Zotero.ItemTree", function() {
|
|||
|
||||
// Remove item
|
||||
var treeRow = itemsView.getRow(2);
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield collection.removeItems([treeRow.ref.id]);
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
await collection.removeItems([treeRow.ref.id]);
|
||||
}.bind(this));
|
||||
|
||||
// Selection should stay on third row
|
||||
|
@ -414,12 +414,12 @@ describe("Zotero.ItemTree", function() {
|
|||
}
|
||||
|
||||
var num = numVisibleRows + 10;
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
for (let i = 0; i < num; i++) {
|
||||
let title = getTitle(i, num);
|
||||
let item = createUnsavedDataObject('item', { title });
|
||||
item.addToCollection(collection.id);
|
||||
yield item.save();
|
||||
await item.save();
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
|
@ -436,12 +436,12 @@ describe("Zotero.ItemTree", function() {
|
|||
skipSelect: true
|
||||
});
|
||||
// Then add a few more in a transaction
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
for (let i = 0; i < 3; i++) {
|
||||
var item = createUnsavedDataObject(
|
||||
'item', { title: getTitle(0, num), collections: [collection.id] }
|
||||
);
|
||||
yield item.save({
|
||||
await item.save({
|
||||
skipSelect: true
|
||||
});
|
||||
}
|
||||
|
@ -465,12 +465,12 @@ describe("Zotero.ItemTree", function() {
|
|||
}
|
||||
|
||||
var num = numVisibleRows + 10;
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
for (let i = 0; i < num; i++) {
|
||||
let title = getTitle(i, num);
|
||||
let item = createUnsavedDataObject('item', { title });
|
||||
item.addToCollection(collection.id);
|
||||
yield item.save();
|
||||
await item.save();
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
|
@ -490,12 +490,12 @@ describe("Zotero.ItemTree", function() {
|
|||
skipSelect: true
|
||||
});
|
||||
// Then add a few more in a transaction
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
for (let i = 0; i < 3; i++) {
|
||||
var item = createUnsavedDataObject(
|
||||
'item', { title: getTitle(0, num), collections: [collection.id] }
|
||||
);
|
||||
yield item.save({
|
||||
await item.save({
|
||||
skipSelect: true
|
||||
});
|
||||
}
|
||||
|
@ -521,13 +521,13 @@ describe("Zotero.ItemTree", function() {
|
|||
}
|
||||
|
||||
var num = numVisibleRows + 10;
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
// Start at "*1" so we can add items before
|
||||
for (let i = 1; i < num; i++) {
|
||||
let title = getTitle(i, num);
|
||||
let item = createUnsavedDataObject('item', { title });
|
||||
item.addToCollection(collection.id);
|
||||
yield item.save();
|
||||
await item.save();
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
|
@ -542,12 +542,12 @@ describe("Zotero.ItemTree", function() {
|
|||
skipSelect: true
|
||||
});
|
||||
// Then add a few more in a transaction
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
for (let i = 0; i < 3; i++) {
|
||||
var item = createUnsavedDataObject(
|
||||
'item', { title: getTitle(0, num), collections: [collection.id] }
|
||||
);
|
||||
yield item.save({
|
||||
await item.save({
|
||||
skipSelect: true
|
||||
});
|
||||
}
|
||||
|
|
|
@ -15,12 +15,12 @@ describe("Zotero.Notifier", function () {
|
|||
};
|
||||
var id = Zotero.Notifier.registerObserver(observer, null, 'test_trigger');
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
var item = new Zotero.Item('book');
|
||||
item.setField('title', 'A');
|
||||
yield item.save();
|
||||
await item.save();
|
||||
item.setField('title', 'B');
|
||||
yield item.save();
|
||||
await item.save();
|
||||
|
||||
Zotero.Notifier.queue('unknown', 'item', item.id);
|
||||
});
|
||||
|
|
|
@ -37,8 +37,8 @@ describe("Zotero.Relations", function () {
|
|||
var rels = item2.getRelationsByPredicate(Zotero.Relations.relatedItemPredicate);
|
||||
assert.include(rels[0], "/users/local");
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.Relations.updateUser(null, 1);
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
await Zotero.Relations.updateUser(null, 1);
|
||||
})
|
||||
|
||||
var rels = item2.getRelationsByPredicate(Zotero.Relations.relatedItemPredicate);
|
||||
|
@ -56,8 +56,8 @@ describe("Zotero.Relations", function () {
|
|||
var rels = item2.getRelationsByPredicate(Zotero.Relations.relatedItemPredicate);
|
||||
assert.include(rels[0], "/users/1");
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.Relations.updateUser(1, 2);
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
await Zotero.Relations.updateUser(1, 2);
|
||||
});
|
||||
|
||||
var rels = item2.getRelationsByPredicate(Zotero.Relations.relatedItemPredicate);
|
||||
|
|
|
@ -145,10 +145,10 @@ describe("Tag Selector", function () {
|
|||
}
|
||||
]);
|
||||
var promise = waitForTagSelector(win);
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield item1.save();
|
||||
yield item2.save();
|
||||
yield item3.save();
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
await item1.save();
|
||||
await item2.save();
|
||||
await item3.save();
|
||||
});
|
||||
yield promise;
|
||||
|
||||
|
@ -177,10 +177,10 @@ describe("Tag Selector", function () {
|
|||
var item3 = createUnsavedDataObject('item', { collections: [collection.id] });
|
||||
item3.setTags([tag3]);
|
||||
var promise = waitForTagSelector(win);
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield item1.save();
|
||||
yield item2.save();
|
||||
yield item3.save();
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
await item1.save();
|
||||
await item2.save();
|
||||
await item3.save();
|
||||
});
|
||||
yield promise;
|
||||
|
||||
|
|
|
@ -142,8 +142,8 @@ describe("Zotero.Tags", function () {
|
|||
|
||||
assert.equal(Zotero.Tags.getName(tagID), tagName);
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.Tags.purge();
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
await Zotero.Tags.purge();
|
||||
});
|
||||
|
||||
assert.isFalse(Zotero.Tags.getName(tagID));
|
||||
|
|
|
@ -1709,13 +1709,13 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
let getter = new Zotero.Translate.ItemGetter();
|
||||
let items, itemIDs, itemURIs;
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
items = [
|
||||
yield new Zotero.Item('journalArticle'),
|
||||
yield new Zotero.Item('book')
|
||||
await new Zotero.Item('journalArticle'),
|
||||
await new Zotero.Item('book')
|
||||
];
|
||||
|
||||
itemIDs = [ yield items[0].save(), yield items[1].save() ];
|
||||
itemIDs = [ await items[0].save(), await items[1].save() ];
|
||||
itemURIs = items.map(i => Zotero.URI.getItemURI(i));
|
||||
});
|
||||
|
||||
|
@ -1729,19 +1729,19 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
let getter = new Zotero.Translate.ItemGetter();
|
||||
let itemWithAutomaticTag, itemWithManualTag, itemWithMultipleTags
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
itemWithAutomaticTag = new Zotero.Item('journalArticle');
|
||||
itemWithAutomaticTag.addTag('automatic tag', 0);
|
||||
yield itemWithAutomaticTag.save();
|
||||
await itemWithAutomaticTag.save();
|
||||
|
||||
itemWithManualTag = new Zotero.Item('journalArticle');
|
||||
itemWithManualTag.addTag('manual tag', 1);
|
||||
yield itemWithManualTag.save();
|
||||
await itemWithManualTag.save();
|
||||
|
||||
itemWithMultipleTags = new Zotero.Item('journalArticle');
|
||||
itemWithMultipleTags.addTag('tag1', 0);
|
||||
itemWithMultipleTags.addTag('tag2', 1);
|
||||
yield itemWithMultipleTags.save();
|
||||
await itemWithMultipleTags.save();
|
||||
});
|
||||
|
||||
let legacyMode = [false, true];
|
||||
|
@ -1778,14 +1778,14 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
let getter = new Zotero.Translate.ItemGetter();
|
||||
let items, collections;
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
items = getter._itemsLeft = [
|
||||
new Zotero.Item('journalArticle'), // Not in collection
|
||||
new Zotero.Item('journalArticle'), // In a single collection
|
||||
new Zotero.Item('journalArticle'), //In two collections
|
||||
new Zotero.Item('journalArticle') // In a nested collection
|
||||
];
|
||||
yield Zotero.Promise.all(items.map(item => item.save()));
|
||||
await Zotero.Promise.all(items.map(item => item.save()));
|
||||
|
||||
collections = [
|
||||
new Zotero.Collection,
|
||||
|
@ -1797,16 +1797,16 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
collections[1].name = "test2";
|
||||
collections[2].name = "subTest1";
|
||||
collections[3].name = "subTest2";
|
||||
yield collections[0].save();
|
||||
yield collections[1].save();
|
||||
await collections[0].save();
|
||||
await collections[1].save();
|
||||
collections[2].parentID = collections[0].id;
|
||||
collections[3].parentID = collections[1].id;
|
||||
yield collections[2].save();
|
||||
yield collections[3].save();
|
||||
await collections[2].save();
|
||||
await collections[3].save();
|
||||
|
||||
yield collections[0].addItems([items[1].id, items[2].id]);
|
||||
yield collections[1].addItem(items[2].id);
|
||||
yield collections[2].addItem(items[3].id);
|
||||
await collections[0].addItems([items[1].id, items[2].id]);
|
||||
await collections[1].addItem(items[2].id);
|
||||
await collections[2].addItem(items[3].id);
|
||||
});
|
||||
|
||||
let translatorItem = getter.nextItem();
|
||||
|
@ -1837,7 +1837,7 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
let getter = new Zotero.Translate.ItemGetter();
|
||||
let items;
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
items = [
|
||||
new Zotero.Item('journalArticle'), // Item with no relations
|
||||
|
||||
|
@ -1848,15 +1848,15 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
new Zotero.Item('journalArticle'), // But this item is not related to the item below
|
||||
new Zotero.Item('journalArticle')
|
||||
];
|
||||
yield Zotero.Promise.all(items.map(item => item.save()));
|
||||
await Zotero.Promise.all(items.map(item => item.save()));
|
||||
|
||||
yield items[1].addRelatedItem(items[2]);
|
||||
yield items[2].addRelatedItem(items[1]);
|
||||
await items[1].addRelatedItem(items[2]);
|
||||
await items[2].addRelatedItem(items[1]);
|
||||
|
||||
yield items[3].addRelatedItem(items[4]);
|
||||
yield items[4].addRelatedItem(items[3]);
|
||||
yield items[3].addRelatedItem(items[5]);
|
||||
yield items[5].addRelatedItem(items[3]);
|
||||
await items[3].addRelatedItem(items[4]);
|
||||
await items[4].addRelatedItem(items[3]);
|
||||
await items[3].addRelatedItem(items[5]);
|
||||
await items[5].addRelatedItem(items[3]);
|
||||
});
|
||||
|
||||
getter._itemsLeft = items.slice();
|
||||
|
@ -1902,24 +1902,24 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
it('should return standalone note in expected format', Zotero.Promise.coroutine(function* () {
|
||||
let relatedItem, note, collection;
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
relatedItem = new Zotero.Item('journalArticle');
|
||||
yield relatedItem.save();
|
||||
await relatedItem.save();
|
||||
|
||||
note = new Zotero.Item('note');
|
||||
note.setNote('Note');
|
||||
note.addTag('automaticTag', 0);
|
||||
note.addTag('manualTag', 1);
|
||||
note.addRelatedItem(relatedItem);
|
||||
yield note.save();
|
||||
await note.save();
|
||||
|
||||
relatedItem.addRelatedItem(note);
|
||||
yield relatedItem.save();
|
||||
await relatedItem.save();
|
||||
|
||||
collection = new Zotero.Collection;
|
||||
collection.name = 'test';
|
||||
yield collection.save();
|
||||
yield collection.addItem(note.id);
|
||||
await collection.save();
|
||||
await collection.addItem(note.id);
|
||||
});
|
||||
|
||||
let legacyMode = [false, true];
|
||||
|
@ -1985,32 +1985,32 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
}));
|
||||
it('should return attached note in expected format', Zotero.Promise.coroutine(function* () {
|
||||
let relatedItem, items, collection, note;
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
relatedItem = new Zotero.Item('journalArticle');
|
||||
yield relatedItem.save();
|
||||
await relatedItem.save();
|
||||
|
||||
items = [
|
||||
new Zotero.Item('journalArticle'),
|
||||
new Zotero.Item('journalArticle')
|
||||
];
|
||||
yield Zotero.Promise.all(items.map(item => item.save()));
|
||||
await Zotero.Promise.all(items.map(item => item.save()));
|
||||
|
||||
collection = new Zotero.Collection;
|
||||
collection.name = 'test';
|
||||
yield collection.save();
|
||||
yield collection.addItem(items[0].id);
|
||||
yield collection.addItem(items[1].id);
|
||||
await collection.save();
|
||||
await collection.addItem(items[0].id);
|
||||
await collection.addItem(items[1].id);
|
||||
|
||||
note = new Zotero.Item('note');
|
||||
note.setNote('Note');
|
||||
note.addTag('automaticTag', 0);
|
||||
note.addTag('manualTag', 1);
|
||||
yield note.save();
|
||||
await note.save();
|
||||
|
||||
note.addRelatedItem(relatedItem);
|
||||
relatedItem.addRelatedItem(note);
|
||||
yield note.save();
|
||||
yield relatedItem.save();
|
||||
await note.save();
|
||||
await relatedItem.save();
|
||||
});
|
||||
|
||||
let legacyMode = [false, true];
|
||||
|
@ -2094,11 +2094,11 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
let file = getTestPDF();
|
||||
let item, relatedItem;
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
item = new Zotero.Item('journalArticle');
|
||||
yield item.save();
|
||||
await item.save();
|
||||
relatedItem = new Zotero.Item('journalArticle');
|
||||
yield relatedItem.save();
|
||||
await relatedItem.save();
|
||||
});
|
||||
|
||||
// Attachment items
|
||||
|
@ -2110,7 +2110,7 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
yield Zotero.Attachments.linkFromURL({"url":'http://example.com', "parentItemID":item.id, "contentType":'application/pdf', "title":'empty.pdf'}) // Attached link to URL
|
||||
];
|
||||
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
yield Zotero.DB.executeTransaction(async function () {
|
||||
// Make sure all fields are populated
|
||||
for (let i=0; i<attachments.length; i++) {
|
||||
let attachment = attachments[i];
|
||||
|
@ -2124,12 +2124,12 @@ describe("Zotero.Translate.ItemGetter", function() {
|
|||
|
||||
attachment.addRelatedItem(relatedItem);
|
||||
|
||||
yield attachment.save();
|
||||
await attachment.save();
|
||||
|
||||
relatedItem.addRelatedItem(attachment);
|
||||
}
|
||||
|
||||
yield relatedItem.save();
|
||||
await relatedItem.save();
|
||||
});
|
||||
|
||||
let items = [ attachments[0], attachments[1], item ]; // Standalone attachments and item with child attachments
|
||||
|
|
Loading…
Reference in a new issue