commit 7d3311679edfa2cc8c710dc90f256668323ecab6
parent 1cb49cc5d3df16f28c45c8bc409a223a3164f959
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 16 Nov 2017 06:43:18 -0500
Add creator fix to integrity check, and run at startup if necessary
Diffstat:
2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/creators.js b/chrome/content/zotero/xpcom/data/creators.js
@@ -31,16 +31,33 @@ Zotero.Creators = new function() {
var _cache = {};
this.init = Zotero.Promise.coroutine(function* () {
+ var repaired = false;
var sql = "SELECT * FROM creators";
var rows = yield Zotero.DB.queryAsync(sql);
for (let i = 0; i < rows.length; i++) {
let row = rows[i];
- _cache[row.creatorID] = this.cleanData({
- // Avoid "DB column 'name' not found" warnings from the DB row Proxy
- firstName: row.firstName,
- lastName: row.lastName,
- fieldMode: row.fieldMode
- });
+ try {
+ _cache[row.creatorID] = this.cleanData({
+ // Avoid "DB column 'name' not found" warnings from the DB row Proxy
+ firstName: row.firstName,
+ lastName: row.lastName,
+ fieldMode: row.fieldMode
+ });
+ }
+ catch (e) {
+ // Automatically fix DB errors and try again
+ if (!repaired) {
+ Zotero.logError(e);
+ Zotero.logError("Trying integrity check to fix creator error");
+ yield Zotero.Schema.integrityCheck(true);
+ repaired = true;
+ rows = yield Zotero.DB.queryAsync(sql);
+ i = -1;
+ continue;
+ }
+
+ throw e;
+ }
}
});
diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js
@@ -1334,6 +1334,11 @@ Zotero.Schema = new function(){
[
"SELECT COUNT(*) > 0 FROM itemAttachments WHERE linkMode NOT IN (0,1,2,3)",
"UPDATE itemAttachments SET linkMode=1 WHERE linkMode NOT IN (0,1,2,3)"
+ ],
+ // Creators with first name can't be fieldMode 1
+ [
+ "SELECT COUNT(*) > 0 FROM creators WHERE fieldMode = 1 AND firstName != ''",
+ "UPDATE creators SET fieldMode = 0 WHERE fieldMode = 1 AND firstName != ''"
]
];