Relations libraryID fixes
- For cross-library links, if both group libraries, store relation with source group. Otherwise, store with personal library. - Send libraryID when syncing - Update libraryID properly when syncing updated relation from server - Increment sync API version so server can send relation libraryIDs safely
This commit is contained in:
parent
7338e5e40f
commit
83216d6125
4 changed files with 54 additions and 16 deletions
|
@ -1180,7 +1180,12 @@ Zotero.Collection.prototype.addLinkedCollection = function (collection) {
|
||||||
Zotero.debug("Collections " + this.key + " and " + collection.key + " are already linked");
|
Zotero.debug("Collections " + this.key + " and " + collection.key + " are already linked");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Zotero.Relations.add(null, url1, predicate, url2);
|
|
||||||
|
// If both group libraries, store relation with source group.
|
||||||
|
// Otherwise, store with personal library.
|
||||||
|
var libraryID = (this.libraryID && item.libraryID) ? this.libraryID : null;
|
||||||
|
|
||||||
|
Zotero.Relations.add(libraryID, url1, predicate, url2);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -3621,7 +3621,12 @@ Zotero.Item.prototype.addLinkedItem = function (item) {
|
||||||
Zotero.debug("Items " + this.key + " and " + item.key + " are already linked");
|
Zotero.debug("Items " + this.key + " and " + item.key + " are already linked");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Zotero.Relations.add(null, url1, predicate, url2);
|
|
||||||
|
// If both group libraries, store relation with source group.
|
||||||
|
// Otherwise, store with personal library.
|
||||||
|
var libraryID = (this.libraryID && item.libraryID) ? this.libraryID : null;
|
||||||
|
|
||||||
|
Zotero.Relations.add(libraryID, url1, predicate, url2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -158,20 +158,46 @@ Zotero.Relation.prototype.save = function () {
|
||||||
throw ("Missing object in Zotero.Relation.save()");
|
throw ("Missing object in Zotero.Relation.save()");
|
||||||
}
|
}
|
||||||
|
|
||||||
var sql = "INSERT OR IGNORE INTO relations "
|
var sql = "INSERT INTO relations "
|
||||||
+ "(libraryID, subject, predicate, object, clientDateModified) "
|
+ "(libraryID, subject, predicate, object, clientDateModified) "
|
||||||
+ "VALUES (?, ?, ?, ?, ?)";
|
+ "VALUES (?, ?, ?, ?, ?)";
|
||||||
var insertID = Zotero.DB.query(
|
try {
|
||||||
sql,
|
var insertID = Zotero.DB.query(
|
||||||
[
|
sql,
|
||||||
this.libraryID,
|
[
|
||||||
this.subject,
|
this.libraryID,
|
||||||
this.predicate,
|
this.subject,
|
||||||
this.object,
|
this.predicate,
|
||||||
Zotero.DB.transactionDateTime
|
this.object,
|
||||||
]
|
Zotero.DB.transactionDateTime
|
||||||
);
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
// If above failed, try deleting existing row, in case libraryID has changed
|
||||||
|
Zotero.DB.beginTransaction();
|
||||||
|
|
||||||
|
var sql2 = "SELECT COUNT(*) FROM relations WHERE subject=? AND predicate=? AND object=?";
|
||||||
|
if (Zotero.DB.valueQuery(sql2, [this.subject, this.predicate, this.object])) {
|
||||||
|
// Delete
|
||||||
|
sql2 = "DELETE FROM relations WHERE subject=? AND predicate=? AND object=?";
|
||||||
|
Zotero.DB.query(sql2, [this.subject, this.predicate, this.object]);
|
||||||
|
|
||||||
|
// Insert with original query
|
||||||
|
var insertID = Zotero.DB.query(
|
||||||
|
sql,
|
||||||
|
[
|
||||||
|
this.libraryID,
|
||||||
|
this.subject,
|
||||||
|
this.predicate,
|
||||||
|
this.object,
|
||||||
|
Zotero.DB.transactionDateTime
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.DB.commitTransaction();
|
||||||
|
}
|
||||||
return insertID;
|
return insertID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +225,7 @@ Zotero.Relation.prototype.erase = function () {
|
||||||
|
|
||||||
Zotero.Relation.prototype.toXML = function () {
|
Zotero.Relation.prototype.toXML = function () {
|
||||||
var xml = <relation/>;
|
var xml = <relation/>;
|
||||||
|
xml.@libraryID = this.libraryID;
|
||||||
xml.subject = this.subject;
|
xml.subject = this.subject;
|
||||||
xml.predicate = this.predicate;
|
xml.predicate = this.predicate;
|
||||||
xml.object = this.object;
|
xml.object = this.object;
|
||||||
|
|
|
@ -1209,7 +1209,7 @@ Zotero.Sync.Server = new function () {
|
||||||
this.manualSyncRequired = false;
|
this.manualSyncRequired = false;
|
||||||
this.upgradeRequired = false;
|
this.upgradeRequired = false;
|
||||||
this.nextLocalSyncDate = false;
|
this.nextLocalSyncDate = false;
|
||||||
this.apiVersion = 8;
|
this.apiVersion = 9;
|
||||||
|
|
||||||
default xml namespace = '';
|
default xml namespace = '';
|
||||||
|
|
||||||
|
@ -2203,7 +2203,8 @@ Zotero.Sync.Server = new function () {
|
||||||
Zotero.userID = userID;
|
Zotero.userID = userID;
|
||||||
Zotero.libraryID = libraryID;
|
Zotero.libraryID = libraryID;
|
||||||
|
|
||||||
// Update userID in relations
|
// Update libraryID in relations, which we store for the local
|
||||||
|
// for some reason. All other objects use null for the local library.
|
||||||
if (lastUserID && lastLibraryID) {
|
if (lastUserID && lastLibraryID) {
|
||||||
Zotero.Relations.updateUser(lastUserID, lastLibraryID, userID, libraryID);
|
Zotero.Relations.updateUser(lastUserID, lastLibraryID, userID, libraryID);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue