New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(h5p-server): upgrade existing content on saving edit #1992
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I remember this was left out as I didn't know the purpose of it.
@JPSchellenberg Content types may provide an You could install an outdated version of a content type that has an upgrade hook for later versions. The later version may not be installed yet. Then create some content with that version. If you now install the later version, the existing content will continue to use the old version, while newly created content will use the later version. In order to upgrade existing content to the newer version, one could run a batch upgrade (not available for the node.js port yet) or open the existing content in the editor and then save it again. On saving, the upgrade hook will be run. That's what's implemented now. You could, for instance, install version 1.0 Advanced Blanks first (https://github.com/sr258/h5p-advanced-blanks/tree/1.0.1). It will have the image zooming settings in the behavioural settings of the editor. Save some content. For version 1.1 that setting was moved to the top of the editor, and that requires an upgrade hook, see https://github.com/sr258/h5p-advanced-blanks/blob/master/upgrades.js. So, you can now install the latest version of Advanced Blanks, edit your content and save it. That should run the upgrade hook. If you then edit the content again, you'll notice that the image zooming setting is now at the top and the content has kept your previous setting and still runs smoothly with the upgraded set of parameters. |
The upgrade should definitely be run! It would be good if we added a way so that this will also work in the h5p-webcomponents package |
@otacke Can you explain where the update is performed? I'd like to document this, as it's not obvious to me from looking at the code change. |
@sr258 Yeah, that is hidden inside the |
@JPSchellenberg @sr258 Do you happen to have a schedule for working on this ticket? Anything I can do to help? Can't review my own code, of course :-D But maybe there's something else I could do? |
Sorry about not merging this yet. I wanted to integrate the change into the webcomponent as well, before merging, but never found the time. You could help by changing h5p-editor.ts in h5p-webcomponent so that it also has the change. |
I'll see what I can do when. |
@otacke I've finally found the time to have a closer look at this. I've adapted the code for the webcomponent it works in my tests. I'm not sure about the recursion protection Also, do you have any old h5ps that I can use to test this in more detail (particularly nested content)? |
@sr258 The I don't have any old content lying around unfortunately, maybe the ZUM or some other organization has some backups? If not, pulling some old Column version with one or two respective simple sub content versions (e.g. True/False and Blanks) could serve as test generators. |
@otacke Alright, thanks for the clarification! I've renamed the variable to make it more clear. I like to divert from Joubel's naming if it makes things more clear. |
I've just tested this and it doesn't seem to work as expected. An upgrade of Interactive Video produces a broken object (tested with the server-side rendering example at h5p-examples):
The video is updated to the 1.24 but the JavaScript of the IV library throws an error as the I've compared the parameters (content.json) of the broken and the correctly upgraded version and the only difference is that the interaction's I've looked at the POST request made when saving and the difference is that in the case of the broken upgrade (upgrade of already present content), the Multiple Choice content type version is left at 1.14 but in the case of the working upgrade its 1.16. (I think the semantics checker deletes the action attribute as the semantics expect 1.16) So it looks the upgrade process doesn't upgrade subcontent. @otacke Do you know why this might be the case? |
@sr258 Sorry, no. I have never looked into the internals of the upgrade process. I might fight an hour next week to look into this. |
@otacke I think I found the bug: The Ajax call still used the old params, not the ones received from getContent. Unfortunately, the params are in a JSON string and need to be parsed and then re-stringified. Looks like things work now. |
@sr258 But then I'll really be able to take a couple of days off this week and will not have an excuse not to! ;-) Glad that you found the issue. |
@otacke I've merged the PR now. Thanks for the suggestion! |
@sr258 Cool, thanks! But I have not yet created a test! |
@otacke It's not part of the new release yet, so there's still time. I think the feature is important enough so that it makes sense to have it even without a test. I would still very much like one, but this requires re-enabling the E2E tests (as this is all client-side code), which I disabled some time ago, because they became more and more flaky. I am planning to rewrite the old E2E tests in Cypress.IO as I picked the Puppeteer + Jest combination as there weren't any better and easier alternatives at the time. So if you are going to add tests for the upgrade it would be great if you used Crypess, too. I won't have the time to work on this before September, though. |
@sr258 Gotcha. I've never used Cypress before (only Behat for E2E tests), but "How hard can it be?" (famous last words) ;-) |
When existing H5P content is opened in the editor of one of the original integrations (WordPress, Drupal, moodle) and there's a later version of the respective H5P content type library installed, the integrations upgrade that content when it's saved.
I am not aware whether this behavior has been changed deliberately here, but if not: I merely re-used the code of the WordPress integration here.