From 1b99dbb677e53ca68e41101d2fb1e69bfa87cc37 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Mon, 2 Dec 2013 09:59:17 +0000 Subject: [PATCH] Add wiki.importTiddler() Exactly like addTiddler except that it rejects plugins that are older than the currently installed version. --- core/modules/wiki.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 1c62c12fe..d51f133fc 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -210,6 +210,23 @@ exports.addTiddler = function(tiddler) { this.enqueueTiddlerEvent(title); }; +/* +Like addTiddler() except it will silently reject any plugin tiddlers that are older than the currently loaded version. Returns true if the tiddler was imported +*/ +exports.importTiddler = function(tiddler) { + var existingTiddler = this.getTiddler(tiddler.fields.title); + // Check if we're dealing with a plugin + if(tiddler && tiddler.hasField("plugin-type") && tiddler.hasField("version") && existingTiddler && existingTiddler.hasField("plugin-type") && existingTiddler.hasField("version")) { + // Reject the incoming plugin if it is older + if($tw.utils.checkVersions(existingTiddler.fields.version,tiddler.fields.version)) { + return false; + } + } + // Fall through to adding the tiddler + this.addTiddler(tiddler); + return true; +}; + /* Return a hashmap of the fields that should be set when a tiddler is created */