From 17a72dc0cf4ec0f60970a4db2ededaceba12cfc9 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 8 Jul 2008 15:02:14 +0000 Subject: [PATCH] Fix tag migration error ("oldIDs.map is not a function") --- chrome/content/zotero/xpcom/schema.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index 993b69e20..9507a665a 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -1517,17 +1517,13 @@ Zotero.Schema = new function(){ var types = Zotero.DB.columnQuery("SELECT DISTINCT tagType FROM tags WHERE tag LIKE ?", l); for each(var type in types) { var newTagID = Zotero.DB.valueQuery("SELECT tagID FROM tags WHERE tag=? AND tagType=?", [newTag, type]); - var oldIDs = Zotero.DB.columnQuery("SELECT tagID FROM tags WHERE tag LIKE ? AND tag != ? AND tagType=?", [l, l, type]); - if (!newTagID) { - if (oldIDs) { + var oldIDs = Zotero.DB.columnQuery("SELECT tagID FROM tags WHERE tag LIKE ? AND tag != ? AND tagType=?", [l, newTag, type]); + if (oldIDs) { + if (!newTagID) { newTagID = oldIDs[0]; } - else { - newTagID = Zotero.DB.valueQuery("SELECT MAX(tagID)+1 FROM tags"); - Zotero.DB.query("INSERT INTO tags VALUES (?,?,?)", [newTagID, newTag, type]); - } + Zotero.DB.query("UPDATE OR REPLACE itemTags SET tagID=? WHERE tagID IN (" + oldIDs.map(function () '?').join() + ")", [newTagID].concat(oldIDs)); } - Zotero.DB.query("UPDATE OR REPLACE itemTags SET tagID=? WHERE tagID IN (" + oldIDs.map(function () '?').join() + ")", [newTagID].concat(oldIDs)); newTags.push({ tagID: newTagID, tag: newTag, tagType: type }); } }