parent
197d609f8e
commit
9ed48f3837
3 changed files with 23 additions and 3 deletions
|
@ -1250,6 +1250,11 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
||||||
env.sqlValues.push({ int: itemTypeID });
|
env.sqlValues.push({ int: itemTypeID });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNew || (this._changed.primaryData && this._changed.primaryData.dateAdded)) {
|
||||||
|
env.sqlColumns.push('dateAdded');
|
||||||
|
env.sqlValues.push(this.dateAdded ? this.dateAdded : Zotero.DB.transactionDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
// If a new item and Date Modified hasn't been provided, or an existing item and
|
// If a new item and Date Modified hasn't been provided, or an existing item and
|
||||||
// Date Modified hasn't changed from its previous value and skipDateModifiedUpdate wasn't
|
// Date Modified hasn't changed from its previous value and skipDateModifiedUpdate wasn't
|
||||||
// passed, use the current timestamp
|
// passed, use the current timestamp
|
||||||
|
@ -1269,9 +1274,6 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
||||||
|
|
||||||
if (env.sqlColumns.length) {
|
if (env.sqlColumns.length) {
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
env.sqlColumns.push('dateAdded');
|
|
||||||
env.sqlValues.push(this.dateAdded ? this.dateAdded : Zotero.DB.transactionDateTime);
|
|
||||||
|
|
||||||
env.sqlColumns.unshift('itemID');
|
env.sqlColumns.unshift('itemID');
|
||||||
env.sqlValues.unshift(parseInt(itemID));
|
env.sqlValues.unshift(parseInt(itemID));
|
||||||
|
|
||||||
|
|
|
@ -759,7 +759,14 @@ Zotero.Items = function() {
|
||||||
var toSave = {};
|
var toSave = {};
|
||||||
toSave[item.id] = item;
|
toSave[item.id] = item;
|
||||||
|
|
||||||
|
var earliestDateAdded = item.dateAdded;
|
||||||
|
|
||||||
for (let otherItem of otherItems) {
|
for (let otherItem of otherItems) {
|
||||||
|
// Use the earliest date added of all the items
|
||||||
|
if (otherItem.dateAdded < earliestDateAdded) {
|
||||||
|
earliestDateAdded = otherItem.dateAdded;
|
||||||
|
}
|
||||||
|
|
||||||
let otherItemURI = Zotero.URI.getItemURI(otherItem);
|
let otherItemURI = Zotero.URI.getItemURI(otherItem);
|
||||||
|
|
||||||
// Move child items to master
|
// Move child items to master
|
||||||
|
@ -824,6 +831,8 @@ Zotero.Items = function() {
|
||||||
yield otherItem.save();
|
yield otherItem.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item.setField('dateAdded', earliestDateAdded);
|
||||||
|
|
||||||
for (let i in toSave) {
|
for (let i in toSave) {
|
||||||
yield toSave[i].save();
|
yield toSave[i].save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,6 +191,15 @@ describe("Zotero.Items", function () {
|
||||||
assert.sameMembers(rels, [item2URI, item3URI]);
|
assert.sameMembers(rels, [item2URI, item3URI]);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should use the earliest Date Added", async function () {
|
||||||
|
var item1 = await createDataObject('item', { dateAdded: '2019-01-02 00:00:00' });
|
||||||
|
var item2 = await createDataObject('item', { dateAdded: '2019-01-01 00:00:00' });
|
||||||
|
var item3 = await createDataObject('item', { dateAdded: '2019-01-03 00:00:00' });
|
||||||
|
|
||||||
|
await Zotero.Items.merge(item1, [item2, item3]);
|
||||||
|
assert.equal(item1.dateAdded, '2019-01-01 00:00:00');
|
||||||
|
});
|
||||||
|
|
||||||
it("should merge two items when servant is linked to an item absent from cache", function* () {
|
it("should merge two items when servant is linked to an item absent from cache", function* () {
|
||||||
// two group libraries
|
// two group libraries
|
||||||
var groupOneInfo = yield createGroup({
|
var groupOneInfo = yield createGroup({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue