From 1ec37ebcbfda8efc38bc8f90c9d2381fd515823c Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 20 Apr 2023 03:21:33 -0400 Subject: [PATCH] Fix redundant Number on Dataset item type --- chrome/content/zotero/xpcom/data/items.js | 2 +- chrome/content/zotero/xpcom/schema.js | 13 +++++++++++-- resource/schema/global | 2 +- resource/schema/userdata.sql | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js index 1007dda01c..8417c4d446 100644 --- a/chrome/content/zotero/xpcom/data/items.js +++ b/chrome/content/zotero/xpcom/data/items.js @@ -556,7 +556,7 @@ Zotero.Items = function() { } catch (e) { if (e.message.includes('no such column: IA.authorName') - && await Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM version WHERE schema='userdata' AND version=120")) { + && await Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM version WHERE schema='userdata' AND version IN (120, 121)")) { await Zotero.DB.queryAsync("UPDATE version SET version=119 WHERE schema='userdata'"); Zotero.crash(); } diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index 9c8c301fc7..773376d5f0 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -3468,8 +3468,17 @@ Zotero.Schema = new function(){ } } - // TEMP: When adding 121, check whether IA.authorName fix in items.js::_loadAnnotations() - // should be updated + else if (i == 121) { + let datasetItemTypeID = await Zotero.DB.valueQueryAsync("SELECT itemTypeID FROM itemTypes WHERE typeName='dataset'"); + let numberFieldID = await Zotero.DB.valueQueryAsync("SELECT fieldID FROM fields WHERE fieldName='number'"); + if (datasetItemTypeID && numberFieldID) { + await Zotero.DB.queryAsync("DELETE FROM itemData WHERE fieldID=? AND itemID IN (SELECT itemID FROM items WHERE itemTypeID=?)", [numberFieldID, datasetItemTypeID]); + await Zotero.DB.queryAsync("DELETE FROM itemTypeFields WHERE itemTypeID=? AND fieldID=?", [datasetItemTypeID, numberFieldID]); + } + } + + // TEMP: When adding 122, check whether IA.authorName fix in items.js::_loadAnnotations() + // can be updated due to update steps being indempodent // If breaking compatibility or doing anything dangerous, clear minorUpdateFrom } diff --git a/resource/schema/global b/resource/schema/global index 46feab5ce7..1b12272d44 160000 --- a/resource/schema/global +++ b/resource/schema/global @@ -1 +1 @@ -Subproject commit 46feab5ce7eed164fe56127428f5ffb25a02cf0f +Subproject commit 1b12272d44134a652519e9192e5a936ac9fcd707 diff --git a/resource/schema/userdata.sql b/resource/schema/userdata.sql index dda3aa6953..da748e36f1 100644 --- a/resource/schema/userdata.sql +++ b/resource/schema/userdata.sql @@ -1,4 +1,4 @@ --- 120 +-- 121 -- Copyright (c) 2009 Center for History and New Media -- George Mason University, Fairfax, Virginia, USA