From d43fa38f2964d06944db25f6dc87544aac7bb0f2 Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Wed, 8 Apr 2015 15:04:29 +0200 Subject: [PATCH] Add upgrade script for adding sub content id --- upgrades.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 upgrades.js diff --git a/upgrades.js b/upgrades.js new file mode 100644 index 0000000..f5f811c --- /dev/null +++ b/upgrades.js @@ -0,0 +1,21 @@ +var H5PUpgrades = H5PUpgrades || {}; + +H5PUpgrades['H5P.QuestionSet'] = (function ($) { + return { + 1: { + 4: function (parameters, finished) { + for (var i = 0; i < parameters.questions.length; i++) { + if (parameters.questions[i].subContentId === undefined) { + // NOTE: We avoid using H5P.createUUID since this is an upgrade script and H5P function may change in the + // future + parameters.questions[i].subContentId = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(char) { + var random = Math.random()*16|0, newChar = char === 'x' ? random : (random&0x3|0x8); + return newChar.toString(16); + }); + } + } + finished(null, parameters); + } + } + }; +})(H5P.jQuery);