HFP-2508 Fix reset of all subContentIds on Copy/Paste

content-upgrade-on-upload
Frode Petterson 2019-01-03 12:46:16 +01:00
parent 4a9c3c7881
commit f19ca76461
1 changed files with 10 additions and 9 deletions

View File

@ -2256,7 +2256,6 @@ H5P.createTitle = function (rawTitle, maxLength) {
* Get item from the H5P Clipboard. * Get item from the H5P Clipboard.
* *
* @private * @private
* @param {boolean} [skipUpdateFileUrls]
* @return {Object} * @return {Object}
*/ */
var parseClipboard = function () { var parseClipboard = function () {
@ -2274,8 +2273,8 @@ H5P.createTitle = function (rawTitle, maxLength) {
return; return;
} }
// Update file URLs // Update file URLs and reset content Ids
updateFileUrls(clipboardData.specific, function (path) { recursiveUpdate(clipboardData.specific, function (path) {
var isTmpFile = (path.substr(-4, 4) === '#tmp'); var isTmpFile = (path.substr(-4, 4) === '#tmp');
if (!isTmpFile && clipboardData.contentId) { if (!isTmpFile && clipboardData.contentId) {
// Comes from existing content // Comes from existing content
@ -2296,22 +2295,20 @@ H5P.createTitle = function (rawTitle, maxLength) {
if (clipboardData.generic) { if (clipboardData.generic) {
// Use reference instead of key // Use reference instead of key
clipboardData.generic = clipboardData.specific[clipboardData.generic]; clipboardData.generic = clipboardData.specific[clipboardData.generic];
// Avoid multiple content with same ID
delete clipboardData.generic.subContentId;
} }
return clipboardData; return clipboardData;
}; };
/** /**
* Update file URLs. Useful when copying content. * Update file URLs and reset content IDs.
* Useful when copying content.
* *
* @private * @private
* @param {object} params Reference * @param {object} params Reference
* @param {function} handler Modifies the path to work when pasted * @param {function} handler Modifies the path to work when pasted
*/ */
var updateFileUrls = function (params, handler) { var recursiveUpdate = function (params, handler) {
for (var prop in params) { for (var prop in params) {
if (params.hasOwnProperty(prop) && params[prop] instanceof Object) { if (params.hasOwnProperty(prop) && params[prop] instanceof Object) {
var obj = params[prop]; var obj = params[prop];
@ -2319,7 +2316,11 @@ H5P.createTitle = function (rawTitle, maxLength) {
obj.path = handler(obj.path); obj.path = handler(obj.path);
} }
else { else {
updateFileUrls(obj, handler); if (obj.library !== undefined && obj.subContentId !== undefined) {
// Avoid multiple content with same ID
delete obj.subContentId;
}
recursiveUpdate(obj, handler);
} }
} }
} }