www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit c96363746bfc482173a3376138d11fdd188926c5
parent 43692ee5648c2e62497c7ac9951c2ccda095c5be
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon, 26 Mar 2018 02:09:09 -0400

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.)

Diffstat:
Mchrome/content/zotero/xpcom/schema.js | 17+++++++++++++++++
Mresource/schema/userdata.sql | 2+-
2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js @@ -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 } diff --git a/resource/schema/userdata.sql b/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