Automatically correct invalid timestamps on sync error

This commit is contained in:
Dan Stillman 2011-02-22 02:45:31 +00:00
parent 2f4de0e803
commit bfbfd07910

View file

@ -1944,6 +1944,33 @@ Zotero.Sync.Server = new function () {
}, 1);
break;
case 'INVALID_TIMESTAMP':
var validClock = Zotero.DB.valueQuery("SELECT CURRENT_TIMESTAMP BETWEEN '1970-01-01 00:00:01' AND '2038-01-19 03:14:07'");
if (!validClock) {
// TODO: localize
_error("The system clock is set to an invalid time. You will need to correct this to sync with the Zotero server.");
}
setTimeout(function () {
Zotero.DB.beginTransaction();
var types = ['collections', 'creators', 'items', 'savedSearches', 'tags'];
for each (var type in types) {
var sql = "UPDATE " + type + " SET dateAdded=CURRENT_TIMESTAMP "
+ "WHERE dateAdded NOT BETWEEN '1970-01-01 00:00:01' AND '2038-01-19 03:14:07'";
Zotero.DB.query(sql);
var sql = "UPDATE " + type + " SET dateModified=CURRENT_TIMESTAMP "
+ "WHERE dateModified NOT BETWEEN '1970-01-01 00:00:01' AND '2038-01-19 03:14:07'";
Zotero.DB.query(sql);
var sql = "UPDATE " + type + " SET clientDateModified=CURRENT_TIMESTAMP "
+ "WHERE clientDateModified NOT BETWEEN '1970-01-01 00:00:01' AND '2038-01-19 03:14:07'";
Zotero.DB.query(sql);
}
Zotero.DB.commitTransaction();
}, 1);
break;
case 'UPGRADE_REQUIRED':
Zotero.Sync.Server.upgradeRequired = true;
break;