Update sync methods (#5467)
This commit is contained in:
parent
7a41283c6b
commit
8d7930f660
|
@ -601,7 +601,10 @@ SaveTiddlerTask.prototype.run = function(callback) {
|
||||||
tiddler = this.syncer.wiki.tiddlerExists(this.title) && this.syncer.wiki.getTiddler(this.title);
|
tiddler = this.syncer.wiki.tiddlerExists(this.title) && this.syncer.wiki.getTiddler(this.title);
|
||||||
this.syncer.logger.log("Dispatching 'save' task:",this.title);
|
this.syncer.logger.log("Dispatching 'save' task:",this.title);
|
||||||
if(tiddler) {
|
if(tiddler) {
|
||||||
this.syncer.syncadaptor.saveTiddler(tiddler,function(err,adaptorInfo,revision) {
|
this.syncer.syncadaptor.saveTiddler(tiddler,{
|
||||||
|
changeCount: changeCount,
|
||||||
|
tiddlerInfo: self.syncer.tiddlerInfo[self.title]
|
||||||
|
},function(err,adaptorInfo,revision) {
|
||||||
// If there's an error, exit without changing any internal state
|
// If there's an error, exit without changing any internal state
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
@ -615,8 +618,6 @@ SaveTiddlerTask.prototype.run = function(callback) {
|
||||||
};
|
};
|
||||||
// Invoke the callback
|
// Invoke the callback
|
||||||
callback(null);
|
callback(null);
|
||||||
},{
|
|
||||||
tiddlerInfo: self.syncer.tiddlerInfo[self.title]
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.syncer.logger.log(" Not Dispatching 'save' task:",this.title,"tiddler does not exist");
|
this.syncer.logger.log(" Not Dispatching 'save' task:",this.title,"tiddler does not exist");
|
||||||
|
@ -633,7 +634,9 @@ function DeleteTiddlerTask(syncer,title) {
|
||||||
DeleteTiddlerTask.prototype.run = function(callback) {
|
DeleteTiddlerTask.prototype.run = function(callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.syncer.logger.log("Dispatching 'delete' task:",this.title);
|
this.syncer.logger.log("Dispatching 'delete' task:",this.title);
|
||||||
this.syncer.syncadaptor.deleteTiddler(this.title,function(err) {
|
this.syncer.syncadaptor.deleteTiddler(this.title,{
|
||||||
|
tiddlerInfo: self.syncer.tiddlerInfo[this.title]
|
||||||
|
},function(err,adaptorInfo) {
|
||||||
// If there's an error, exit without changing any internal state
|
// If there's an error, exit without changing any internal state
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
@ -642,8 +645,6 @@ DeleteTiddlerTask.prototype.run = function(callback) {
|
||||||
delete self.syncer.tiddlerInfo[self.title];
|
delete self.syncer.tiddlerInfo[self.title];
|
||||||
// Invoke the callback
|
// Invoke the callback
|
||||||
callback(null);
|
callback(null);
|
||||||
},{
|
|
||||||
tiddlerInfo: self.syncer.tiddlerInfo[this.title]
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ Returns a revision ID.
|
||||||
Retrieves status information from the server. This method is optional.
|
Retrieves status information from the server. This method is optional.
|
||||||
|
|
||||||
|!Parameter |!Description |
|
|!Parameter |!Description |
|
||||||
|callback |Callback function invoked with parameters `err,isLoggedIn,username,isReadOnly` |
|
|callback |Callback function invoked with parameters `err,isLoggedIn,username,isReadOnly,isAnonymous,isPollingDisabled` |
|
||||||
|
|
||||||
!! `login(username,password,callback)`
|
!! `login(username,password,callback)`
|
||||||
|
|
||||||
|
@ -128,33 +128,40 @@ The syncer will use the `getUpdatedTiddlers()` method in preference to the `getS
|
||||||
|!Parameter |!Description |
|
|!Parameter |!Description |
|
||||||
|callback |Callback function invoked with parameter `err,tiddlers`, where `tiddlers` is an array of tiddler field objects |
|
|callback |Callback function invoked with parameter `err,tiddlers`, where `tiddlers` is an array of tiddler field objects |
|
||||||
|
|
||||||
!! `saveTiddler(tiddler,callback)`
|
!! `saveTiddler(tiddler,options,callback)`
|
||||||
|
|
||||||
Saves a tiddler to the server.
|
Saves a tiddler to the server.
|
||||||
|
|
||||||
|!Parameter |!Description |
|
|!Parameter |!Description |
|
||||||
|tiddler |Tiddler to be saved |
|
|tiddler |Tiddler to be saved |
|
||||||
|
|options |See below |
|
||||||
|callback |Callback function invoked with parameter `err,adaptorInfo,revision` |
|
|callback |Callback function invoked with parameter `err,adaptorInfo,revision` |
|
||||||
|tiddlerInfo |The tiddlerInfo maintained by the syncer for this tiddler |
|
|tiddlerInfo |The tiddlerInfo maintained by the syncer for this tiddler |
|
||||||
|
|
||||||
!! `loadTiddler(title,callback)`
|
!! `loadTiddler(title,options,callback)`
|
||||||
|
|
||||||
Loads a tiddler from the server.
|
Loads a tiddler from the server.
|
||||||
|
|
||||||
|!Parameter |!Description |
|
|!Parameter |!Description |
|
||||||
|title |Title of tiddler to be retrieved |
|
|title |Title of tiddler to be retrieved |
|
||||||
|
|options |See below |
|
||||||
|callback |Callback function invoked with parameter `err,tiddlerFields` |
|
|callback |Callback function invoked with parameter `err,tiddlerFields` |
|
||||||
|
|
||||||
!! `deleteTiddler(title,callback,options)`
|
!! `deleteTiddler(title,options,callback)`
|
||||||
|
|
||||||
Delete a tiddler from the server.
|
Delete a tiddler from the server.
|
||||||
|
|
||||||
|!Parameter |!Description |
|
|!Parameter |!Description |
|
||||||
|title |Title of tiddler to be deleted |
|
|title |Title of tiddler to be deleted |
|
||||||
|callback |Callback function invoked with parameter `err` |
|
|
||||||
|options |See below |
|
|options |See below |
|
||||||
|
|callback |Callback function invoked with parameter `err` |
|
||||||
|
|
||||||
The options parameter contains the following properties:
|
!!! Options
|
||||||
|
|
||||||
|
<<.from-version "5.2.0">> The signature of syncadaptor functions that accept callbacks has been changed so that the callback is always the last argument. A check for the old order of arguments means that this change is backwards compatible. The new order should be prefered when updating or writing new plugins.
|
||||||
|
|
||||||
|
The options parameter may contain the following properties, depending on the method called.
|
||||||
|
|
||||||
|!Property |!Description |
|
|!Property |!Description |
|
||||||
|
|changeCount |The //new// changeCount value for this tiddler |
|
||||||
|tiddlerInfo |The tiddlerInfo maintained by the syncer for this tiddler |
|
|tiddlerInfo |The tiddlerInfo maintained by the syncer for this tiddler |
|
||||||
|
|
|
@ -75,7 +75,14 @@ FileSystemAdaptor.prototype.getTiddlerFileInfo = function(tiddler,callback) {
|
||||||
/*
|
/*
|
||||||
Save a tiddler and invoke the callback with (err,adaptorInfo,revision)
|
Save a tiddler and invoke the callback with (err,adaptorInfo,revision)
|
||||||
*/
|
*/
|
||||||
FileSystemAdaptor.prototype.saveTiddler = function(tiddler,callback,options) {
|
FileSystemAdaptor.prototype.saveTiddler = function(tiddler,options,callback) {
|
||||||
|
// Check for pre v5.2.0 method signature:
|
||||||
|
if(typeof callback !== "function" && typeof options === "function"){
|
||||||
|
var optionsArg = callback;
|
||||||
|
callback = options;
|
||||||
|
options = optionsArg;
|
||||||
|
}
|
||||||
|
options = options || {};
|
||||||
var self = this;
|
var self = this;
|
||||||
var syncerInfo = options.tiddlerInfo || {};
|
var syncerInfo = options.tiddlerInfo || {};
|
||||||
this.getTiddlerFileInfo(tiddler,function(err,fileInfo) {
|
this.getTiddlerFileInfo(tiddler,function(err,fileInfo) {
|
||||||
|
@ -117,14 +124,28 @@ Load a tiddler and invoke the callback with (err,tiddlerFields)
|
||||||
|
|
||||||
We don't need to implement loading for the file system adaptor, because all the tiddler files will have been loaded during the boot process.
|
We don't need to implement loading for the file system adaptor, because all the tiddler files will have been loaded during the boot process.
|
||||||
*/
|
*/
|
||||||
FileSystemAdaptor.prototype.loadTiddler = function(title,callback) {
|
FileSystemAdaptor.prototype.loadTiddler = function(title,options,callback) {
|
||||||
|
// Check for pre v5.2.0 method signature:
|
||||||
|
if(typeof callback !== "function" && typeof options === "function"){
|
||||||
|
var optionsArg = callback;
|
||||||
|
callback = options;
|
||||||
|
options = optionsArg;
|
||||||
|
}
|
||||||
|
options = options || {};
|
||||||
callback(null,null);
|
callback(null,null);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Delete a tiddler and invoke the callback with (err)
|
Delete a tiddler and invoke the callback with (err)
|
||||||
*/
|
*/
|
||||||
FileSystemAdaptor.prototype.deleteTiddler = function(title,callback,options) {
|
FileSystemAdaptor.prototype.deleteTiddler = function(title,options,callback) {
|
||||||
|
// Check for pre v5.2.0 method signature:
|
||||||
|
if(typeof callback !== "function" && typeof options === "function"){
|
||||||
|
var optionsArg = callback;
|
||||||
|
callback = options;
|
||||||
|
options = optionsArg;
|
||||||
|
}
|
||||||
|
options = options || {};
|
||||||
var self = this,
|
var self = this,
|
||||||
fileInfo = this.boot.files[title];
|
fileInfo = this.boot.files[title];
|
||||||
// Only delete the tiddler if we have writable information for the file
|
// Only delete the tiddler if we have writable information for the file
|
||||||
|
|
|
@ -99,7 +99,14 @@ SaveTrailSyncAdaptor.prototype.getTiddlerInfo = function(tiddler) {
|
||||||
/*
|
/*
|
||||||
Save a tiddler and invoke the callback with (err,adaptorInfo,revision)
|
Save a tiddler and invoke the callback with (err,adaptorInfo,revision)
|
||||||
*/
|
*/
|
||||||
SaveTrailSyncAdaptor.prototype.saveTiddler = function(tiddler,callback) {
|
SaveTrailSyncAdaptor.prototype.saveTiddler = function(tiddler,options,callback) {
|
||||||
|
// Check for pre v5.2.0 method signature:
|
||||||
|
if(typeof callback !== "function" && typeof options === "function"){
|
||||||
|
var optionsArg = callback;
|
||||||
|
callback = options;
|
||||||
|
options = optionsArg;
|
||||||
|
}
|
||||||
|
options = options || {};
|
||||||
if($tw.wiki.checkTiddlerText(ENABLE_TIDDLER_TITLE,"yes")) {
|
if($tw.wiki.checkTiddlerText(ENABLE_TIDDLER_TITLE,"yes")) {
|
||||||
var isDraft = $tw.utils.hop(tiddler.fields,"draft.of");
|
var isDraft = $tw.utils.hop(tiddler.fields,"draft.of");
|
||||||
if(!isDraft || $tw.wiki.checkTiddlerText(ENABLE_DRAFTS_TIDDLER_TITLE,"yes")) {
|
if(!isDraft || $tw.wiki.checkTiddlerText(ENABLE_DRAFTS_TIDDLER_TITLE,"yes")) {
|
||||||
|
@ -112,14 +119,28 @@ SaveTrailSyncAdaptor.prototype.saveTiddler = function(tiddler,callback) {
|
||||||
/*
|
/*
|
||||||
Load a tiddler and invoke the callback with (err,tiddlerFields)
|
Load a tiddler and invoke the callback with (err,tiddlerFields)
|
||||||
*/
|
*/
|
||||||
SaveTrailSyncAdaptor.prototype.loadTiddler = function(title,callback) {
|
SaveTrailSyncAdaptor.prototype.loadTiddler = function(title,options,callback) {
|
||||||
|
// Check for pre v5.2.0 method signature:
|
||||||
|
if(typeof callback !== "function" && typeof options === "function"){
|
||||||
|
var optionsArg = callback;
|
||||||
|
callback = options;
|
||||||
|
options = optionsArg;
|
||||||
|
}
|
||||||
|
options = options || {};
|
||||||
callback(null,null);
|
callback(null,null);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Delete a tiddler and invoke the callback with (err)
|
Delete a tiddler and invoke the callback with (err)
|
||||||
*/
|
*/
|
||||||
SaveTrailSyncAdaptor.prototype.deleteTiddler = function(title,callback,options) {
|
SaveTrailSyncAdaptor.prototype.deleteTiddler = function(title,options,callback) {
|
||||||
|
// Check for pre v5.2.0 method signature:
|
||||||
|
if(typeof callback !== "function" && typeof options === "function"){
|
||||||
|
var optionsArg = callback;
|
||||||
|
callback = options;
|
||||||
|
options = optionsArg;
|
||||||
|
}
|
||||||
|
options = options || {};
|
||||||
callback(null,null);
|
callback(null,null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -182,7 +182,14 @@ TiddlyWebAdaptor.prototype.getSkinnyTiddlers = function(callback) {
|
||||||
/*
|
/*
|
||||||
Save a tiddler and invoke the callback with (err,adaptorInfo,revision)
|
Save a tiddler and invoke the callback with (err,adaptorInfo,revision)
|
||||||
*/
|
*/
|
||||||
TiddlyWebAdaptor.prototype.saveTiddler = function(tiddler,callback,options) {
|
TiddlyWebAdaptor.prototype.saveTiddler = function(tiddler,options,callback) {
|
||||||
|
// Check for pre v5.2.0 method signature:
|
||||||
|
if(typeof callback !== "function" && typeof options === "function"){
|
||||||
|
var optionsArg = callback;
|
||||||
|
callback = options;
|
||||||
|
options = optionsArg;
|
||||||
|
}
|
||||||
|
options = options || {};
|
||||||
var self = this;
|
var self = this;
|
||||||
if(this.isReadOnly) {
|
if(this.isReadOnly) {
|
||||||
return callback(null,options.tiddlerInfo.adaptorInfo);
|
return callback(null,options.tiddlerInfo.adaptorInfo);
|
||||||
|
@ -216,7 +223,14 @@ TiddlyWebAdaptor.prototype.saveTiddler = function(tiddler,callback,options) {
|
||||||
/*
|
/*
|
||||||
Load a tiddler and invoke the callback with (err,tiddlerFields)
|
Load a tiddler and invoke the callback with (err,tiddlerFields)
|
||||||
*/
|
*/
|
||||||
TiddlyWebAdaptor.prototype.loadTiddler = function(title,callback) {
|
TiddlyWebAdaptor.prototype.loadTiddler = function(title,options,callback) {
|
||||||
|
// Check for pre v5.2.0 method signature:
|
||||||
|
if(typeof callback !== "function" && typeof options === "function"){
|
||||||
|
var optionsArg = callback;
|
||||||
|
callback = options;
|
||||||
|
options = optionsArg;
|
||||||
|
}
|
||||||
|
options = options || {};
|
||||||
var self = this;
|
var self = this;
|
||||||
$tw.utils.httpRequest({
|
$tw.utils.httpRequest({
|
||||||
url: this.host + "recipes/" + encodeURIComponent(this.recipe) + "/tiddlers/" + encodeURIComponent(title),
|
url: this.host + "recipes/" + encodeURIComponent(this.recipe) + "/tiddlers/" + encodeURIComponent(title),
|
||||||
|
@ -235,7 +249,14 @@ Delete a tiddler and invoke the callback with (err)
|
||||||
options include:
|
options include:
|
||||||
tiddlerInfo: the syncer's tiddlerInfo for this tiddler
|
tiddlerInfo: the syncer's tiddlerInfo for this tiddler
|
||||||
*/
|
*/
|
||||||
TiddlyWebAdaptor.prototype.deleteTiddler = function(title,callback,options) {
|
TiddlyWebAdaptor.prototype.deleteTiddler = function(title,options,callback) {
|
||||||
|
// Check for pre v5.2.0 method signature:
|
||||||
|
if(typeof callback !== "function" && typeof options === "function"){
|
||||||
|
var optionsArg = callback;
|
||||||
|
callback = options;
|
||||||
|
options = optionsArg;
|
||||||
|
}
|
||||||
|
options = options || {};
|
||||||
var self = this;
|
var self = this;
|
||||||
if(this.isReadOnly) {
|
if(this.isReadOnly) {
|
||||||
return callback(null,options.tiddlerInfo.adaptorInfo);
|
return callback(null,options.tiddlerInfo.adaptorInfo);
|
||||||
|
|
Loading…
Reference in New Issue