h5p / moodle-mod_hvp

H5P Plugin for Moodle
GNU General Public License v3.0
134 stars 171 forks source link

Bulk editing H5P activity completion breaks adding h5p activities to a course #386

Open Urpokarhu1 opened 3 years ago

Urpokarhu1 commented 3 years ago

Hello,

You cannot add any H5P activities at all to the course after you have bulk edited existing H5P activitity course completion settings. Tested with Moodle 3.9 & mod_hvp 1.21.0

bulkerror

Steps to repeat:

  1. Create a new course

  2. Create two h5p activities, set "activity completion" to "students can manually mark the activity as completed" in both of them.

  3. Open course completion page -> Default activity completion -tab-> select interactive content -> edit

  4. Change completion to something else than "students can manually mark the activity as completed"

  5. Save

  6. Try to add new H5p activity on the course

  7. Notice that you cannot and you get an error

error/invalidhvp
More information about this error

Debug info:
Error code: invalidhvp
$a contents:

Stack trace:
line 498 of /lib/setuplib.php: moodle_exception thrown
line 182 of /mod/hvp/mod_form.php: call to print_error()
line 116 of /completion/classes/defaultedit_form.php: call to mod_hvp_mod_form->data_preprocessing()
line 214 of /lib/formslib.php: call to core_completion_defaultedit_form->definition()
line 56 of /course/editdefaultcompletion.php: call to moodleform->__construct()

Browser console:

GET http://moodleaddress.com/course/modedit.php?add=hvp&type=&course=54&section=0&return=0&sr=0 404 (Not Found)

first.js:272 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
(anonymous) @ first.js:272
e @ jquery-3.4.1.min.js:2
t @ jquery-3.4.1.min.js:2
setTimeout (async)
(anonymous) @ jquery-3.4.1.min.js:2
c @ jquery-3.4.1.min.js:2
add @ jquery-3.4.1.min.js:2
(anonymous) @ jquery-3.4.1.min.js:2
Deferred @ jquery-3.4.1.min.js:2
then @ jquery-3.4.1.min.js:2
k.fn.ready @ jquery-3.4.1.min.js:2
init @ first.js:272
(anonymous) @ modedit.php?add=hvp&type=&course=54&section=0&return=0&sr=0:2157
execCb @ require.min.js:5
check @ require.min.js:5
enable @ require.min.js:5
init @ require.min.js:5
(anonymous) @ require.min.js:5
setTimeout (async)
req.nextTick @ require.min.js:5
o @ require.min.js:5
requirejs @ require.min.js:5
(anonymous) @ modedit.php?add=hvp&type=&course=54&section=0&return=0&sr=0:2157
execCb @ require.min.js:5
check @ require.min.js:5
(anonymous) @ require.min.js:5
(anonymous) @ require.min.js:5
(anonymous) @ require.min.js:5
each @ require.min.js:5
emit @ require.min.js:5
check @ require.min.js:5
(anonymous) @ require.min.js:5
(anonymous) @ require.min.js:5
(anonymous) @ require.min.js:5
each @ require.min.js:5
emit @ require.min.js:5
check @ require.min.js:5
enable @ require.min.js:5
init @ require.min.js:5
h @ require.min.js:5
completeLoad @ require.min.js:5
onScriptLoad @ require.min.js:5
load (async)
req.load @ require.min.js:5
load @ require.min.js:5
load @ require.min.js:5
fetch @ require.min.js:5
check @ require.min.js:5
enable @ require.min.js:5
enable @ require.min.js:5
(anonymous) @ require.min.js:5
(anonymous) @ require.min.js:5
each @ require.min.js:5
enable @ require.min.js:5
init @ require.min.js:5
h @ require.min.js:5
completeLoad @ require.min.js:5
onScriptLoad @ require.min.js:5
load (async)
req.load @ require.min.js:5
load @ require.min.js:5
load @ require.min.js:5
fetch @ require.min.js:5
check @ require.min.js:5
enable @ require.min.js:5
enable @ require.min.js:5
(anonymous) @ require.min.js:5
(anonymous) @ require.min.js:5
each @ require.min.js:5
enable @ require.min.js:5
init @ require.min.js:5
(anonymous) @ require.min.js:5
setTimeout (async)
req.nextTick @ require.min.js:5
o @ require.min.js:5
requirejs @ require.min.js:5
(anonymous) @ modedit.php?add=hvp&type=&course=54&section=0&return=0&sr=0:2058
yui_combo.php?3.17.2/event-mousewheel/event-mousewheel.js&3.17.2/event-resize/event-resize.js&3.17.2/event-hover/event-hover.js&3.17.2/event-touch/event-touch.js&3.17.2/event-move/event-move.js&3.17.2/event-flick/event-flick.js&3.17.2/event-valuechange/event-valuechange.js&3.17.2/event-tap/event-tap.js&m/1607331922/core/widget/widget-focusafterclose-debug.js&3.17.2/plugin/plugin.js&m/1607331922/core/lockscroll/lockscroll-debug.js&m/1607331922/core/notification/notification-dialogue-debug.js&3.17.2/json-stringify/json-stringify.js&m/1607331922/core_availability/form/form-debug.js&m/1607331922/availability_completion/form/form-debug.js&3.17.2/datatype-xml-parse/datatype-xml-parse.js&3.17.2/io-xdr/io-xdr.js&3.17.2/io-form/io-form.js&3.17.2/io-upload-iframe/io-upload-iframe.js&3.17.2/queue-promote/queue-promote.js&3.17.2/io-queue/io-queue.js&m/1607331922/availability_date/form/form-debug.js&m/1607331922/availability_grade/form/form-debug.js:38

51 Uncaught TypeError: Cannot read property 'setAttribute' of null
    at Object.init (yui_combo.php?3.17.2/event-mousewheel/event-mousewheel.js&3.17.2/event-resize/event-resize.js&3.17.2/event-hover/event-hover.js&3.17.2/event-touch/event-touch.js&3.17.2/event-move/event-move.js&3.17.2/event-flick/event-flick.js&3.17.2/event-valuechange/event-valuechange.js&3.17.2/event-tap/event-tap.js&m/1607331922/core/widget/widget-focusafterclose-debug.js&3.17.2/plugin/plugin.js&m/1607331922/core/lockscroll/lockscroll-debug.js&m/1607331922/core/notification/notification-dialogue-debug.js&3.17.2/json-stringify/json-stringify.js&m/1607331922/core_availability/form/form-debug.js&m/1607331922/availability_completion/form/form-debug.js&3.17.2/datatype-xml-parse/datatype-xml-parse.js&3.17.2/io-xdr/io-xdr.js&3.17.2/io-form/io-form.js&3.17.2/io-upload-iframe/io-upload-iframe.js&3.17.2/queue-promote/queue-promote.js&3.17.2/io-queue/io-queue.js&m/1607331922/availability_date/form/form-debug.js&m/1607331922/availability_grade/form/form-debug.js:3851)
    at modedit.php?add=hvp&type=&course=54&section=0&return=0&sr=0:2241
    at YUI._notify (yui_combo.php?rollup/3.17.2/yui-moodlesimple.js:1089)
    at yui_combo.php?rollup/3.17.2/yui-moodlesimple.js:1005
    at YUI._notify (yui_combo.php?rollup/3.17.2/yui-moodlesimple.js:1089)
    at YUI.handleLoader (yui_combo.php?rollup/3.17.2/yui-moodlesimple.js:1234)
    at Y.Loader._finish (yui_combo.php?rollup/3.17.2/yui-moodlesimple.js:8152)
    at Y.Loader._onSuccess (yui_combo.php?rollup/3.17.2/yui-moodlesimple.js:8201)
    at Y.Loader.complete (yui_combo.php?rollup/3.17.2/yui-moodlesimple.js:8440)
    at Y.Loader.onSuccess (yui_combo.php?rollup/3.17.2/yui-moodlesimple.js:8502)
anieminen commented 3 years ago

I did some debugging and found out that the "Course completion > Default activity completion" page saves the custom completion rules as JSON string to course_completion_defaults table: {"modids":{"12":12},"id":1052,"completionunlocked":1,"completionpass":0,"submitbutton":"Save changes","disable":15}

That JSON is decoded and added to the $defaultvalues array used in the activity edit/update form (mod_form.php). That form uses $defaultvalues['id'] to check if H5P activity/content already exists. But that fails because the id parameter saved to completion defaults is actually course id and not mod_hvp.id.

websdinamicas commented 3 years ago

Hello! This problem occurs also with Moodle 3.3.9 & mod_hvp 1.21.0 If it doesn't exists an hvp activity with that id you get the error 'invalidhvp' bup if exists any hvp activity with that id in the Moodle instance, then you get the form to edit that activity. in any case you cannot add a new H5P activity in the course.