manuals for life
a shenie production
[[Home]]\n
Welcome to my wiki
Home\n
The following 2 issues were discovered which I then created patches and sent to Josh.\n!! Status\nAccepted\n!! Cannot delete tiddlers with '&' character in title\nThe & symbol needed to be escaped before passed to AJAX request.\nInstead of escape() the patch should probably use encodeURIComponent() so it's consistent with how saveTiddlerText() encodes titles as there are [[differences between each encode method|http://xkr.us/articles/javascript/encode-compare/]]\n\n{{{\nIndex: serverside_9_6.js\n===================================================================\n--- serverside_9_6.js (revision 17)\n+++ serverside_9_6.js (working copy)\n@@ -920,7 +920,7 @@\n if (!store.tiddlers[title])\n return closeTiddler(title,false);\n \n- req= new Ajax.Request('/wiki/destroy', {asynchronous:true, parameters:"id=" +title, \nonSuccess:function(request){AJAX_DeleteTiddlerSuccess(request)}, \nonFailure:function(request){AJAX_DeleteTiddlerError(request)}});\n+ req= new Ajax.Request('/wiki/destroy', {asynchronous:true, parameters:"id=" +escape(title), \nonSuccess:function(request){AJAX_DeleteTiddlerSuccess(request)}, \nonFailure:function(request){AJAX_DeleteTiddlerError(request)}});\n // IE doesn't support attributes on XHMLHTTPrequest\n if (navigator.userAgent.indexOf("MSIE")==-1) \n req.transport.TiddlerTitle=title\n}}}\n//p.s. I manually wrapped the lines in the above patch to make it look nicer//\n\n!! Deleting tiddler does not delete associated record in tiddler_versions table\nIt might be intentional as acts_as_versioned codebase only deletes versioned records when they go over max limit.\nThis is how I patched the problem based on [[Rick's suggestion|http://rails.techno-weenie.net/forums/1/topics/67?page=1]]\n{{{\nIndex: app/models/tiddler.rb\n===================================================================\n--- app/models/tiddler.rb (revision 17)\n+++ app/models/tiddler.rb (working copy)\n@@ -3,6 +3,8 @@\n acts_as_versioned :limit => 10, :if => Proc.new { |t| !t.recently_revised? }, :if_changed => [ :body ]\n \n validates_presence_of :title\n+ \n+ after_destroy { |tiddler| self.versioned_class.delete_all ['tiddler_id', tiddler.id] }\n \n def recently_revised?; \n return false if new_record? or versions.length==0\n}}}\n\nI [[found|How to recreate SoloWiki tiddler versions?]] tiddler_versions were all deleted when a tiddler is deleted. Not sure when it started happening but I've further patched tiddler.rb to the following.\n{{{\nafter_destroy {|tiddler| self.versioned_class.delete_all "tiddler_id = #{tiddler.id}" }\n}}}
I discovered by accident that most of the tiddler versions of this wiki were missing. Not that it is a big deal as I backup the database regularly but the problem is that there is now a opportunity to get exception when revisions button is clicked.\n\nI considered patched the code so that it doesn't throw method not found error (basically Java's ~NullPointerException) when tiddler revisions doesn't exist. But I decided it was easy to just recreate the data.\n\np.s. it technically just recreate the latest version record but that's good enough to stop the errors.\n\nSo here's what I did\n{{{\ndelete from tiddler_versions\n\ninsert into tiddler_versions\n (tiddler_id, version, title, modifier, body, tags, updated_on, created_on, private) \nselect id, version, title, 'YourName', body, tags, now(), now(), private from tiddlers\n}}}