Fix creator migration from Extra
This commit is contained in:
parent
982bcff357
commit
23c936f016
4 changed files with 42 additions and 5 deletions
|
@ -4631,7 +4631,7 @@ Zotero.Item.prototype.migrateExtraFields = function () {
|
|||
this.setField(field, value);
|
||||
}
|
||||
if (creators.length) {
|
||||
this.setCreators([...item.getCreators(), ...creators]);
|
||||
this.setCreators([...this.getCreators(), ...creators]);
|
||||
}
|
||||
this.setField('extra', extra);
|
||||
if (!this.hasChanged()) {
|
||||
|
|
|
@ -1057,7 +1057,7 @@ Zotero.Utilities.Internal = {
|
|||
creatorType: possibleCreatorType
|
||||
};
|
||||
if (value.includes('||')) {
|
||||
let [first, last] = value.split(/\s*\|\|\s*/);
|
||||
let [last, first] = value.split(/\s*\|\|\s*/);
|
||||
c.firstName = first;
|
||||
c.lastName = last;
|
||||
}
|
||||
|
|
|
@ -74,6 +74,43 @@ describe("Zotero.Schema", function() {
|
|||
assert.equal(item.getField('extra'), 'number-of-pages: 11\nThis is another line.');
|
||||
assert.isFalse(item.synced);
|
||||
});
|
||||
|
||||
it("should migrate creator", async function () {
|
||||
var item = await createDataObject('item', { itemType: 'book' });
|
||||
item.setCreators([
|
||||
{
|
||||
firstName: 'Abc',
|
||||
lastName: 'Def',
|
||||
creatorType: 'author',
|
||||
fieldMode: 0
|
||||
}
|
||||
]);
|
||||
item.setField('extra', 'editor: Last || First\nFoo: Bar');
|
||||
item.synced = true;
|
||||
await item.saveTx();
|
||||
|
||||
schema.version++;
|
||||
schema.itemTypes.find(x => x.itemType == 'book').fields.splice(0, 1, { field: 'fooBar' })
|
||||
var newLocales = {};
|
||||
Object.keys(schema.locales).forEach((locale) => {
|
||||
var o = schema.locales[locale];
|
||||
o.fields.fooBar = 'Foo Bar';
|
||||
newLocales[locale] = o;
|
||||
});
|
||||
await Zotero.Schema._updateGlobalSchemaForTest(schema);
|
||||
await Zotero.Schema.migrateExtraFields();
|
||||
|
||||
var creators = item.getCreators();
|
||||
assert.lengthOf(creators, 2);
|
||||
assert.propertyVal(creators[0], 'firstName', 'Abc');
|
||||
assert.propertyVal(creators[0], 'lastName', 'Def');
|
||||
assert.propertyVal(creators[0], 'creatorTypeID', Zotero.CreatorTypes.getID('author'));
|
||||
assert.propertyVal(creators[1], 'firstName', 'First');
|
||||
assert.propertyVal(creators[1], 'lastName', 'Last');
|
||||
assert.propertyVal(creators[1], 'creatorTypeID', Zotero.CreatorTypes.getID('editor'));
|
||||
assert.equal(item.getField('extra'), 'Foo: Bar');
|
||||
assert.isFalse(item.synced);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -224,7 +224,7 @@ describe("Zotero.Utilities.Internal", function () {
|
|||
});
|
||||
|
||||
it("should extract a CSL name", function () {
|
||||
var str = 'container-author: First || Last';
|
||||
var str = 'container-author: Last || First';
|
||||
var { creators, extra } = Zotero.Utilities.Internal.extractExtraFields(str);
|
||||
assert.lengthOf(creators, 1);
|
||||
assert.propertyVal(creators[0], 'creatorType', 'bookAuthor');
|
||||
|
@ -235,7 +235,7 @@ describe("Zotero.Utilities.Internal", function () {
|
|||
|
||||
it("should extract a CSL name that's valid for a given item type", function () {
|
||||
var item = createUnsavedDataObject('item', { itemType: 'bookSection' });
|
||||
var str = 'container-author: First || Last';
|
||||
var str = 'container-author: Last || First';
|
||||
var { creators, extra } = Zotero.Utilities.Internal.extractExtraFields(str, item);
|
||||
assert.lengthOf(creators, 1);
|
||||
assert.propertyVal(creators[0], 'creatorType', 'bookAuthor');
|
||||
|
@ -246,7 +246,7 @@ describe("Zotero.Utilities.Internal", function () {
|
|||
|
||||
it("shouldn't extract a CSL name that's not valid for a given item type", function () {
|
||||
var item = createUnsavedDataObject('item', { itemType: 'journalArticle' });
|
||||
var str = 'container-author: First || Last';
|
||||
var str = 'container-author: Last || First';
|
||||
var { creators, extra } = Zotero.Utilities.Internal.extractExtraFields(str, item);
|
||||
assert.lengthOf(creators, 0);
|
||||
assert.strictEqual(extra, str);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue