Fix sync error from invalid link mode in database

And add cleanup step to DB integrity check
This commit is contained in:
Dan Stillman 2017-10-08 04:42:42 -04:00
parent 773a93f55d
commit 08d322932d
3 changed files with 10 additions and 1 deletions

View file

@ -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;

View file

@ -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':

View file

@ -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)"
]
];