Fix related-item relations pointing to a previous user account
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.)
This commit is contained in:
parent
43692ee564
commit
c96363746b
2 changed files with 18 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
-- 99
|
||||
-- 100
|
||||
|
||||
-- Copyright (c) 2009 Center for History and New Media
|
||||
-- George Mason University, Fairfax, Virginia, USA
|
||||
|
|
Loading…
Reference in a new issue