store.saveTiddler

58 views
Skip to first unread message

Henry

unread,
Jun 13, 2011, 6:04:04 AM6/13/11
to TiddlyWeb
Hi all,

I met a problem in my source code. I tried to create a new tiddler and
overwrote the existing one. The part of the code is as follows

newTiddler.fields = merge({}, config.defaultCustomFields);
newTiddler.fields['server.workspace'] = 'bags/'+bag;
newTiddler.fields['server.page.revision'] = revision;
store.addTiddler(newTiddler);
store.saveTiddler(newTiddler.title);
saveChanges();

However, for some reasons, the new tiddler cannot be saved. I checked
and realized that the problem is caused by the incorrect revision
generated by the generateETag function (the generated revision,
revision 0, is older than the existing one, revision 1). Further
checking, I realized that the problem might come from getting data of
tiddler.fields['server.workspace'] and
tiddler.fields['server.page.revision'] as both of them returned
'undefined'.

Could anyone give me a hint of what is the potential error here? Is
there any problem with the saveTiddler function? (the new tiddler was
saved as it can be retrieved but not the meta data !!!.)

I would like to debug saveTiddler, where can I find the function. Note
that I found the function in the Python\Lib\site-packages\tiddlywebwiki
\resources\empty.html but modification on this file does not make any
effect.

Thanks
Henry

Peter Neumark

unread,
Jun 13, 2011, 7:38:00 AM6/13/11
to tidd...@googlegroups.com
Hi Henry,

I can help with why your new saveTiddler function is not visible:
The contents of files like empty.html are placed into the store (which
is typically a mysql database).
In order to make your changes visible, you should run 'twanager
update' after saving empty.html.

This will refresh the contents of these special tiddlers in the database.
Typically, you can avoid editing these files if you overwrite
javascript functions once the page has loaded.

Good luck,
Peter

> --
> You received this message because you are subscribed to the Google Groups "TiddlyWeb" group.
> To post to this group, send email to tidd...@googlegroups.com.
> To unsubscribe from this group, send email to tiddlyweb+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/tiddlyweb?hl=en.
>
>

Henry

unread,
Jun 14, 2011, 4:16:53 AM6/14/11
to TiddlyWeb
Thanks Peter,

Related to the above error, I used the following code for testing

newTiddler.fields['server.page.revision'] = revision;
alert(newTiddler.fields['server.page.revision']);
store.addTiddler(newTiddler);
store.saveTiddler(newTiddler.title);
alert(newTiddler.fields['server.page.revision']);

The first alert shows the correct revision while the second alert
shows 'undefined'. Thus, the error may be related to the saveTiddler
method. Do you have any idea on this error?

Thanks,
Henry

PMario

unread,
Jun 14, 2011, 7:16:12 AM6/14/11
to TiddlyWeb
Hi Henry,
There are known problems with TW consistency checks, if you
programmatically create/change tiddlers. At the moment, there is no
"clean and easy to use API". At the moment the programmer has to know,
what he is doing.

It is very easy to get a "precondition failed" response from the
server and the tiddler isn't saved. You have to look at firebug to
see, what's going on.

Setting server.page.revision field doesn't work, since it is created
by the server. There is a somewhat "dirty hack" to disable the
consistnecy check at saving a tiddler.

Set the revision to false. Which will force a save to the server.



newTiddler.fields['server.page.revision'] = false;

and delete some fields, that may exist and cause problems if you save
a changed tiddler.

delete newTiddler.fields["server.permissions"];
delete newTiddler.fields["server.title"];
delete newTiddler.fields["server.etag"];


!!! Be aware, that the last write will win. Eg: If two differnt
browser windows write to the same tiddler. The last write will win,
since consistency check is deactivated. Server side revision handling
is fine, so revisions can be compared afterwards, if needed.

====
I am not a core dev, so I probably don't know what I am doing here. I
just can tell, what works for me :)

-m

rakugo

unread,
Jun 17, 2011, 4:27:52 AM6/17/11
to TiddlyWeb
The following code should be all you need to save to the server:

merge(newTiddler.fields, config.defaultCustomFields)
var tid = store.saveTiddler(newTiddler.title);
autoSaveChanges(null, [ tid ]);


If you are overwriting an existing tiddler then you are NOT creating a
new tiddler, you are rewriting an existing tiddler.
Thus the best way to do this is to start with the tiddler you are
overwriting.
I assume somewhere you have you var tiddler = new Tiddler("foo");
Instead do:
var tiddler = store.tiddlerExists("foo") ? store.getTiddler("foo") :
new Tiddler("foo");
Reply all
Reply to author
Forward
0 new messages