Update sync methods (#5467)

This commit is contained in:
Joshua Fontany 2021-05-24 13:16:23 -07:00 committed by GitHub
parent 7a41283c6b
commit 8d7930f660
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 92 additions and 21 deletions

View File

@ -601,7 +601,10 @@ SaveTiddlerTask.prototype.run = function(callback) {
tiddler = this.syncer.wiki.tiddlerExists(this.title) && this.syncer.wiki.getTiddler(this.title);
this.syncer.logger.log("Dispatching 'save' task:",this.title);
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(err) {
return callback(err);
@ -615,8 +618,6 @@ SaveTiddlerTask.prototype.run = function(callback) {
};
// Invoke the callback
callback(null);
},{
tiddlerInfo: self.syncer.tiddlerInfo[self.title]
});
} else {
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) {
var self = this;
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(err) {
return callback(err);
@ -642,8 +645,6 @@ DeleteTiddlerTask.prototype.run = function(callback) {
delete self.syncer.tiddlerInfo[self.title];
// Invoke the callback
callback(null);
},{
tiddlerInfo: self.syncer.tiddlerInfo[this.title]
});
};

View File

@ -69,7 +69,7 @@ Returns a revision ID.
Retrieves status information from the server. This method is optional.
|!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)`
@ -128,33 +128,40 @@ The syncer will use the `getUpdatedTiddlers()` method in preference to the `getS
|!Parameter |!Description |
|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.
|!Parameter |!Description |
|tiddler |Tiddler to be saved |
|options |See below |
|callback |Callback function invoked with parameter `err,adaptorInfo,revision` |
|tiddlerInfo |The tiddlerInfo maintained by the syncer for this tiddler |
!! `loadTiddler(title,callback)`
!! `loadTiddler(title,options,callback)`
Loads a tiddler from the server.
|!Parameter |!Description |
|title |Title of tiddler to be retrieved |
|options |See below |
|callback |Callback function invoked with parameter `err,tiddlerFields` |
!! `deleteTiddler(title,callback,options)`
!! `deleteTiddler(title,options,callback)`
Delete a tiddler from the server.
|!Parameter |!Description |
|title |Title of tiddler to be deleted |
|callback |Callback function invoked with parameter `err` |
|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 |
|changeCount |The //new// changeCount value for this tiddler |
|tiddlerInfo |The tiddlerInfo maintained by the syncer for this tiddler |

View File

@ -75,7 +75,14 @@ FileSystemAdaptor.prototype.getTiddlerFileInfo = function(tiddler,callback) {
/*
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 syncerInfo = options.tiddlerInfo || {};
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.
*/
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);
};
/*
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,
fileInfo = this.boot.files[title];
// Only delete the tiddler if we have writable information for the file

View File

@ -99,7 +99,14 @@ SaveTrailSyncAdaptor.prototype.getTiddlerInfo = function(tiddler) {
/*
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")) {
var isDraft = $tw.utils.hop(tiddler.fields,"draft.of");
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)
*/
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);
};
/*
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);
};

View File

@ -182,7 +182,14 @@ TiddlyWebAdaptor.prototype.getSkinnyTiddlers = function(callback) {
/*
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;
if(this.isReadOnly) {
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)
*/
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;
$tw.utils.httpRequest({
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:
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;
if(this.isReadOnly) {
return callback(null,options.tiddlerInfo.adaptorInfo);