JI-942 Add better error handling for Content Upgrade

content-upgrade-on-upload
Frode Petterson 2019-01-28 16:01:08 +01:00
parent 9cf3f4aa7f
commit c9e1ac9347
3 changed files with 47 additions and 18 deletions

View File

@ -537,9 +537,10 @@ interface H5PFrameworkInterface {
* Get number of contents using library as main library. * Get number of contents using library as main library.
* *
* @param int $libraryId * @param int $libraryId
* @param array $skip
* @return int * @return int
*/ */
public function getNumContent($libraryId); public function getNumContent($libraryId, $skip = NULL);
/** /**
* Determines if content slug is used. * Determines if content slug is used.

View File

@ -27,6 +27,7 @@ H5P.ContentUpgradeProcess = (function (Version) {
self.loadLibrary = loadLibrary; self.loadLibrary = loadLibrary;
self.upgrade(name, oldVersion, newVersion, params.params, params.metadata, function (err, upgradedParams, upgradedMetadata) { self.upgrade(name, oldVersion, newVersion, params.params, params.metadata, function (err, upgradedParams, upgradedMetadata) {
if (err) { if (err) {
err.id = id;
return done(err); return done(err);
} }
@ -176,7 +177,11 @@ H5P.ContentUpgradeProcess = (function (Version) {
var usedVer = new Version(usedLib[1]); var usedVer = new Version(usedLib[1]);
var availableVer = new Version(availableLib[1]); var availableVer = new Version(availableLib[1]);
if (usedVer.major > availableVer.major || (usedVer.major === availableVer.major && usedVer.minor >= availableVer.minor)) { if (usedVer.major > availableVer.major || (usedVer.major === availableVer.major && usedVer.minor >= availableVer.minor)) {
return done(); // Larger or same version that's available return done({
type: 'errorTooHighVersion',
used: usedLib[0] + ' ' + usedVer,
supported: availableLib[0] + ' ' + availableVer
}); // Larger or same version that's available
} }
// A newer version is available, upgrade params // A newer version is available, upgrade params
@ -192,7 +197,12 @@ H5P.ContentUpgradeProcess = (function (Version) {
}); });
} }
} }
done();
// Content type was not supporte by the higher version
done({
type: 'errorNotSupported',
used: usedLib[0] + ' ' + usedVer
});
break; break;
case 'group': case 'group':

View File

@ -1,7 +1,7 @@
/* global H5PAdminIntegration H5PUtils */ /* global H5PAdminIntegration H5PUtils */
(function ($, Version) { (function ($, Version) {
var info, $container, librariesCache = {}, scriptsCache = {}; var info, $log, $container, librariesCache = {}, scriptsCache = {};
// Initialize // Initialize
$(document).ready(function () { $(document).ready(function () {
@ -9,7 +9,9 @@
info = H5PAdminIntegration.libraryInfo; info = H5PAdminIntegration.libraryInfo;
// Get and reset container // Get and reset container
$container = $('#h5p-admin-container').html('<p>' + info.message + '</p>'); const $wrapper = $('#h5p-admin-container').html('');
$log = $('<ul class="content-upgrade-log"></ul>').appendTo($wrapper);
$container = $('<div><p>' + info.message + '</p></div>').appendTo($wrapper);
// Make it possible to select version // Make it possible to select version
var $version = $(getVersionSelect(info.versions)).appendTo($container); var $version = $(getVersionSelect(info.versions)).appendTo($container);
@ -120,9 +122,7 @@
}, },
error: function (error) { error: function (error) {
self.printError(error.err); self.printError(error.err);
self.workDone(error.id, null, this);
// Stop everything
self.terminate();
}, },
loadLibrary: function (details) { loadLibrary: function (details) {
var worker = this; var worker = this;
@ -184,7 +184,7 @@
self.token = inData.token; self.token = inData.token;
// Start processing // Start processing
self.processBatch(inData.params); self.processBatch(inData.params, inData.skipped);
}); });
}; };
@ -202,11 +202,12 @@
* *
* @param {Object} parameters * @param {Object} parameters
*/ */
ContentUpgrade.prototype.processBatch = function (parameters) { ContentUpgrade.prototype.processBatch = function (parameters, skipped) {
var self = this; var self = this;
// Track upgraded params // Track upgraded params
self.upgraded = {}; self.upgraded = {};
self.skipped = skipped;
// Track current batch // Track current batch
self.parameters = parameters; self.parameters = parameters;
@ -276,7 +277,7 @@
}, function done(err, result) { }, function done(err, result) {
if (err) { if (err) {
self.printError(err); self.printError(err);
return ; result = null;
} }
self.workDone(id, result); self.workDone(id, result);
@ -291,7 +292,12 @@
var self = this; var self = this;
self.working--; self.working--;
if (result === null) {
self.skipped.push(id);
}
else {
self.upgraded[id] = result; self.upgraded[id] = result;
}
// Update progress message // Update progress message
self.throbber.setProgress(Math.round((info.total - self.left + self.current) / (info.total / 100)) + ' %'); self.throbber.setProgress(Math.round((info.total - self.left + self.current) / (info.total / 100)) + ' %');
@ -302,6 +308,7 @@
self.nextBatch({ self.nextBatch({
libraryId: self.version.libraryId, libraryId: self.version.libraryId,
token: self.token, token: self.token,
skipped: JSON.stringify(self.skipped),
params: JSON.stringify(self.upgraded) params: JSON.stringify(self.upgraded)
}); });
} }
@ -410,14 +417,25 @@
ContentUpgrade.prototype.printError = function (error) { ContentUpgrade.prototype.printError = function (error) {
var self = this; var self = this;
if (error.type === 'errorParamsBroken') { switch (error.type) {
case 'errorParamsBroken':
error = info.errorContent.replace('%id', error.id) + ' ' + info.errorParamsBroken; error = info.errorContent.replace('%id', error.id) + ' ' + info.errorParamsBroken;
} break;
else if (error.type === 'scriptMissing') {
case 'scriptMissing':
error = info.errorScript.replace('%lib', error.library); error = info.errorScript.replace('%lib', error.library);
break;
case 'errorTooHighVersion':
error = info.errorContent.replace('%id', error.id) + ' ' + info.errorTooHighVersion.replace('%used', error.used).replace('%supported', error.supported);
break;
case 'errorNotSupported':
error = info.errorContent.replace('%id', error.id) + ' ' + info.errorNotSupported.replace('%used', error.used);
break;
} }
self.setStatus('<p>' + info.error + '<br/>' + error + '</p>'); $('<li>' + info.error + '<br/>' + error + '</li>').appendTo($log);
}; };
})(H5P.jQuery, H5P.Version); })(H5P.jQuery, H5P.Version);