Skip to content
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

Error with Quiz activity, conflict with Grade in settings form #18

Open
PatLemaire opened this issue May 13, 2019 · 6 comments
Open

Error with Quiz activity, conflict with Grade in settings form #18

PatLemaire opened this issue May 13, 2019 · 6 comments

Comments

@PatLemaire
Copy link

Context :

  • Tested on both Moodle 3.5.5 (Build: 20190311) and Moodle 3.5 (Build: 20180517)
  • « metadata for modules » is activated
  • Add a few metadatas (a checkbox, a Date/Time and a Dropdown menu)
  • Add a Quiz activity to a course
  • Try to edit Quiz's settings
    A debug message appears :
Notice: Undefined index: grade in path\to\moodle\mod\quiz\mod_form.php on line 474
with Call Stack
	Time	Memory	Function	Location
1	0.0006	427000	{main}( )	...\modedit.php:0
2	0.3061	24388392	mod_quiz_mod_form->__construct( )	...\modedit.php:141
3	0.3061	24388344	mod_quiz_mod_form->__construct( )	...\mod_form.php:58
4	0.3067	24389224	mod_quiz_mod_form->__construct( )	...\moodleform_mod.php:99
5	0.3400	26129344	mod_quiz_mod_form->definition( )	...\formslib.php:204
6	0.5411	29050328	mod_quiz_mod_form->standard_coursemodule_elements( )	...\mod_form.php:393
7	0.6016	29834160	mod_quiz_mod_form->plugin_extend_coursemodule_standard_elements( )	...\moodleform_mod.php:733
8	0.6276	30971080	local_metadata_coursemodule_standard_elements( )	...\moodleform_mod.php:745
9	0.6320	31172592	metadatacontext_module\context_handler->coursemodule_standard_elements( )	...\lib.php:421
10	0.6484	31111808	mod_quiz_mod_form->set_data( )	...\context_handler.php:199
11	0.6484	31111832	mod_quiz_mod_form->data_preprocessing( )	...\moodleform_mod.php:477

If we try to save the form, a new error message appears and there is no change in settings.

@nadavkav
Copy link

nadavkav commented Sep 1, 2019

I have a similar issue with mod/hvp (H5P)

line 494 of /lib/setuplib.php: moodle_exception thrown
line 182 of /mod/hvp/mod_form.php: call to print_error()
line 481 of /course/moodleform_mod.php: call to mod_hvp_mod_form->data_preprocessing()
line 199 of /local/metadata/context/module/classes/context_handler.php: call to moodleform_mod->set_data()
line 421 of /local/metadata/lib.php: call to metadatacontext_module\context_handler->coursemodule_standard_elements()
line 749 of /course/moodleform_mod.php: call to local_metadata_coursemodule_standard_elements()
line 737 of /course/moodleform_mod.php: call to moodleform_mod->plugin_extend_coursemodule_standard_elements()
line 118 of /mod/hvp/mod_form.php: call to moodleform_mod->standard_coursemodule_elements()
line 206 of /lib/formslib.php: call to mod_hvp_mod_form->definition()
line 99 of /course/moodleform_mod.php: call to moodleform->__construct()
line 141 of /course/modedit.php: call to moodleform_mod->__construct()

And I found the issue is caused by:
$formwrapper->set_data($this->instance);
https://github.com/PoetOS/moodle-local_metadata/blob/master/context/module/classes/context_handler.php#L199
$this->instance->id is supposed to be mdl_course_module.instanceid, and instead it is mdl_course_module.id

Workaround:
Disable metadata > module support.

@nadavkav
Copy link

nadavkav commented Sep 1, 2019

@mchurchward , do you have any idea how to fix this?

@seb-vial
Copy link

seb-vial commented Sep 1, 2019

Cf the PR associated to that feature #8 (comment)

My workaround for H5P is right down ugly but could not find any other solution for now.

@nadavkav
Copy link

nadavkav commented Sep 1, 2019

Found a working workaround:

if (!empty($this->instance->instance)) {
            $this->instance->id = $this->instance->instance;
        }

Which does not break H5P and Metadata data.

@nadavkav
Copy link

nadavkav commented Sep 1, 2019

@Birssan , great insight! just saw your comment :-) and I wished I saw it earlier, as I spend too much valuable time xdebugging the code to find it.

Indeed, I came to the same conclusion as you did.

I ran some tests, and It seems nothing in the local_metadata table data gets broken by this, so I am going to try it for a while, and see that there is no data corruption in the mdl_local_metadata table by this hack.

But, I am still looking for @mchurchward review and insights on this.

@seb-vial
Copy link

seb-vial commented Sep 1, 2019

I believe H5P is actually responsible for this issue. The plugin seems to change the form object received by the hook function and is not "formed" like it is in the core modules plug-ins. (or so I believed as there is the same issue with mod_quiz...)

Your solution is definitely better than mine as it's generic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants