Skip to content

Commit

Permalink
Fix related-item relations pointing to a previous user account
Browse files Browse the repository at this point in the history
If somebody switched accounts in a previous version, it was apparently
possible for related items to end up pointing at an item URI with the
old userID, which could cause a 403 on sync.

https://forums.zotero.org/discussion/70989/report-id-477331252

(5.0 deletes data when switching accounts to avoid exactly this sort of
bug.)
  • Loading branch information
dstillman committed Mar 26, 2018
1 parent 43692ee commit c963637
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions chrome/content/zotero/xpcom/schema.js
Expand Up @@ -2414,6 +2414,23 @@ Zotero.Schema = new function(){
yield Zotero.DB.queryAsync("DELETE FROM relationPredicates WHERE predicate='dc:isReplacedBy'");
}

else if (i == 100) {
let userID = yield Zotero.DB.valueQueryAsync("SELECT value FROM settings WHERE setting='account' AND key='userID'");
if (userID) {
let predicateID = yield Zotero.DB.valueQueryAsync("SELECT predicateID FROM relationPredicates WHERE predicate='dc:relation'");
let rows = yield Zotero.DB.queryAsync("SELECT itemID, object FROM items JOIN itemRelations IR USING (itemID) WHERE libraryID=? AND predicateID=?", [1, predicateID]);
for (let row of rows) {
let matches = row.object.match(/^http:\/\/zotero.org\/users\/(\d+)\/items\/([A-Z0-9]+)$/);
if (matches) {
// Wrong libraryID
if (matches[1] != userID) {
yield Zotero.DB.queryAsync(`UPDATE itemRelations SET object='http://zotero.org/users/${userID}/items/${matches[2]}' WHERE itemID=? AND predicateID=?`, [row.itemID, predicateID]);
}
}
}
}
}

// If breaking compatibility or doing anything dangerous, clear minorUpdateFrom
}

Expand Down
2 changes: 1 addition & 1 deletion resource/schema/userdata.sql
@@ -1,4 +1,4 @@
-- 99
-- 100

-- Copyright (c) 2009 Center for History and New Media
-- George Mason University, Fairfax, Virginia, USA
Expand Down

0 comments on commit c963637

Please sign in to comment.