Add pref to disable full-text syncing, and prompt existing users on sync

FT sync is enabled by default for new users and configurable in the Sync
prefs.

Also disable downgrades once full-text sync is enabled, since otherwise
someone switching back and forth between old and new versions could miss
full-text content updates.
This commit is contained in:
Dan Stillman 2013-11-05 05:01:35 -05:00
parent 0c3529170f
commit a3a7a1d0cf
5 changed files with 106 additions and 32 deletions

View file

@ -32,6 +32,7 @@
<preferences>
<preference id="pref-sync-autosync" name="extensions.zotero.sync.autoSync" type="bool"/>
<preference id="pref-sync-username" name="extensions.zotero.sync.server.username" type="string" instantApply="true"/>
<preference id="pref-sync-fulltext-enabled" name="extensions.zotero.sync.fulltext.enabled" type="bool"/>
<preference id="pref-storage-enabled" name="extensions.zotero.sync.storage.enabled" type="bool"/>
<preference id="pref-storage-protocol" name="extensions.zotero.sync.storage.protocol" type="string"
onchange="Zotero_Preferences.Sync.unverifyStorageServer()"/>
@ -76,6 +77,15 @@
<box/>
<checkbox label="&zotero.preferences.sync.syncAutomatically;" preference="pref-sync-autosync"/>
</row>
<row>
<box/>
<vbox>
<!-- TODO: localize -->
<checkbox label="Sync full-text content"
preference="pref-sync-fulltext-enabled"
tooltiptext="Zotero can sync the full-text content of files in your Zotero libraries with zotero.org and other computers, allowing you to easily search for your files wherever you are. The full-text content of your files will not be shared publicly."/>
</vbox>
</row>
<!--
<row>
<box/>

View file

@ -1446,7 +1446,10 @@ Zotero.Schema = new function(){
Zotero.Schema.updateCustomTables(true);
_updateDBVersion('system', _getSchemaSQLVersion('system'));
_updateDBVersion('userdata', _getSchemaSQLVersion('userdata'));
// TEMP: 77 is for full-text syncing. New users don't need the
// prompt, so initialize new databases to 77.
//_updateDBVersion('userdata', _getSchemaSQLVersion('userdata'));
_updateDBVersion('userdata', 77);
_updateDBVersion('userdata2', _getSchemaSQLVersion('userdata2'));
_updateDBVersion('triggers', _getSchemaSQLVersion('triggers'));
@ -1792,7 +1795,11 @@ Zotero.Schema = new function(){
return false;
}
if (fromVersion > toVersion){
// 77 is a hack for full-text content syncing
if (fromVersion == 77) {
return false;
}
else if (fromVersion > toVersion) {
throw("Zotero user data DB version is newer than SQL file");
}

View file

@ -1368,6 +1368,44 @@ Zotero.Sync.Server = new function () {
_error(e);
}
// TEMP
if (Zotero.Prefs.get("sync.fulltext.enabled") &&
Zotero.DB.valueQuery("SELECT version FROM version WHERE schema='userdata'") < 77) {
// Don't show multiple times on idle
_syncInProgress = true;
let ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
let buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING)
+ ps.BUTTON_DELAY_ENABLE;
let index = ps.confirmEx(
null,
"New: Full-Text Content Syncing",
"Zotero can now sync the full-text content of files in your Zotero libraries "
+ "with zotero.org and other computers, allowing you to easily search for "
+ "your files wherever you are. The full-text content of your files will "
+ "not be shared publicly.\n\n"
+ "You can change this setting later from the Sync pane of the Zotero "
+ "preferences.",
buttonFlags,
"Use Full-Text Syncing",
"Not Now",
null, null, {}
);
_syncInProgress = false;
// Enable
if (index == 0) {
Zotero.DB.query("UPDATE version SET version=77 WHERE schema='userdata'");
}
// Disable
else {
Zotero.Prefs.set("sync.fulltext.enabled", false);
}
}
username = encodeURIComponent(username);
password = encodeURIComponent(password);
var body = _apiVersionComponent
@ -1469,7 +1507,12 @@ Zotero.Sync.Server = new function () {
body += '&upload=1';
}
body += Zotero.Fulltext.getUndownloadedPostData();
if (Zotero.Prefs.get("sync.fulltext.enabled")) {
body += "&ft=1" + Zotero.Fulltext.getUndownloadedPostData();
}
else {
body += "&ft=0";
}
Zotero.Sync.Runner.setSyncStatus(Zotero.getString('sync.status.gettingUpdatedData'));
@ -3574,34 +3617,36 @@ Zotero.Sync.Server.Data = new function() {
docElem.appendChild(settingsNode);
}
// Add up to 500K characters of full-text content
try {
var rows = Zotero.Fulltext.getUnsyncedContent(500000);
}
catch (e) {
Zotero.debug(e, 1);
Components.utils.reportError(e);
var rows = [];
}
if (rows.length) {
let fulltextsNode = doc.createElement('fulltexts');
syncSession.fulltextItems = [];
for (let i=0; i<rows.length; i++) {
syncSession.fulltextItems.push({
libraryID: rows[i].libraryID,
key: rows[i].key
})
let node = doc.createElement('fulltext');
node.setAttribute('libraryID', rows[i].libraryID ? rows[i].libraryID : Zotero.libraryID);
node.setAttribute('key', rows[i].key);
node.setAttribute('indexedChars', rows[i].indexedChars);
node.setAttribute('totalChars', rows[i].totalChars);
node.setAttribute('indexedPages', rows[i].indexedPages);
node.setAttribute('totalPages', rows[i].totalPages);
node.appendChild(doc.createTextNode(_xmlize(rows[i].text)));
fulltextsNode.appendChild(node);
if (Zotero.Prefs.get("sync.fulltext.enabled")) {
// Add up to 500K characters of full-text content
try {
var rows = Zotero.Fulltext.getUnsyncedContent(500000);
}
catch (e) {
Zotero.debug(e, 1);
Components.utils.reportError(e);
var rows = [];
}
if (rows.length) {
let fulltextsNode = doc.createElement('fulltexts');
syncSession.fulltextItems = [];
for (let i=0; i<rows.length; i++) {
syncSession.fulltextItems.push({
libraryID: rows[i].libraryID,
key: rows[i].key
})
let node = doc.createElement('fulltext');
node.setAttribute('libraryID', rows[i].libraryID ? rows[i].libraryID : Zotero.libraryID);
node.setAttribute('key', rows[i].key);
node.setAttribute('indexedChars', rows[i].indexedChars);
node.setAttribute('totalChars', rows[i].totalChars);
node.setAttribute('indexedPages', rows[i].indexedPages);
node.setAttribute('totalPages', rows[i].totalPages);
node.appendChild(doc.createTextNode(_xmlize(rows[i].text)));
fulltextsNode.appendChild(node);
}
docElem.appendChild(fulltextsNode);
}
docElem.appendChild(fulltextsNode);
}
// Deletions

View file

@ -548,8 +548,6 @@ Components.utils.import("resource://gre/modules/Services.jsm");
Zotero.DB.addCallback('commit', Zotero.Notifier.commit);
Zotero.DB.addCallback('rollback', Zotero.Notifier.reset);
Zotero.Fulltext.init();
// Require >=2.1b3 database to ensure proper locking
if (Zotero.isStandalone && Zotero.Schema.getDBVersion('system') > 0 && Zotero.Schema.getDBVersion('system') < 31) {
var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
@ -641,6 +639,8 @@ Components.utils.import("resource://gre/modules/Services.jsm");
}
}
Zotero.Fulltext.init();
Zotero.DB.startDummyStatement();
// Populate combined tables for custom types and fields -- this is likely temporary
@ -2275,6 +2275,17 @@ Zotero.Prefs = new function(){
}
break;
// TEMP
case "sync.fulltext.enabled":
if (this.get("sync.fulltext.enabled")) {
// Disable downgrades if full-text sync is enabled, since otherwise
// we could miss full-text content updates
if (Zotero.DB.valueQuery("SELECT version FROM version WHERE schema='userdata'") < 77) {
Zotero.DB.query("UPDATE version SET version=77 WHERE schema='userdata'");
}
}
break;
case "search.quicksearch-mode":
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);

View file

@ -144,6 +144,7 @@ pref("extensions.zotero.sync.storage.deleteDelayDays", 30);
pref("extensions.zotero.sync.storage.groups.enabled", true);
pref("extensions.zotero.sync.storage.downloadMode.personal", "on-sync");
pref("extensions.zotero.sync.storage.downloadMode.groups", "on-sync");
pref("extensions.zotero.sync.fulltext.enabled", true);
// Proxy
pref("extensions.zotero.proxies.autoRecognize", true);