Compare commits

..

No commits in common. "master" and "5.0.49" have entirely different histories.

10 changed files with 60 additions and 152 deletions

View File

@ -306,10 +306,7 @@ var Zotero_File_Interface = new function() {
} }
if (typeof options == 'string' || options instanceof Components.interfaces.nsIFile) { if (typeof options == 'string' || options instanceof Components.interfaces.nsIFile) {
Zotero.debug("WARNING: importFile() now takes a single options object -- update your code"); Zotero.debug("WARNING: importFile() now takes a single options object -- update your code");
options = { options = { file: options };
file: options,
createNewCollection: arguments[1]
};
} }
var file = options.file ? Zotero.File.pathToFile(options.file) : null; var file = options.file ? Zotero.File.pathToFile(options.file) : null;

View File

@ -806,7 +806,7 @@ Zotero_Import_Mendeley.prototype._convertNote = function (note) {
Zotero_Import_Mendeley.prototype._saveItems = async function (libraryID, json) { Zotero_Import_Mendeley.prototype._saveItems = async function (libraryID, json) {
var idMap = new Map(); var idMap = new Map();
await Zotero.DB.executeTransaction(async function () {
var lastExistingParentItem; var lastExistingParentItem;
for (let i = 0; i < json.length; i++) { for (let i = 0; i < json.length; i++) {
let itemJSON = json[i]; let itemJSON = json[i];
@ -843,7 +843,7 @@ Zotero_Import_Mendeley.prototype._saveItems = async function (libraryID, json) {
delete toSave.documentID; delete toSave.documentID;
item.fromJSON(toSave); item.fromJSON(toSave);
await item.saveTx({ await item.save({
skipSelect: true, skipSelect: true,
skipDateModifiedUpdate: true skipDateModifiedUpdate: true
}); });
@ -851,6 +851,7 @@ Zotero_Import_Mendeley.prototype._saveItems = async function (libraryID, json) {
idMap.set(itemJSON.documentID, item.id); idMap.set(itemJSON.documentID, item.id);
} }
} }
}.bind(this));
return idMap; return idMap;
}; };
@ -983,7 +984,6 @@ Zotero_Import_Mendeley.prototype._saveFilesAndAnnotations = async function (file
options.title = file.title; options.title = file.title;
options.url = file.url; options.url = file.url;
options.contentType = file.contentType; options.contentType = file.contentType;
options.singleFile = true;
attachment = await Zotero.Attachments.importSnapshotFromFile(options); attachment = await Zotero.Attachments.importSnapshotFromFile(options);
} }
else { else {
@ -1156,55 +1156,3 @@ Zotero_Import_Mendeley.prototype._updateItemCollectionKeys = function (json, old
} }
} }
} }
//
// Clean up extra files created <5.0.51
//
Zotero_Import_Mendeley.prototype.hasImportedFiles = async function () {
return !!(await Zotero.DB.valueQueryAsync(
"SELECT itemID FROM itemRelations JOIN relationPredicates USING (predicateID) "
+ "WHERE predicate='mendeleyDB:fileHash' LIMIT 1"
));
};
Zotero_Import_Mendeley.prototype.queueFileCleanup = async function () {
await Zotero.DB.queryAsync("INSERT INTO settings VALUES ('mImport', 'cleanup', 1)");
};
Zotero_Import_Mendeley.prototype.deleteNonPrimaryFiles = async function () {
var rows = await Zotero.DB.queryAsync(
"SELECT key, path FROM itemRelations "
+ "JOIN relationPredicates USING (predicateID) "
+ "JOIN items USING (itemID) "
+ "JOIN itemAttachments USING (itemID) "
+ "WHERE predicate='mendeleyDB:fileHash' AND linkMode=1" // imported_url
);
for (let row of rows) {
let dir = (Zotero.Attachments.getStorageDirectoryByLibraryAndKey(1, row.key)).path;
if (!row.path.startsWith('storage:')) {
Zotero.logError(row.path + " does not start with 'storage:'");
continue;
}
let filename = row.path.substr(8);
Zotero.debug(`Checking for extra files in ${dir}`);
await Zotero.File.iterateDirectory(dir, function* (iterator) {
while (true) {
let entry = yield iterator.next();
if (entry.name.startsWith('.zotero') || entry.name == filename) {
continue;
}
Zotero.debug(`Deleting ${entry.path}`);
try {
yield OS.File.remove(entry.path);
}
catch (e) {
Zotero.logError(e);
}
}
});
}
await Zotero.DB.queryAsync("DELETE FROM settings WHERE setting='mImport' AND key='cleanup'");
};

View File

@ -176,18 +176,14 @@ Zotero.Attachments = new function(){
/** /**
* @param {Object} options - 'file', 'url', 'title', 'contentType', 'charset', 'parentItemID', 'singleFile' * @param {Object} options - 'file', 'url', 'title', 'contentType', 'charset', 'parentItemID'
* @return {Promise<Zotero.Item>} * @return {Promise<Zotero.Item>}
*/ */
this.importSnapshotFromFile = Zotero.Promise.coroutine(function* (options) { this.importSnapshotFromFile = Zotero.Promise.coroutine(function* (options) {
Zotero.debug('Importing snapshot from file'); Zotero.debug('Importing snapshot from file');
var file = Zotero.File.pathToFile(options.file); var file = Zotero.File.pathToFile(options.file);
// TODO: Fix main filename when copying directory, though in that case it's probably var fileName = file.leafName;
// from our own export and already clean
var fileName = options.singleFile
? Zotero.File.getValidFileName(file.leafName)
: file.leafName;
var url = options.url; var url = options.url;
var title = options.title; var title = options.title;
var contentType = options.contentType; var contentType = options.contentType;
@ -198,7 +194,7 @@ Zotero.Attachments = new function(){
throw new Error("parentItemID not provided"); throw new Error("parentItemID not provided");
} }
var attachmentItem, itemID, destDir, newPath; var attachmentItem, itemID, destDir, newFile;
try { try {
yield Zotero.DB.executeTransaction(function* () { yield Zotero.DB.executeTransaction(function* () {
// Create a new attachment // Create a new attachment
@ -221,23 +217,13 @@ Zotero.Attachments = new function(){
var storageDir = Zotero.getStorageDirectory(); var storageDir = Zotero.getStorageDirectory();
destDir = this.getStorageDirectory(attachmentItem); destDir = this.getStorageDirectory(attachmentItem);
yield OS.File.removeDir(destDir.path); yield 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);
yield OS.File.copy(file.path, newPath);
}
// Copy entire parent directory (for HTML snapshots)
else {
file.parent.copyTo(storageDir, destDir.leafName); file.parent.copyTo(storageDir, destDir.leafName);
}
// Point to copied file
newFile = destDir.clone();
newFile.append(file.leafName);
}.bind(this)); }.bind(this));
yield _postProcessFile( yield _postProcessFile(attachmentItem, newFile, contentType, charset);
attachmentItem,
Zotero.File.pathToFile(newPath),
contentType,
charset
);
} }
catch (e) { catch (e) {
Zotero.logError(e); Zotero.logError(e);

View File

@ -2433,14 +2433,6 @@ Zotero.Schema = new function(){
} }
} }
else if (i == 101) {
Components.utils.import("chrome://zotero/content/import/mendeley/mendeleyImport.js");
let importer = new Zotero_Import_Mendeley();
if (yield importer.hasImportedFiles()) {
yield importer.queueFileCleanup();
}
}
// If breaking compatibility or doing anything dangerous, clear minorUpdateFrom // If breaking compatibility or doing anything dangerous, clear minorUpdateFrom
} }

View File

@ -820,7 +820,7 @@ Zotero.Sync.APIClient.prototype = {
_checkBackoff: function (xmlhttp) { _checkBackoff: function (xmlhttp) {
var backoff = xmlhttp.getResponseHeader("Backoff"); var backoff = xmlhttp.getResponseHeader("Backoff");
if (backoff && parseInt(backoff) == backoff) { if (backoff && Number.isInteger(backoff)) {
// TODO: Update status? // TODO: Update status?
this.caller.pause(backoff * 1000); this.caller.pause(backoff * 1000);
} }
@ -831,7 +831,7 @@ Zotero.Sync.APIClient.prototype = {
var retryAfter = xmlhttp.getResponseHeader("Retry-After"); var retryAfter = xmlhttp.getResponseHeader("Retry-After");
var delay; var delay;
if (!retryAfter) return false; if (!retryAfter) return false;
if (parseInt(retryAfter) != retryAfter) { if (!Number.isInteger(retryAfter)) {
Zotero.logError(`Invalid Retry-After delay ${retryAfter}`); Zotero.logError(`Invalid Retry-After delay ${retryAfter}`);
return false; return false;
} }

View File

@ -260,18 +260,6 @@ var ZoteroPane = new function()
ZoteroPane_Local.show(); ZoteroPane_Local.show();
}, 0); }, 0);
} }
// TEMP: Clean up extra files from Mendeley imports <5.0.51
setTimeout(async function () {
var needsCleanup = await Zotero.DB.valueQueryAsync(
"SELECT COUNT(*) FROM settings WHERE setting='mImport' AND key='cleanup'"
)
if (!needsCleanup) return;
Components.utils.import("chrome://zotero/content/import/mendeley/mendeleyImport.js");
var importer = new Zotero_Import_Mendeley();
importer.deleteNonPrimaryFiles();
}, 10000)
} }

View File

@ -636,10 +636,7 @@ ZoteroCommandLineHandler.prototype = {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator); .getService(Components.interfaces.nsIWindowMediator);
var browserWindow = wm.getMostRecentWindow("navigator:browser"); var browserWindow = wm.getMostRecentWindow("navigator:browser");
browserWindow.Zotero_File_Interface.importFile({ browserWindow.Zotero_File_Interface.importFile(file, checkState.value);
file,
createNewCollection: checkState.value
});
} }
} }
}); });

View File

@ -6,7 +6,7 @@
<em:id>zotero@chnm.gmu.edu</em:id> <em:id>zotero@chnm.gmu.edu</em:id>
<em:name>Zotero</em:name> <em:name>Zotero</em:name>
<em:version>5.0.51.SOURCE</em:version> <em:version>5.0.49.SOURCE</em:version>
<em:creator>Center for History and New Media<br/>George Mason University</em:creator> <em:creator>Center for History and New Media<br/>George Mason University</em:creator>
<em:contributor>Dan Cohen</em:contributor> <em:contributor>Dan Cohen</em:contributor>
<em:contributor>Sean Takats</em:contributor> <em:contributor>Sean Takats</em:contributor>

View File

@ -1,4 +1,4 @@
-- 101 -- 100
-- Copyright (c) 2009 Center for History and New Media -- Copyright (c) 2009 Center for History and New Media
-- George Mason University, Fairfax, Virginia, USA -- George Mason University, Fairfax, Virginia, USA

View File

@ -174,7 +174,7 @@ describe("Zotero.Sync.APIClient", function () {
req.respond( req.respond(
503, 503,
{ {
"Retry-After": "5" "Retry-After": 5
}, },
"" ""
); );
@ -183,7 +183,7 @@ describe("Zotero.Sync.APIClient", function () {
req.respond( req.respond(
503, 503,
{ {
"Retry-After": "10" "Retry-After": 10
}, },
"" ""
); );