commit f8716fbe8865f310bcb7399a5cb3a5a7ddcbc6e9
parent 56e40c485ba8a5e0d019f27ebe414685c8e762aa
Author: Dan Stillman <dstillman@zotero.org>
Date: Sat, 21 May 2016 15:41:41 -0400
Don't change Date Modified when updating local item after upload
If the API returns a modified item after an upload (e.g., to strip invalid
characters), don't update the Date Modified field when saving those changes to
the local version (though it would still be good to avoid API-side changes as
much as possible).
Diffstat:
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/chrome/content/zotero/xpcom/sync/syncEngine.js b/chrome/content/zotero/xpcom/sync/syncEngine.js
@@ -959,7 +959,12 @@ Zotero.Sync.Data.Engine.prototype._uploadObjects = Zotero.Promise.coroutine(func
);
yield Zotero.DB.executeTransaction(function* () {
for (let i = 0; i < toSave.length; i++) {
- yield toSave[i].save();
+ yield toSave[i].save({
+ skipSyncedUpdate: true,
+ // We want to minimize the times when server writes actually result in local
+ // updates, but when they do, don't update the user-visible timestamp
+ skipDateModifiedUpdate: true
+ });
}
this.library.libraryVersion = libraryVersion;
yield this.library.save();
diff --git a/test/tests/syncEngineTest.js b/test/tests/syncEngineTest.js
@@ -960,18 +960,29 @@ describe("Zotero.Sync.Data.Engine", function () {
it("should update local objects with remotely saved version after uploading if necessary", function* () {
({ engine, client, caller } = yield setup());
- var libraryID = Zotero.Libraries.userLibraryID;
+ var library = Zotero.Libraries.userLibrary;
+ var libraryID = library.id;
var lastLibraryVersion = 5;
- yield Zotero.Libraries.setVersion(libraryID, lastLibraryVersion);
+ library.libraryVersion = lastLibraryVersion;
+ yield library.saveTx();
var types = Zotero.DataObjectUtilities.getTypes();
var objects = {};
var objectResponseJSON = {};
var objectNames = {};
+ var itemDateModified = {};
for (let type of types) {
- objects[type] = [yield createDataObject(type, { setTitle: true })];
+ objects[type] = [
+ yield createDataObject(
+ type, { setTitle: true, dateModified: '2016-05-21 01:00:00' }
+ )
+ ];
objectNames[type] = {};
objectResponseJSON[type] = objects[type].map(o => o.toResponseJSON());
+ if (type == 'item') {
+ let item = objects[type][0];
+ itemDateModified[item.key] = item.dateModified;
+ }
}
server.respond(function (req) {
@@ -1011,7 +1022,7 @@ describe("Zotero.Sync.Data.Engine", function () {
yield engine.start();
- assert.equal(Zotero.Libraries.getVersion(libraryID), lastLibraryVersion);
+ assert.equal(library.libraryVersion, lastLibraryVersion);
for (let type of types) {
// Make sure local objects were updated with new metadata and marked as synced
assert.lengthOf((yield Zotero.Sync.Data.Local.getUnsynced(type, libraryID)), 0);
@@ -1021,6 +1032,9 @@ describe("Zotero.Sync.Data.Engine", function () {
let name = objectNames[type][key];
if (type == 'item') {
assert.equal(name, o.getField('title'));
+
+ // But Date Modified shouldn't have changed for items
+ assert.equal(itemDateModified[key], o.dateModified);
}
else {
assert.equal(name, o.name);