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).
This commit is contained in:
parent
56e40c485b
commit
f8716fbe88
2 changed files with 24 additions and 5 deletions
|
@ -959,7 +959,12 @@ Zotero.Sync.Data.Engine.prototype._uploadObjects = Zotero.Promise.coroutine(func
|
||||||
);
|
);
|
||||||
yield Zotero.DB.executeTransaction(function* () {
|
yield Zotero.DB.executeTransaction(function* () {
|
||||||
for (let i = 0; i < toSave.length; i++) {
|
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;
|
this.library.libraryVersion = libraryVersion;
|
||||||
yield this.library.save();
|
yield this.library.save();
|
||||||
|
|
|
@ -960,18 +960,29 @@ describe("Zotero.Sync.Data.Engine", function () {
|
||||||
it("should update local objects with remotely saved version after uploading if necessary", function* () {
|
it("should update local objects with remotely saved version after uploading if necessary", function* () {
|
||||||
({ engine, client, caller } = yield setup());
|
({ engine, client, caller } = yield setup());
|
||||||
|
|
||||||
var libraryID = Zotero.Libraries.userLibraryID;
|
var library = Zotero.Libraries.userLibrary;
|
||||||
|
var libraryID = library.id;
|
||||||
var lastLibraryVersion = 5;
|
var lastLibraryVersion = 5;
|
||||||
yield Zotero.Libraries.setVersion(libraryID, lastLibraryVersion);
|
library.libraryVersion = lastLibraryVersion;
|
||||||
|
yield library.saveTx();
|
||||||
|
|
||||||
var types = Zotero.DataObjectUtilities.getTypes();
|
var types = Zotero.DataObjectUtilities.getTypes();
|
||||||
var objects = {};
|
var objects = {};
|
||||||
var objectResponseJSON = {};
|
var objectResponseJSON = {};
|
||||||
var objectNames = {};
|
var objectNames = {};
|
||||||
|
var itemDateModified = {};
|
||||||
for (let type of types) {
|
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] = {};
|
objectNames[type] = {};
|
||||||
objectResponseJSON[type] = objects[type].map(o => o.toResponseJSON());
|
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) {
|
server.respond(function (req) {
|
||||||
|
@ -1011,7 +1022,7 @@ describe("Zotero.Sync.Data.Engine", function () {
|
||||||
|
|
||||||
yield engine.start();
|
yield engine.start();
|
||||||
|
|
||||||
assert.equal(Zotero.Libraries.getVersion(libraryID), lastLibraryVersion);
|
assert.equal(library.libraryVersion, lastLibraryVersion);
|
||||||
for (let type of types) {
|
for (let type of types) {
|
||||||
// Make sure local objects were updated with new metadata and marked as synced
|
// Make sure local objects were updated with new metadata and marked as synced
|
||||||
assert.lengthOf((yield Zotero.Sync.Data.Local.getUnsynced(type, libraryID)), 0);
|
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];
|
let name = objectNames[type][key];
|
||||||
if (type == 'item') {
|
if (type == 'item') {
|
||||||
assert.equal(name, o.getField('title'));
|
assert.equal(name, o.getField('title'));
|
||||||
|
|
||||||
|
// But Date Modified shouldn't have changed for items
|
||||||
|
assert.equal(itemDateModified[key], o.dateModified);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert.equal(name, o.name);
|
assert.equal(name, o.name);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue