php sync scripts + sync adaptor plugin -- could something like this work?

82 views
Skip to first unread message

Mark Brown

unread,
Sep 1, 2016, 5:56:41 AM9/1/16
to TiddlyWikiDev
Hi all,

I'm only semi php- and js-literate, but i'm wondering if this could work in  theory?

I'd like to have the benefits of lazy-loading etc of a syncadaptor on my cheap shared hosting. If i'm reading the developer docs correctly, there's only a few  mandatory methods for a sync adaptor.

Here's my rough idea:

On a web-server:

empty+plugins.html  <--- the core wiki with plugins baked in
content1.tid   <--- a .tid file to be synced
content2.tid  <--- a .tid file to be synced
content3.tid   <--- a .tid file to be synced
getSkinnyTiddlers.php  <-- a php script that compiles a set of skinny tiddlers from all .tid files and echoes as json
saveTiddler.php <- a php script that takes a file upload and saves as a .tid
loadTiddler.php <- that takes a GET parameter as a .tid file name and echoes the full tiddler as json
deleteTiddler.php <- that takes a GET parameter as a .tid file name and deletes that file

In a corresponding sync adaptor plugin:

- the constructor method
- methods corresponding to each of the 4 php scripts, doing an http request to that script


That's it. No database back end, python, or nodejs.

Possible? Practical? Someone done it already?


Jeremy Ruston

unread,
Sep 1, 2016, 6:32:08 AM9/1/16
to tiddly...@googlegroups.com
Hi Mark

I'm only semi php- and js-literate, but i'm wondering if this could work in  theory?

Broadly, yes, it looks like a reasonable and potentially robust approach. There are a lot of details you’d have to work out - for example, how the .tid files are named, given that not all of the characters that can appear in a tiddler title can be used within a filename.

I think you wouldn’t necessarily have to create a custom sync adaptor. Instead, you could offer a compatible HTTP interface and have the standard tiddlywebadaptor handle syncing.

Best wishes

Jeremy.

--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/97305243-ff16-4c5a-952d-4fb0a8357d93%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Mark Brown

unread,
Sep 3, 2016, 12:19:22 AM9/3/16
to TiddlyWikiDev
Thanks Jeremy. I'm making good progress. I hope to share it soon.

Mark Brown

unread,
Sep 3, 2016, 7:24:54 AM9/3/16
to TiddlyWikiDev
A progress report:

Made a lot of progress today. I have working bare bones implementations of:
  • saveTiddler
  • deleteTiddler
  • getSkinnyTiddlers

loadTiddler is giving me trouble, however. The wiki just doesn't seem to dispatch the load events, and I don't know why.


for anyone who is curious, my horrible code is here at github, but be warned it is not pretty:


https://github.com/Wheels00/tw5-php-simple-sync


Mark Brown

unread,
Sep 4, 2016, 7:06:40 AM9/4/16
to tiddly...@googlegroups.com
Ok, so, i've been debugging my lazy loading issue.

I set a breakpoint at the start of this syncer.js method in Jeremy's code:



     
     
       
/*

     
     
       
Lazily load a skinny tiddler if we can

     
     
       
*/

       
Syncer.prototype.handleLazyLoadEvent = function(title) {

     
       
        // Don't lazy load the same tiddler twice

     
       
        var info = this.tiddlerInfo[title];

     
// MARK's BREAKPOINT
     
       
        if(!info || !info.hasBeenLazyLoaded) { // MARK'S OBSERVATION -- ALWAYS EVALUATES FALSE AND SKIPS OVER 

     
     
       
                this.createTiddlerInfo(title);

     
     
       
                this.tiddlerInfo[title].hasBeenLazyLoaded = true;

     
     
       
                // Queue up a sync task to load this tiddler

     
     
       
                this.enqueueSyncTask({

     
     
       
                        type: "load",

     
     
       
                        title: title

     
     
       
                });            

     
       
        }
};

The wiki seems to always think my skinny tiddler has already been lazy loaded... but I can't workout where or why this flag is being set.

Any ideas?

Danielo Rodríguez

unread,
Sep 4, 2016, 12:36:12 PM9/4/16
to TiddlyWikiDev
Yes,

It is a bug introduced in 5.1.13
I have reported it some time ago and it's already fixed, but you have to use prerelease version of TW or wait until 5.1.14
I advised Jeremy to do a patch release of 5.1.13 because it adds a lot of confusion to developers, but I didn't hear anything from him about this.

Regards

Danielo Rodríguez

unread,
Sep 4, 2016, 12:38:44 PM9/4/16
to TiddlyWikiDev
If you are curious about it, here is the original issue

https://github.com/Jermolene/TiddlyWiki5/issues/2514

Maybe you want to add a +1 to it

Mark Brown

unread,
Sep 4, 2016, 11:58:31 PM9/4/16
to TiddlyWikiDev
Thanks so much for your explanation, Danielo! You've saved me hours of debugging.

I'll use the pre-release

Mark Brown

unread,
Sep 5, 2016, 2:39:40 AM9/5/16
to TiddlyWikiDev
And it works! (well enough for my purposes at least)

I call it PHP Simple Sync and if anyone would like to improve it you can find it here https://github.com/Wheels00/tw5-php-simple-sync

Reply all
Reply to author
Forward
0 new messages