Better way of skipping migration of Place and Date from Extra

Or at least a way that we already have built-in and that only applies to
the call in `Zotero.Item::migrateExtraFields()`. This doesn't
distinguish between CSL fields (`publisher-place`, `event-place`,
`issued`) and actual Zotero field, and we really only need to skip
the former, but it's fine.

Follow-up to e3cfeee81, related to #3030
This commit is contained in:
Dan Stillman 2023-03-21 06:23:16 -04:00
parent e3cfeee813
commit 1aa82094f1
4 changed files with 28 additions and 35 deletions

View file

@ -5442,7 +5442,16 @@ Zotero.Item.prototype.migrateExtraFields = function () {
try { try {
var { itemType, fields, creators, extra } = Zotero.Utilities.Internal.extractExtraFields( var { itemType, fields, creators, extra } = Zotero.Utilities.Internal.extractExtraFields(
originalExtra, this originalExtra,
this,
[
// Skip 'publisher-place' and 'event-place' for now, since the mappings will be changed
// https://github.com/citation-style-language/zotero-bits/issues/6
'place',
// Skip 'issued' for now, since we don't support date ranges in Date
// https://github.com/zotero/zotero/issues/3030
'date'
]
); );
if (itemType) { if (itemType) {
let originalType = this.itemTypeID; let originalType = this.itemTypeID;

View file

@ -1297,20 +1297,9 @@ Zotero.Utilities.Internal = {
return true; return true;
} }
// Skip for now, since the mappings to Place will be changed
// https://github.com/citation-style-language/zotero-bits/issues/6
if (key == 'event-place' || key == 'publisher-place') {
return true;
}
// Skip for now, since we don't support date ranges
// https://github.com/zotero/zotero/issues/3030
if (key == 'issued') {
return true;
}
// Fields // Fields
let possibleFields = fieldNames.get(key); let possibleFields = fieldNames.get(key);
// No valid fields // No valid fields
if (possibleFields) { if (possibleFields) {
let added = false; let added = false;

View file

@ -236,6 +236,20 @@ describe("Zotero.Schema", function() {
assert.equal(item.getField('extra'), 'type: invalid'); assert.equal(item.getField('extra'), 'type: invalid');
assert.isTrue(item.synced); assert.isTrue(item.synced);
}); });
it("shouldn't migrate certain fields temporarily", async function () {
var item = await createDataObject('item', { itemType: 'book' });
var extra = 'event-place: Event Place\npublisher-place: Publisher Place\nIssued: 2020/2023';
item.setField('extra', extra);
item.synced = true;
await item.saveTx();
await migrate();
assert.equal(item.getField('place'), '');
assert.equal(item.getField('date'), '');
assert.equal(item.getField('extra'), extra);
});
}); });
}); });

View file

@ -248,7 +248,7 @@ describe("Zotero.Utilities.Internal", function () {
assert.equal(creators[0].name, 'Bar'); assert.equal(creators[0].name, 'Bar');
}); });
it.skip("should extract a CSL date field", function () { it("should extract a CSL date field", function () {
var str = 'issued: 2000'; var str = 'issued: 2000';
var { fields, extra } = Zotero.Utilities.Internal.extractExtraFields(str); var { fields, extra } = Zotero.Utilities.Internal.extractExtraFields(str);
assert.equal(fields.size, 1); assert.equal(fields.size, 1);
@ -286,13 +286,11 @@ describe("Zotero.Utilities.Internal", function () {
}); });
it("should extract the citeproc-js cheater syntax", function () { it("should extract the citeproc-js cheater syntax", function () {
//var issued = '{:number-of-pages:11}\n{:issued:2014}'; var issued = '{:number-of-pages:11}\n{:issued:2014}';
var issued = '{:number-of-pages:11}\n{:archive_location:Location}';
var { fields, extra } = Zotero.Utilities.Internal.extractExtraFields(issued); var { fields, extra } = Zotero.Utilities.Internal.extractExtraFields(issued);
assert.equal(fields.size, 2); assert.equal(fields.size, 2);
assert.equal(fields.get('numPages'), 11); assert.equal(fields.get('numPages'), 11);
assert.equal(fields.get('archiveLocation'), 'Location'); assert.equal(fields.get('date'), 2014);
//assert.equal(fields.get('date'), 2014);
assert.strictEqual(extra, ''); assert.strictEqual(extra, '');
}); });
@ -302,23 +300,6 @@ describe("Zotero.Utilities.Internal", function () {
assert.equal(fields.size, 0); assert.equal(fields.size, 0);
assert.strictEqual(extra, str); assert.strictEqual(extra, str);
}); });
it("should ignore both Event Place and Publisher Place (temporary)", function () {
var str = "Event Place: Foo\nPublisher Place: Bar";
var { fields, extra } = Zotero.Utilities.Internal.extractExtraFields(str);
Zotero.debug([...fields.entries()]);
assert.equal(fields.size, 0);
assert.equal(extra, "Event Place: Foo\nPublisher Place: Bar");
});
// Re-enable "should extract a CSL date field" and cheater-syntax lines above when removed
it("should ignore Issued (temporary)", function () {
var str = "Issued: 1994/1998";
var { fields, extra } = Zotero.Utilities.Internal.extractExtraFields(str);
Zotero.debug([...fields.entries()]);
assert.equal(fields.size, 0);
assert.equal(extra, "Issued: 1994/1998");
});
}); });
describe("#combineExtraFields", function () { describe("#combineExtraFields", function () {