Merge branch 'master' of https://github.com/h5p/h5p-php-library
commit
2d3fe61371
|
@ -3683,7 +3683,6 @@ class H5PContentValidator {
|
||||||
|
|
||||||
if (isset($file->copyright)) {
|
if (isset($file->copyright)) {
|
||||||
$this->validateGroup($file->copyright, $this->getCopyrightSemantics());
|
$this->validateGroup($file->copyright, $this->getCopyrightSemantics());
|
||||||
// TODO: We'll need to do something here about getMetadataSemantics() if we change the widgets
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ H5P.ContentUpgradeProcess = (function (Version) {
|
||||||
* @class
|
* @class
|
||||||
* @namespace H5P
|
* @namespace H5P
|
||||||
*/
|
*/
|
||||||
function ContentUpgradeProcess(name, oldVersion, newVersion, params, extras, id, loadLibrary, done) {
|
function ContentUpgradeProcess(name, oldVersion, newVersion, params, id, loadLibrary, done) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// Make params possible to work with
|
// Make params possible to work with
|
||||||
|
@ -24,38 +24,28 @@ H5P.ContentUpgradeProcess = (function (Version) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make extras possible to work with
|
|
||||||
for (var element in extras) {
|
|
||||||
if (extras[element] !== undefined) {
|
|
||||||
try {
|
|
||||||
extras[element] = JSON.parse(extras[element]);
|
|
||||||
if (!(extras[element] instanceof Object)) {
|
|
||||||
throw true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (event) {
|
|
||||||
return done({
|
|
||||||
type: 'errorExtrasBroken',
|
|
||||||
id: id
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.loadLibrary = loadLibrary;
|
self.loadLibrary = loadLibrary;
|
||||||
self.upgrade(name, oldVersion, newVersion, params, extras, function (err, result) {
|
self.upgrade(name, oldVersion, newVersion, params, function (err, upgradedParams) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
done(null, JSON.stringify(params), JSON.stringify(extras));
|
done(null, JSON.stringify(upgradedParams));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Run content upgrade.
|
||||||
*
|
*
|
||||||
|
* @public
|
||||||
|
* @param {string} name
|
||||||
|
* @param {Version} oldVersion
|
||||||
|
* @param {Version} newVersion
|
||||||
|
* @param {Object} params Only for subcontent
|
||||||
|
* @param {Function} done Only for subcontent
|
||||||
|
* @param {Object} [metadata] Only for subcontent
|
||||||
*/
|
*/
|
||||||
ContentUpgradeProcess.prototype.upgrade = function (name, oldVersion, newVersion, params, extras, done) {
|
ContentUpgradeProcess.prototype.upgrade = function (name, oldVersion, newVersion, params, done, metadata) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// Load library details and upgrade routines
|
// Load library details and upgrade routines
|
||||||
|
@ -65,7 +55,7 @@ H5P.ContentUpgradeProcess = (function (Version) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run upgrade routines on params
|
// Run upgrade routines on params
|
||||||
self.processParams(library, oldVersion, newVersion, params, extras, function (err, params, extras) {
|
self.processParams(library, oldVersion, newVersion, params, metadata, function (err, params, metadata) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
|
@ -79,7 +69,7 @@ H5P.ContentUpgradeProcess = (function (Version) {
|
||||||
next(err);
|
next(err);
|
||||||
});
|
});
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
done(err, params, extras);
|
done(err, params, metadata);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -95,7 +85,7 @@ H5P.ContentUpgradeProcess = (function (Version) {
|
||||||
* @param {Object} params
|
* @param {Object} params
|
||||||
* @param {Function} next
|
* @param {Function} next
|
||||||
*/
|
*/
|
||||||
ContentUpgradeProcess.prototype.processParams = function (library, oldVersion, newVersion, params, extras, next) {
|
ContentUpgradeProcess.prototype.processParams = function (library, oldVersion, newVersion, params, metadata, next) {
|
||||||
if (H5PUpgrades[library.name] === undefined) {
|
if (H5PUpgrades[library.name] === undefined) {
|
||||||
if (library.upgradesScript) {
|
if (library.upgradesScript) {
|
||||||
// Upgrades script should be loaded so the upgrades should be here.
|
// Upgrades script should be loaded so the upgrades should be here.
|
||||||
|
@ -130,17 +120,11 @@ H5P.ContentUpgradeProcess = (function (Version) {
|
||||||
try {
|
try {
|
||||||
unnecessaryWrapper(params, function (err, upgradedParams, upgradedExtras) {
|
unnecessaryWrapper(params, function (err, upgradedParams, upgradedExtras) {
|
||||||
params = upgradedParams;
|
params = upgradedParams;
|
||||||
/**
|
if (upgradedExtras && upgradedExtras.metadata) { // Optional
|
||||||
* "params" (and "extras", e.g. metadata) flow through each update function and are changed
|
metadata = upgradedExtras.metadata;
|
||||||
* if necessary. Since "extras" was added later and old update functions don't return
|
|
||||||
* it, we need to ignore undefined values here -- or change every single update function
|
|
||||||
* in all content types.
|
|
||||||
*/
|
|
||||||
if (upgradedExtras) {
|
|
||||||
extras = upgradedExtras;
|
|
||||||
}
|
}
|
||||||
nextMinor(err);
|
nextMinor(err);
|
||||||
}, extras);
|
}, {metadata: metadata});
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
if (console && console.log) {
|
if (console && console.log) {
|
||||||
|
@ -154,7 +138,7 @@ H5P.ContentUpgradeProcess = (function (Version) {
|
||||||
}, nextMajor);
|
}, nextMajor);
|
||||||
}
|
}
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
next(err, params, extras);
|
next(err, params, metadata);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -195,24 +179,17 @@ H5P.ContentUpgradeProcess = (function (Version) {
|
||||||
return done(); // Larger or same version that's available
|
return done(); // Larger or same version that's available
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currently, we only use metadata as additional things that might need change
|
|
||||||
var extras = {
|
|
||||||
metadata: params.metadata
|
|
||||||
};
|
|
||||||
|
|
||||||
// A newer version is available, upgrade params
|
// A newer version is available, upgrade params
|
||||||
return self.upgrade(availableLib[0], usedVer, availableVer, params.params, extras, function (err, upgraded, extras) {
|
return self.upgrade(availableLib[0], usedVer, availableVer, params.params, function (err, upgradedParams, upgradedMetadata) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
params.library = availableLib[0] + ' ' + availableVer.major + '.' + availableVer.minor;
|
params.library = availableLib[0] + ' ' + availableVer.major + '.' + availableVer.minor;
|
||||||
params.params = upgraded;
|
params.params = upgradedParams;
|
||||||
if (extras) {
|
if (upgradedMetadata) {
|
||||||
if (extras.metadata) {
|
params.metadata = upgradedMetadata;
|
||||||
params.metadata = extras.metadata;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done(err, params);
|
done(err, params);
|
||||||
});
|
}, params.metadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
|
|
|
@ -9,7 +9,7 @@ var libraryLoadedCallback;
|
||||||
var messageHandlers = {
|
var messageHandlers = {
|
||||||
newJob: function (job) {
|
newJob: function (job) {
|
||||||
// Start new job
|
// Start new job
|
||||||
new H5P.ContentUpgradeProcess(job.name, new H5P.Version(job.oldVersion), new H5P.Version(job.newVersion), job.params, job.extras, job.id, function loadLibrary(name, version, next) {
|
new H5P.ContentUpgradeProcess(job.name, new H5P.Version(job.oldVersion), new H5P.Version(job.newVersion), job.params, job.id, function loadLibrary(name, version, next) {
|
||||||
// TODO: Cache?
|
// TODO: Cache?
|
||||||
postMessage({
|
postMessage({
|
||||||
action: 'loadLibrary',
|
action: 'loadLibrary',
|
||||||
|
@ -17,7 +17,7 @@ var messageHandlers = {
|
||||||
version: version.toString()
|
version: version.toString()
|
||||||
});
|
});
|
||||||
libraryLoadedCallback = next;
|
libraryLoadedCallback = next;
|
||||||
}, function done(err, result, extras) {
|
}, function done(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
// Return error
|
// Return error
|
||||||
postMessage({
|
postMessage({
|
||||||
|
@ -33,8 +33,7 @@ var messageHandlers = {
|
||||||
postMessage({
|
postMessage({
|
||||||
action: 'done',
|
action: 'done',
|
||||||
id: job.id,
|
id: job.id,
|
||||||
params: result,
|
params: result
|
||||||
extras: extras
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -116,7 +116,7 @@
|
||||||
// Register message handlers
|
// Register message handlers
|
||||||
var messageHandlers = {
|
var messageHandlers = {
|
||||||
done: function (result) {
|
done: function (result) {
|
||||||
self.workDone(result.id, result.params, result.extras, this);
|
self.workDone(result.id, result.params, this);
|
||||||
},
|
},
|
||||||
error: function (error) {
|
error: function (error) {
|
||||||
self.printError(error.err);
|
self.printError(error.err);
|
||||||
|
@ -184,7 +184,7 @@
|
||||||
self.token = inData.token;
|
self.token = inData.token;
|
||||||
|
|
||||||
// Start processing
|
// Start processing
|
||||||
self.processBatch(inData.params, {metadata: inData.metadata});
|
self.processBatch(inData.params);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@
|
||||||
*
|
*
|
||||||
* @param {Object} parameters
|
* @param {Object} parameters
|
||||||
*/
|
*/
|
||||||
ContentUpgrade.prototype.processBatch = function (parameters, extras) {
|
ContentUpgrade.prototype.processBatch = function (parameters) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// Track upgraded params
|
// Track upgraded params
|
||||||
|
@ -210,7 +210,6 @@
|
||||||
|
|
||||||
// Track current batch
|
// Track current batch
|
||||||
self.parameters = parameters;
|
self.parameters = parameters;
|
||||||
self.extras = extras;
|
|
||||||
|
|
||||||
// Create id mapping
|
// Create id mapping
|
||||||
self.ids = [];
|
self.ids = [];
|
||||||
|
@ -248,10 +247,6 @@
|
||||||
self.current++;
|
self.current++;
|
||||||
self.working++;
|
self.working++;
|
||||||
|
|
||||||
var extras = {
|
|
||||||
metadata: (self.extras.metadata && self.extras.metadata[id]) ? self.extras.metadata[id] : undefined
|
|
||||||
};
|
|
||||||
|
|
||||||
if (worker) {
|
if (worker) {
|
||||||
worker.postMessage({
|
worker.postMessage({
|
||||||
action: 'newJob',
|
action: 'newJob',
|
||||||
|
@ -259,12 +254,11 @@
|
||||||
name: info.library.name,
|
name: info.library.name,
|
||||||
oldVersion: info.library.version,
|
oldVersion: info.library.version,
|
||||||
newVersion: self.version.toString(),
|
newVersion: self.version.toString(),
|
||||||
params: self.parameters[id],
|
params: self.parameters[id]
|
||||||
extras: extras
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
new H5P.ContentUpgradeProcess(info.library.name, new Version(info.library.version), self.version, self.parameters[id], extras, id, function loadLibrary(name, version, next) {
|
new H5P.ContentUpgradeProcess(info.library.name, new Version(info.library.version), self.version, self.parameters[id], id, function loadLibrary(name, version, next) {
|
||||||
self.loadLibrary(name, version, function (err, library) {
|
self.loadLibrary(name, version, function (err, library) {
|
||||||
if (library.upgradesScript) {
|
if (library.upgradesScript) {
|
||||||
self.loadScript(library.upgradesScript, function (err) {
|
self.loadScript(library.upgradesScript, function (err) {
|
||||||
|
@ -279,13 +273,13 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}, function done(err, result, extras) {
|
}, function done(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.printError(err);
|
self.printError(err);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.workDone(id, result, extras);
|
self.workDone(id, result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -293,7 +287,7 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
ContentUpgrade.prototype.workDone = function (id, result, extras, worker) {
|
ContentUpgrade.prototype.workDone = function (id, result, worker) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self.working--;
|
self.working--;
|
||||||
|
@ -308,8 +302,7 @@
|
||||||
self.nextBatch({
|
self.nextBatch({
|
||||||
libraryId: self.version.libraryId,
|
libraryId: self.version.libraryId,
|
||||||
token: self.token,
|
token: self.token,
|
||||||
params: JSON.stringify(self.upgraded),
|
params: JSON.stringify(self.upgraded)
|
||||||
extras: extras
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -133,9 +133,10 @@ H5P.XAPIEvent.prototype.setObject = function (instance) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (H5PIntegration && H5PIntegration.contents && H5PIntegration.contents['cid-' + instance.contentId].title) {
|
var content = H5P.getContentForInstance(instance.contentId);
|
||||||
|
if (content && content.metadata && content.metadata.title) {
|
||||||
this.data.statement.object.definition.name = {
|
this.data.statement.object.definition.name = {
|
||||||
"en-US": H5P.createTitle(H5PIntegration.contents['cid-' + instance.contentId].title)
|
"en-US": H5P.createTitle(content.metadata.title)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,7 +151,6 @@ H5P.XAPIEvent.prototype.setObject = function (instance) {
|
||||||
*/
|
*/
|
||||||
H5P.XAPIEvent.prototype.setContext = function (instance) {
|
H5P.XAPIEvent.prototype.setContext = function (instance) {
|
||||||
if (instance.parent && (instance.parent.contentId || instance.parent.subContentId)) {
|
if (instance.parent && (instance.parent.contentId || instance.parent.subContentId)) {
|
||||||
var parentId = instance.parent.subContentId === undefined ? instance.parent.contentId : instance.parent.subContentId;
|
|
||||||
this.data.statement.context = {
|
this.data.statement.context = {
|
||||||
"contextActivities": {
|
"contextActivities": {
|
||||||
"parent": [
|
"parent": [
|
||||||
|
|
14
js/h5p.js
14
js/h5p.js
|
@ -2140,6 +2140,20 @@ H5P.createTitle = function (rawTitle, maxLength) {
|
||||||
contentUserDataAjax(contentId, dataId, subContentId, undefined, null);
|
contentUserDataAjax(contentId, dataId, subContentId, undefined, null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function for getting content for a certain ID
|
||||||
|
*
|
||||||
|
* @param {number} contentId
|
||||||
|
* @return {Object}
|
||||||
|
*/
|
||||||
|
H5P.getContentForInstance = function (contentId) {
|
||||||
|
var key = 'cid-' + contentId;
|
||||||
|
var exists = H5PIntegration && H5PIntegration.contents &&
|
||||||
|
H5PIntegration.contents[key];
|
||||||
|
|
||||||
|
return exists ? H5PIntegration.contents[key] : undefined;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the content parameters for storing in the clipboard.
|
* Prepares the content parameters for storing in the clipboard.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue