From 08d322932d90a96ec0e27268c955fe9f135a68a8 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 8 Oct 2017 04:42:42 -0400 Subject: [PATCH] Fix sync error from invalid link mode in database And add cleanup step to DB integrity check --- chrome/content/zotero/xpcom/attachments.js | 1 + chrome/content/zotero/xpcom/data/item.js | 5 ++++- chrome/content/zotero/xpcom/schema.js | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index eff18de43..9889b72a0 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -24,6 +24,7 @@ */ Zotero.Attachments = new function(){ + // Keep in sync with Zotero.Schema.integrityCheck() this.LINK_MODE_IMPORTED_FILE = 0; this.LINK_MODE_IMPORTED_URL = 1; this.LINK_MODE_LINKED_FILE = 2; diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 0bc14ddb9..3ecab174f 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -349,7 +349,10 @@ Zotero.Item.prototype._parseRowData = function(row) { break; case 'attachmentLinkMode': - val = val !== null ? parseInt(val) : false; + val = val !== null + ? parseInt(val) + // Shouldn't happen + : Zotero.Attachments.LINK_MODE_IMPORTED_URL; break; case 'attachmentPath': diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index a833c26fc..8a61736be 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -1329,6 +1329,11 @@ Zotero.Schema = new function(){ [ "SELECT COUNT(*) > 1 FROM fulltextItems WHERE itemID NOT IN (SELECT itemID FROM items WHERE itemTypeID=14)", "DELETE FROM fulltextItems WHERE itemID NOT IN (SELECT itemID FROM items WHERE itemTypeID=14)" + ], + // Invalid link mode -- set to imported url + [ + "SELECT COUNT(*) > 1 FROM itemAttachments WHERE linkMode NOT IN (0,1,2,3)", + "UPDATE itemAttachments SET linkMode=1 WHERE linkMode NOT IN (0,1,2,3)" ] ];