drachels / moodle-mod_mootyper

4 stars 18 forks source link

New activity not creating a new grade_item #83

Closed freeradicalx closed 4 years ago

freeradicalx commented 4 years ago

I've discovered a reproducible issue on activity completion, caused by an bug regarding missing grade_items.

Specs of both the production environment where this issue was first discovered and my dev environment where I was able to replicate it:

mod_mootyper release 3.8.3 / 2019123002
moodle version 3.8.1 / 2019111801.00
php 7.2
ubuntu server 18.04
mariadb 10.2.11

To reproduce, simply create a new Mootyper activity in a course. Go into the mdl_grade_items table in the database and confirm that a new row was not created for this activity. Then go to edit the activity's settings on the front end (Moodle activity settings page, not Mootyper settings): Open up Activity Completion, from the drop-down select "Show activity complete when conditions are met", and pick "Students must view this activity to complete it". Hit the Save and Display button and you should be presented with this error:

Debug info: Module mootyper claims to support
FEATURE_COMPLETION_HAS_RULES but does not have required
mootyper_get_completion_state function
Error code: err_system 

Stack trace:

    line 1369 of /lib/completionlib.php: moodle_exception thrown
    line 691 of /lib/completionlib.php: call to completion_info->internal_systemerror()
    line 614 of /lib/completionlib.php: call to completion_info->internal_get_state()
    line 740 of /lib/completionlib.php: call to completion_info->update_state()
    line 73 of /mod/mootyper/view.php: call to completion_info->set_module_viewed() 

I am not sure why grade_items are not being created, but the error itself seems to be caused by mod/mootyper/view.php on line 73 where it calls:

$completion->set_module_viewed($cm);

This kicks off a stack in lib/completionlib.php that eventually tries to pull up the grade_item for the module on line 661, and of course fails because none exists.

drachels commented 4 years ago

Thanks for reporting this! It's my fault. MooTyper has never used the grade capability of Moodle, but since I took over maintaining it, I have wanted to convert MooTyper's built in grading tables over to using Moodle's grading tables. Between MooTyper 3.6.1 and MooTyper 3.7.0, I was working on doing that, and started making some needed changes in lib.php. Since some of the case FEATURE's there would need to be true, I changed them from false to true, and that's what's causing the problem. Along about that time, we discovered my wife had pancreatic cancer so my priorities radically changed, and in the mad scramble to take care of her health, I totally forgot about those preliminary development changes I had made, and forgot to get rid of them. Meanwhile, changes to Moodle 3.7 and 3.8 caused some other MooTyper stuff to break, so I worked on what was needed for those changes, and forgot to finish the grading project, or at least, to eliminate the preliminary changes, so they have been included in recent MooTyper releases. I am hard at work on lot's of other new stuff for MooTyper, and will see what I can do to fix this for the next release to come out after Moodle 3.9. Meanwhile, I will test to see if it is safe to just reset the case settings in lib.php. If so, I will let you know.

drachels commented 4 years ago

Okay. A new grade item in table mdl_grade_items, should NOT be created since MooTyper is still using its own grade table. In the MooTyper lib.php file, around line 47, in the function mootyper_supports($feature), only the following should return true: case FEATURE_MOD_INTRO: case FEATURE_COMPLETION_TRACKS_VIEWS: case FEATURE_BACKUP_MOODLE2: case FEATURE_SHOW_DESCRIPTION:

All the other features should be set to false.

drachels commented 4 years ago

Features are set to false in the new v3.9.0 version.