From 7d3311679edfa2cc8c710dc90f256668323ecab6 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 16 Nov 2017 06:43:18 -0500 Subject: [PATCH] Add creator fix to integrity check, and run at startup if necessary --- chrome/content/zotero/xpcom/data/creators.js | 29 ++++++++++++++++---- chrome/content/zotero/xpcom/schema.js | 5 ++++ 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 index ae21064df..753a04f8a 100644 --- 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 index db00171c3..2813c47a0 100644 --- 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 != ''" ] ];