Remove obsolete sync code
This commit is contained in:
parent
d07756d68d
commit
318528df4d
1 changed files with 0 additions and 488 deletions
|
@ -94,112 +94,6 @@ Zotero.Sync = new function() {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Date} olderThanDate Retrieve objects last updated before this date
|
||||
* @param {Date} newerThanDate Retrieve objects last updated after this date
|
||||
* @param {Zotero.Sync.Server.ObjectKeySet}
|
||||
*/
|
||||
this.getObjectsByDate = function (olderThanDate, newerThanDate, objectKeySet) {
|
||||
var funcName = "Zotero.Sync.getObjectsByDate()";
|
||||
if (olderThanDate && olderThanDate.constructor.name != 'Date') {
|
||||
throw ("olderThanDate must be a Date or FALSE in " + funcName)
|
||||
}
|
||||
if (newerThanDate && newerThanDate.constructor.name != 'Date') {
|
||||
throw ("newerThanDate must be a Date or FALSE in " + funcName)
|
||||
}
|
||||
|
||||
// If either not set (first sync) or dates overlap, retrieve all objects
|
||||
if ((!olderThanDate || !newerThanDate) ||
|
||||
(olderThanDate && newerThanDate && olderThanDate > newerThanDate)) {
|
||||
olderThanDate = null;
|
||||
newerThanDate = null;
|
||||
var all = true;
|
||||
}
|
||||
|
||||
for (var type in this.syncObjects) {
|
||||
if (type == 'setting' || type == 'fulltext') {
|
||||
continue;
|
||||
}
|
||||
|
||||
var Types = this.syncObjects[type].plural; // 'Items'
|
||||
var types = Types.toLowerCase(); // 'items'
|
||||
|
||||
Zotero.debug("Getting updated local " + types);
|
||||
|
||||
if (olderThanDate) {
|
||||
var earlierIDs = Zotero[Types].getOlder(olderThanDate);
|
||||
if (earlierIDs) {
|
||||
objectKeySet.addIDs(type, earlierIDs);
|
||||
}
|
||||
}
|
||||
|
||||
if (newerThanDate || all) {
|
||||
var laterIDs = Zotero[Types].getNewer(newerThanDate);
|
||||
if (laterIDs) {
|
||||
objectKeySet.addIDs(type, laterIDs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Date} lastSyncDate JS Date object
|
||||
* @param {Zotero.Sync.Server.ObjectKeySet}
|
||||
* @return TRUE if found, FALSE if none, or -1 if last sync time is before start of log
|
||||
*/
|
||||
this.getDeletedObjects = function (lastSyncDate, objectKeySet) {
|
||||
if (lastSyncDate && lastSyncDate.constructor.name != 'Date') {
|
||||
throw ('lastSyncDate must be a Date or FALSE in '
|
||||
+ 'Zotero.Sync.getDeletedObjects()')
|
||||
}
|
||||
|
||||
var sql = "SELECT version FROM version WHERE schema='syncdeletelog'";
|
||||
var syncLogStart = Zotero.DB.valueQuery(sql);
|
||||
if (!syncLogStart) {
|
||||
throw ('syncLogStart not found in Zotero.Sync.getDeletedObjects()');
|
||||
}
|
||||
|
||||
// Last sync time is before start of log
|
||||
if (lastSyncDate && new Date(syncLogStart * 1000) > lastSyncDate) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
var param = false;
|
||||
var sql = "SELECT syncObjectTypeID, libraryID, key FROM syncDeleteLog";
|
||||
if (lastSyncDate) {
|
||||
param = Zotero.Date.toUnixTimestamp(lastSyncDate);
|
||||
sql += " WHERE timestamp>?";
|
||||
}
|
||||
sql += " ORDER BY timestamp";
|
||||
var rows = Zotero.DB.query(sql, param);
|
||||
|
||||
if (!rows) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var keys = {};
|
||||
for (var type in this.syncObjects) {
|
||||
keys[type] = [];
|
||||
}
|
||||
|
||||
var type;
|
||||
for each(var row in rows) {
|
||||
type = this.getObjectTypeName(row.syncObjectTypeID);
|
||||
keys[type].push({
|
||||
libraryID: row.libraryID,
|
||||
key: row.key
|
||||
});
|
||||
}
|
||||
|
||||
for (var type in keys) {
|
||||
objectKeySet.addLibraryKeyPairs(type, keys[type]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int deleteOlderThan Unix timestamp
|
||||
*/
|
||||
|
@ -229,134 +123,6 @@ Zotero.Sync = new function() {
|
|||
}
|
||||
|
||||
|
||||
|
||||
Zotero.Sync.ObjectKeySet = function () {
|
||||
// Set up key holders for different types
|
||||
var syncTypes = Zotero.Sync.syncObjects;
|
||||
for each(var type in syncTypes) {
|
||||
this[type.plural.toLowerCase()] = {};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Zotero.Sync.ObjectKeySet.prototype.addIDs = function (type, ids) {
|
||||
var Types = Zotero.Sync.syncObjects[type].plural;
|
||||
var types = Types.toLowerCase();
|
||||
|
||||
var obj, libraryID, key;
|
||||
for each(var id in ids) {
|
||||
obj = Zotero[Types].get(id);
|
||||
libraryID = obj.libraryID;
|
||||
if (!libraryID) {
|
||||
libraryID = 0; // current user
|
||||
}
|
||||
key = obj.key;
|
||||
if (!this[types][libraryID]) {
|
||||
this[types][libraryID] = {};
|
||||
}
|
||||
this[types][libraryID][key] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {String} type Sync object type (e.g., 'item', 'collection')
|
||||
* @param {Object[]} keyPairs Array of objects with 'libraryID' and 'key'
|
||||
*/
|
||||
Zotero.Sync.ObjectKeySet.prototype.addLibraryKeys = function (type, libraryID, keys) {
|
||||
var Types = Zotero.Sync.syncObjects[type].plural;
|
||||
var types = Types.toLowerCase();
|
||||
|
||||
var key;
|
||||
for each(var key in keys) {
|
||||
if (!libraryID) {
|
||||
libraryID = 0; // current user
|
||||
}
|
||||
if (!this[types][libraryID]) {
|
||||
this[types][libraryID] = {};
|
||||
}
|
||||
this[types][libraryID][key] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {String} type Sync object type (e.g., 'item', 'collection')
|
||||
* @param {Object[]} keyPairs Array of objects with 'libraryID' and 'key'
|
||||
*/
|
||||
Zotero.Sync.ObjectKeySet.prototype.addLibraryKeyPairs = function (type, keyPairs) {
|
||||
var Types = Zotero.Sync.syncObjects[type].plural;
|
||||
var types = Types.toLowerCase();
|
||||
|
||||
var libraryID, key;
|
||||
for each(var pair in keyPairs) {
|
||||
libraryID = pair.libraryID;
|
||||
if (!libraryID) {
|
||||
libraryID = 0; // current user
|
||||
}
|
||||
key = pair.key;
|
||||
if (!this[types][libraryID]) {
|
||||
this[types][libraryID] = {};
|
||||
}
|
||||
this[types][libraryID][key] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Zotero.Sync.ObjectKeySet.prototype.hasLibraryKey = function (type, libraryID, key) {
|
||||
var Types = Zotero.Sync.syncObjects[type].plural;
|
||||
var types = Types.toLowerCase();
|
||||
|
||||
if (!libraryID) {
|
||||
libraryID = 0;
|
||||
}
|
||||
|
||||
if (this[types] && this[types][libraryID] && this[types][libraryID][key]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Zotero.Sync.ObjectKeySet.prototype.getKeys = function (type, libraryID) {
|
||||
var Types = Zotero.Sync.syncObjects[type].plural;
|
||||
var types = Types.toLowerCase();
|
||||
|
||||
if (!libraryID) {
|
||||
libraryID = 0;
|
||||
}
|
||||
|
||||
if (!this[types] || !this[types][libraryID]) {
|
||||
return [];
|
||||
}
|
||||
|
||||
var keys = [];
|
||||
for (var key in this[types][libraryID]) {
|
||||
keys.push(key);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
||||
Zotero.Sync.ObjectKeySet.prototype.removeLibraryKeyPairs = function (type, keyPairs) {
|
||||
var Types = Zotero.Sync.syncObjects[type].plural;
|
||||
var types = Types.toLowerCase();
|
||||
|
||||
var libraryID, key;
|
||||
for each(var pair in keyPairs) {
|
||||
libraryID = pair.libraryID;
|
||||
if (!libraryID) {
|
||||
libraryID = 0; // current user
|
||||
}
|
||||
key = pair.key;
|
||||
if (this[types][libraryID]) {
|
||||
delete this[types][libraryID][key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Methods for syncing with the Zotero Server
|
||||
*/
|
||||
|
@ -365,7 +131,6 @@ Zotero.Sync.Server = new function () {
|
|||
this.sync = sync;
|
||||
this.clear = clear;
|
||||
this.resetClient = resetClient;
|
||||
this.logout = logout;
|
||||
|
||||
this.__defineGetter__('enabled', function () {
|
||||
if (_throttleTimeout && new Date() < _throttleTimeout) {
|
||||
|
@ -375,96 +140,6 @@ Zotero.Sync.Server = new function () {
|
|||
return this.username && this.password;
|
||||
});
|
||||
|
||||
this.__defineGetter__('username', function () {
|
||||
return Zotero.Prefs.get('sync.server.username');
|
||||
});
|
||||
|
||||
this.__defineGetter__('password', function () {
|
||||
var username = this.username;
|
||||
|
||||
if (!username) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (_cachedCredentials.username == username && _cachedCredentials.password) {
|
||||
return _cachedCredentials.password;
|
||||
}
|
||||
|
||||
Zotero.debug('Getting Zotero sync password');
|
||||
var loginManager = Components.classes["@mozilla.org/login-manager;1"]
|
||||
.getService(Components.interfaces.nsILoginManager);
|
||||
try {
|
||||
var logins = loginManager.findLogins({}, _loginManagerHost, _loginManagerURL, null);
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.debug(e);
|
||||
if (Zotero.isStandalone) {
|
||||
var msg = Zotero.getString('sync.error.loginManagerCorrupted1', Zotero.appName) + "\n\n"
|
||||
+ Zotero.getString('sync.error.loginManagerCorrupted2', [Zotero.appName, Zotero.appName]);
|
||||
}
|
||||
else {
|
||||
var msg = Zotero.getString('sync.error.loginManagerInaccessible') + "\n\n"
|
||||
+ Zotero.getString('sync.error.checkMasterPassword', Zotero.appName) + "\n\n"
|
||||
+ Zotero.getString('sync.error.corruptedLoginManager', Zotero.appName);
|
||||
}
|
||||
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
||||
.getService(Components.interfaces.nsIPromptService);
|
||||
ps.alert(null, Zotero.getString('general.error'), msg);
|
||||
return '';
|
||||
}
|
||||
|
||||
// Find user from returned array of nsILoginInfo objects
|
||||
for (var i = 0; i < logins.length; i++) {
|
||||
if (logins[i].username == username) {
|
||||
_cachedCredentials = {
|
||||
username: username,
|
||||
password: logins[i].password
|
||||
};
|
||||
return logins[i].password;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
});
|
||||
|
||||
this.__defineSetter__('password', function (password) {
|
||||
_sessionID = null;
|
||||
|
||||
var loginManager = Components.classes["@mozilla.org/login-manager;1"]
|
||||
.getService(Components.interfaces.nsILoginManager);
|
||||
var logins = loginManager.findLogins({}, _loginManagerHost, _loginManagerURL, null);
|
||||
for (var i = 0; i < logins.length; i++) {
|
||||
Zotero.debug('Clearing Zotero sync credentials');
|
||||
loginManager.removeLogin(logins[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
// Clear password for file sync
|
||||
Zotero.Sync.Storage.ZFS.clearCachedCredentials();
|
||||
|
||||
_cachedCredentials = {};
|
||||
|
||||
var username = this.username;
|
||||
|
||||
if (!username) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (password) {
|
||||
var nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
|
||||
Components.interfaces.nsILoginInfo, "init");
|
||||
|
||||
Zotero.debug('Setting Zotero sync password');
|
||||
var loginInfo = new nsLoginInfo(_loginManagerHost, _loginManagerURL,
|
||||
null, username, password, "", "");
|
||||
loginManager.addLogin(loginInfo);
|
||||
_cachedCredentials = {
|
||||
username: username,
|
||||
password: password
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
this.__defineGetter__("syncInProgress", function () _syncInProgress);
|
||||
this.__defineGetter__("updatesInProgress", function () _updatesInProgress);
|
||||
this.__defineGetter__("sessionIDComponent", function () {
|
||||
|
@ -479,15 +154,7 @@ Zotero.Sync.Server = new function () {
|
|||
this.manualSyncRequired = false;
|
||||
this.upgradeRequired = false;
|
||||
this.nextLocalSyncDate = false;
|
||||
this.apiVersion = 9;
|
||||
|
||||
var _loginManagerHost = 'chrome://zotero';
|
||||
var _loginManagerURL = 'Zotero Sync Server';
|
||||
|
||||
var _serverURL = ZOTERO_CONFIG.SYNC_URL;
|
||||
|
||||
var _apiVersionComponent = "version=" + this.apiVersion;
|
||||
var _cachedCredentials = {};
|
||||
var _syncInProgress;
|
||||
var _updatesInProgress;
|
||||
var _sessionID;
|
||||
|
@ -1086,34 +753,6 @@ Zotero.Sync.Server = new function () {
|
|||
}
|
||||
|
||||
|
||||
function logout(callback) {
|
||||
var url = _serverURL + "logout";
|
||||
var body = _apiVersionComponent
|
||||
+ '&' + Zotero.Sync.Server.sessionIDComponent;
|
||||
|
||||
_sessionID = null;
|
||||
|
||||
Zotero.HTTP.doPost(url, body, function (xmlhttp) {
|
||||
_checkResponse(xmlhttp);
|
||||
Zotero.debug(xmlhttp.responseText);
|
||||
|
||||
var response = xmlhttp.responseXML.childNodes[0];
|
||||
|
||||
if (response.firstChild.tagName == 'error') {
|
||||
_error(response.firstChild.firstChild.nodeValue);
|
||||
}
|
||||
|
||||
if (response.firstChild.tagName != 'loggedout') {
|
||||
_error('Invalid response from server', xmlhttp.responseText);
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function _checkResponse(xmlhttp, noReloadOnFailure) {
|
||||
if (!xmlhttp.responseText) {
|
||||
var channel = xmlhttp.channel;
|
||||
|
@ -2924,134 +2563,7 @@ Zotero.Sync.Server.Data = new function() {
|
|||
}
|
||||
|
||||
|
||||
this.tagToXML = function (tag, doc) {
|
||||
var tagElem = doc.createElement('tag');
|
||||
tagElem.setAttribute('libraryID', tag.libraryID ? tag.libraryID : Zotero.libraryID);
|
||||
tagElem.setAttribute('key', tag.key);
|
||||
tagElem.setAttribute('name', _xmlize(tag.name));
|
||||
if (tag.type) {
|
||||
tagElem.setAttribute('type', tag.type);
|
||||
}
|
||||
tagElem.setAttribute('dateAdded', tag.dateAdded);
|
||||
tagElem.setAttribute('dateModified', tag.dateModified);
|
||||
var linkedItems = tag.getLinkedItems();
|
||||
if (linkedItems) {
|
||||
var linkedItemKeys = [];
|
||||
for each(var linkedItem in linkedItems) {
|
||||
linkedItemKeys.push(linkedItem.key);
|
||||
}
|
||||
var itemsElem = doc.createElement('items');
|
||||
itemsElem.appendChild(doc.createTextNode(linkedItemKeys.join(' ')));
|
||||
tagElem.appendChild(itemsElem);
|
||||
}
|
||||
return tagElem;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert DOM <tag> node into an unsaved Zotero.Tag
|
||||
*
|
||||
* @param object tagNode DOM XML node with tag data
|
||||
* @param object tag (Optional) Existing Zotero.Tag to update
|
||||
* @param bool skipPrimary (Optional) Ignore passed primary fields
|
||||
*/
|
||||
this.xmlToTag = function (tagNode, tag, skipPrimary, defaultLibraryID, deletedItemKeys) {
|
||||
if (!tag) {
|
||||
tag = new Zotero.Tag;
|
||||
}
|
||||
else if (skipPrimary) {
|
||||
throw ("Cannot use new id with existing tag in "
|
||||
+ "Zotero.Sync.Server.Data.xmlToTag()");
|
||||
}
|
||||
|
||||
if (!skipPrimary) {
|
||||
tag.libraryID = _getLibraryID(tagNode.getAttribute('libraryID'), defaultLibraryID);
|
||||
tag.key = tagNode.getAttribute('key');
|
||||
tag.dateAdded = tagNode.getAttribute('dateAdded');
|
||||
tag.dateModified = tagNode.getAttribute('dateModified');
|
||||
}
|
||||
|
||||
tag.name = tagNode.getAttribute('name');
|
||||
var type = tagNode.getAttribute('type');
|
||||
tag.type = type ? parseInt(type) : 0;
|
||||
|
||||
var keys = _getFirstChildContent(tagNode, 'items');
|
||||
if (keys) {
|
||||
keys = keys.split(' ');
|
||||
var ids = [];
|
||||
for each(var key in keys) {
|
||||
var item = Zotero.Items.getByLibraryAndKey(tag.libraryID, key);
|
||||
if (!item) {
|
||||
// See note in xmlToCollection()
|
||||
if (deletedItemKeys && deletedItemKeys.indexOf(key) != -1) {
|
||||
Zotero.debug("Ignoring deleted linked item '" + key + "'");
|
||||
continue;
|
||||
}
|
||||
|
||||
var msg = "Linked item " + key + " doesn't exist in Zotero.Sync.Server.Data.xmlToTag()";
|
||||
var e = new Zotero.Error(msg, "MISSING_OBJECT");
|
||||
throw (e);
|
||||
}
|
||||
ids.push(item.id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
var ids = [];
|
||||
}
|
||||
tag.linkedItems = ids;
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {String} name Tag name
|
||||
* @param {Integer} type Tag type
|
||||
* @return {Integer[]|FALSE} Array of itemIDs of items linked to
|
||||
* deleted tag, or FALSE if no
|
||||
* matching tag found
|
||||
*/
|
||||
function _deleteConflictingTag(syncSession, name, type, libraryID) {
|
||||
var tagID = Zotero.Tags.getID(name, type, libraryID);
|
||||
if (tagID) {
|
||||
Zotero.debug("Deleting conflicting local '" + name + "' tag " + tagID);
|
||||
var tag = Zotero.Tags.get(tagID);
|
||||
// Tag has already been deleted, which can happen if the server has
|
||||
// two new tags that differ only in case, and one matches a local tag
|
||||
// with a different key, causing that tag to be deleted already.
|
||||
if (!tag) {
|
||||
Zotero.debug("Local tag " + tagID + " doesn't exist");
|
||||
return false;
|
||||
}
|
||||
var linkedItems = tag.getLinkedItems(true);
|
||||
Zotero.Tags.erase(tagID);
|
||||
Zotero.Tags.purge(tagID);
|
||||
|
||||
syncSession.removeFromUpdated(tag);
|
||||
//syncSession.addToDeleted(tag);
|
||||
|
||||
return linkedItems ? linkedItems : [];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function _getFirstChildContent(node, childName) {
|
||||
var elems = Zotero.Utilities.xpath(node, childName);
|
||||
return elems.length ? elems[0].textContent : "";
|
||||
}
|
||||
|
||||
|
||||
function _xmlize(str) {
|
||||
return str.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\ud800-\udfff\ufffe\uffff]/g, '\u2B1A');
|
||||
}
|
||||
|
||||
|
||||
function _getLibraryID(libraryID, defaultLibraryID) {
|
||||
if (!libraryID) {
|
||||
return null;
|
||||
}
|
||||
return libraryID == defaultLibraryID ? null : parseInt(libraryID);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue