Recover orphaned notes that some people seem to have, though I'm not sure how they happened -- maybe due to the previous behavior of closing out incomplete transactions?

This commit is contained in:
Dan Stillman 2007-04-29 06:27:19 +00:00
parent 240e1a09e0
commit 58f1a67ffd
2 changed files with 21 additions and 1 deletions

View File

@ -1056,6 +1056,26 @@ Zotero.Schema = new function(){
if (i==32) {
Zotero.DB.query("UPDATE itemData SET fieldID=100 WHERE itemID IN (SELECT itemID FROM items WHERE itemTypeID=20) AND fieldID=14;");
}
if (i==33) {
var rows = Zotero.DB.query("SELECT * FROM itemNotes WHERE itemID NOT IN (SELECT itemID FROM items)");
if (rows) {
var colID = Zotero.getRandomID('collections', 'collectionID');
Zotero.DB.query("INSERT INTO collections VALUES (?,?,?)", [colID, "[Recovered Notes]", null]);
for (var j=0; j<rows.length; j++) {
if (rows[j].sourceItemID) {
var count = Zotero.DB.valueQuery("SELECT COUNT(*) FROM items WHERE itemID=?", rows[j].sourceItemID);
if (count == 0) {
Zotero.DB.query("UPDATE itemNotes SET sourceItemID=NULL WHERE itemID=?", rows[j].sourceItemID);
}
}
Zotero.DB.query("INSERT INTO items (itemID, itemTypeID) VALUES (?,?)", [rows[j].itemID, 1]);
var max = Zotero.DB.valueQuery("SELECT COUNT(*) FROM collectionItems WHERE collectionID=?", colID);
Zotero.DB.query("INSERT INTO collectionItems VALUES (?,?,?)", [colID, rows[j].itemID, max]);
}
}
}
}
_updateSchema('userdata');

View File

@ -1,4 +1,4 @@
-- 32
-- 33
-- This file creates tables containing user-specific data -- any changes
-- to existing tables made here must be mirrored in transition steps in