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* () {
|
||||
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();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue