Handle auto-hyphenated ISBN during item conflict
Always keep the hyphenated version, and don't consider it a visible conflict
This commit is contained in:
parent
3a1bec1ab3
commit
e23452363b
2 changed files with 116 additions and 3 deletions
|
@ -838,7 +838,9 @@ Zotero.Sync.Data.Local = {
|
|||
jsonObject,
|
||||
{
|
||||
skipData: true,
|
||||
notifierQueue
|
||||
notifierQueue,
|
||||
// Save as unsynced
|
||||
saveAsChanged: !!result.localChanged
|
||||
}
|
||||
);
|
||||
results.push(saveResults);
|
||||
|
@ -884,6 +886,11 @@ Zotero.Sync.Data.Local = {
|
|||
jsonDataLocal[x] = jsonData[x];
|
||||
})
|
||||
jsonObject.data = jsonDataLocal;
|
||||
|
||||
// Save as unsynced
|
||||
if (results.localChanged) {
|
||||
saveOptions.saveAsChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Object doesn't exist locally
|
||||
|
@ -1160,7 +1167,7 @@ Zotero.Sync.Data.Local = {
|
|||
|
||||
let saveOptions = {};
|
||||
Object.assign(saveOptions, options);
|
||||
// Tell _saveObjectFromJSON to save as unsynced
|
||||
// Tell _saveObjectFromJSON() to save as unsynced
|
||||
saveOptions.saveAsChanged = true;
|
||||
saveOptions.notifierQueue = notifierQueue;
|
||||
|
||||
|
@ -1533,7 +1540,31 @@ Zotero.Sync.Data.Local = {
|
|||
conflicts.push([c1, c2]);
|
||||
}
|
||||
|
||||
return { changes, conflicts };
|
||||
var localChanged = false;
|
||||
|
||||
// Massage some old data
|
||||
conflicts = conflicts.filter((x) => {
|
||||
// If one side has auto-hyphenated ISBN, use that
|
||||
if (x[0].field == 'ISBN' && x[0].op == 'add' && x[1].op == 'add') {
|
||||
let hyphenatedA = Zotero.Utilities.Internal.hyphenateISBN(x[0].value);
|
||||
let hyphenatedB = Zotero.Utilities.Internal.hyphenateISBN(x[1].value);
|
||||
if (hyphenatedA && hyphenatedB) {
|
||||
// Use remote
|
||||
if (hyphenatedA == x[1].value) {
|
||||
changes.push(x[1]);
|
||||
return false;
|
||||
}
|
||||
// Use local
|
||||
else if (x[0].value == hyphenatedB) {
|
||||
localChanged = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
return { changes, conflicts, localChanged };
|
||||
},
|
||||
|
||||
|
||||
|
|
|
@ -439,6 +439,35 @@ describe("Zotero.Sync.Data.Local", function() {
|
|||
assert.equal(obj.getField('place'), changedPlace);
|
||||
})
|
||||
|
||||
it("should save item with overriding local conflict as unsynced", function* () {
|
||||
var libraryID = Zotero.Libraries.userLibraryID;
|
||||
|
||||
var isbn = '978-0-335-22006-9';
|
||||
var type = 'item';
|
||||
let obj = createUnsavedDataObject(type, { version: 5 });
|
||||
obj.setField('ISBN', isbn);
|
||||
yield obj.saveTx();
|
||||
let data = obj.toJSON();
|
||||
|
||||
data.key = obj.key;
|
||||
data.version = 10;
|
||||
data.ISBN = '9780335220069';
|
||||
let json = {
|
||||
key: obj.key,
|
||||
version: 10,
|
||||
data
|
||||
};
|
||||
var results = yield Zotero.Sync.Data.Local.processObjectsFromJSON(
|
||||
type, libraryID, [json], { stopOnError: true }
|
||||
);
|
||||
assert.isTrue(results[0].processed);
|
||||
assert.isUndefined(results[0].changes);
|
||||
assert.isUndefined(results[0].conflicts);
|
||||
assert.equal(obj.version, 10);
|
||||
assert.equal(obj.getField('ISBN'), isbn);
|
||||
assert.isFalse(obj.synced);
|
||||
});
|
||||
|
||||
it("should delete older versions in sync cache after processing", function* () {
|
||||
var libraryID = Zotero.Libraries.userLibraryID;
|
||||
|
||||
|
@ -1835,5 +1864,58 @@ describe("Zotero.Sync.Data.Local", function() {
|
|||
]
|
||||
);
|
||||
})
|
||||
|
||||
it("should automatically use local hyphenated ISBN value if only difference", function () {
|
||||
var json1 = {
|
||||
key: "AAAAAAAA",
|
||||
version: 1234,
|
||||
itemType: "book",
|
||||
ISBN: "978-0-335-22006-9"
|
||||
};
|
||||
var json2 = {
|
||||
key: "AAAAAAAA",
|
||||
version: 1235,
|
||||
itemType: "book",
|
||||
ISBN: "9780335220069"
|
||||
};
|
||||
var ignoreFields = ['dateAdded', 'dateModified'];
|
||||
var result = Zotero.Sync.Data.Local._reconcileChangesWithoutCache(
|
||||
'item', json1, json2, ignoreFields
|
||||
);
|
||||
assert.lengthOf(result.changes, 0);
|
||||
assert.lengthOf(result.conflicts, 0);
|
||||
assert.isTrue(result.localChanged);
|
||||
});
|
||||
|
||||
it("should automatically use remote hyphenated ISBN value if only difference", function () {
|
||||
var json1 = {
|
||||
key: "AAAAAAAA",
|
||||
version: 1234,
|
||||
itemType: "book",
|
||||
ISBN: "9780335220069"
|
||||
};
|
||||
var json2 = {
|
||||
key: "AAAAAAAA",
|
||||
version: 1235,
|
||||
itemType: "book",
|
||||
ISBN: "978-0-335-22006-9"
|
||||
};
|
||||
var ignoreFields = ['dateAdded', 'dateModified'];
|
||||
var result = Zotero.Sync.Data.Local._reconcileChangesWithoutCache(
|
||||
'item', json1, json2, ignoreFields
|
||||
);
|
||||
assert.sameDeepMembers(
|
||||
result.changes,
|
||||
[
|
||||
{
|
||||
field: "ISBN",
|
||||
op: "add",
|
||||
value: "978-0-335-22006-9"
|
||||
}
|
||||
]
|
||||
);
|
||||
assert.lengthOf(result.conflicts, 0);
|
||||
assert.isFalse(result.localChanged);
|
||||
});
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue