Merge branch 'master' of github.com:h5p/h5p-php-library

HFP-2095-Fix-table-styling
Paal Joergensen 2018-08-30 12:35:56 +02:00
commit 43b9703fc9
4 changed files with 36 additions and 68 deletions

View File

@ -3682,7 +3682,6 @@ class H5PContentValidator {
if (isset($file->copyright)) {
$this->validateGroup($file->copyright, $this->getCopyrightSemantics());
// TODO: We'll need to do something here about getMetadataSemantics() if we change the widgets
}
}

View File

@ -7,7 +7,7 @@ H5P.ContentUpgradeProcess = (function (Version) {
* @class
* @namespace H5P
*/
function ContentUpgradeProcess(name, oldVersion, newVersion, params, extras, id, loadLibrary, done) {
function ContentUpgradeProcess(name, oldVersion, newVersion, params, id, loadLibrary, done) {
var self = this;
// 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.upgrade(name, oldVersion, newVersion, params, extras, function (err, result) {
self.upgrade(name, oldVersion, newVersion, params, function (err, upgradedParams) {
if (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;
// Load library details and upgrade routines
@ -65,7 +55,7 @@ H5P.ContentUpgradeProcess = (function (Version) {
}
// 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) {
return done(err);
}
@ -79,7 +69,7 @@ H5P.ContentUpgradeProcess = (function (Version) {
next(err);
});
}, function (err) {
done(err, params, extras);
done(err, params, metadata);
});
});
});
@ -95,7 +85,7 @@ H5P.ContentUpgradeProcess = (function (Version) {
* @param {Object} params
* @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 (library.upgradesScript) {
// Upgrades script should be loaded so the upgrades should be here.
@ -130,17 +120,11 @@ H5P.ContentUpgradeProcess = (function (Version) {
try {
unnecessaryWrapper(params, function (err, upgradedParams, upgradedExtras) {
params = upgradedParams;
/**
* "params" (and "extras", e.g. metadata) flow through each update function and are changed
* 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;
if (upgradedExtras && upgradedExtras.metadata) { // Optional
metadata = upgradedExtras.metadata;
}
nextMinor(err);
}, extras);
}, {metadata: metadata});
}
catch (err) {
if (console && console.log) {
@ -154,7 +138,7 @@ H5P.ContentUpgradeProcess = (function (Version) {
}, nextMajor);
}
}, 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
}
// Currently, we only use metadata as additional things that might need change
var extras = {
metadata: params.metadata
};
// 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) {
params.library = availableLib[0] + ' ' + availableVer.major + '.' + availableVer.minor;
params.params = upgraded;
if (extras) {
if (extras.metadata) {
params.metadata = extras.metadata;
}
params.params = upgradedParams;
if (upgradedMetadata) {
params.metadata = upgradedMetadata;
}
}
done(err, params);
});
}, params.metadata);
}
}
done();

View File

@ -9,7 +9,7 @@ var libraryLoadedCallback;
var messageHandlers = {
newJob: function (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?
postMessage({
action: 'loadLibrary',
@ -17,7 +17,7 @@ var messageHandlers = {
version: version.toString()
});
libraryLoadedCallback = next;
}, function done(err, result, extras) {
}, function done(err, result) {
if (err) {
// Return error
postMessage({
@ -33,8 +33,7 @@ var messageHandlers = {
postMessage({
action: 'done',
id: job.id,
params: result,
extras: extras
params: result
});
});
},

View File

@ -116,7 +116,7 @@
// Register message handlers
var messageHandlers = {
done: function (result) {
self.workDone(result.id, result.params, result.extras, this);
self.workDone(result.id, result.params, this);
},
error: function (error) {
self.printError(error.err);
@ -184,7 +184,7 @@
self.token = inData.token;
// Start processing
self.processBatch(inData.params, {metadata: inData.metadata});
self.processBatch(inData.params);
});
};
@ -202,7 +202,7 @@
*
* @param {Object} parameters
*/
ContentUpgrade.prototype.processBatch = function (parameters, extras) {
ContentUpgrade.prototype.processBatch = function (parameters) {
var self = this;
// Track upgraded params
@ -210,7 +210,6 @@
// Track current batch
self.parameters = parameters;
self.extras = extras;
// Create id mapping
self.ids = [];
@ -248,10 +247,6 @@
self.current++;
self.working++;
var extras = {
metadata: (self.extras.metadata && self.extras.metadata[id]) ? self.extras.metadata[id] : undefined
};
if (worker) {
worker.postMessage({
action: 'newJob',
@ -259,12 +254,11 @@
name: info.library.name,
oldVersion: info.library.version,
newVersion: self.version.toString(),
params: self.parameters[id],
extras: extras
params: self.parameters[id]
});
}
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) {
if (library.upgradesScript) {
self.loadScript(library.upgradesScript, function (err) {
@ -279,13 +273,13 @@
}
});
}, function done(err, result, extras) {
}, function done(err, result) {
if (err) {
self.printError(err);
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;
self.working--;
@ -308,8 +302,7 @@
self.nextBatch({
libraryId: self.version.libraryId,
token: self.token,
params: JSON.stringify(self.upgraded),
extras: extras
params: JSON.stringify(self.upgraded)
});
}
};