FMCorz / moodle-block_xp

A gamification plugin for Moodle allowing students to gain experience points and level up.
https://levelup.plus/?ref=github
150 stars 42 forks source link

Trying to change "Default rules" in plugin settings produces a database error #134

Closed acquaalta closed 2 years ago

acquaalta commented 2 years ago

Hi,

Moodle version: 3.11.6 Plugin version: Level Up XP 3.12.0 (2022041501) Theme: Fordson

Problem

When I try to edit the "Default rules" in plugin settings in "Site administration", no matter which change is done, when I try to save changes, the following error appears. Apparently, a course id is expected as a parameter, but since it's a template rule, a course id is not relevant. Could you please clarify this issue? Thanks :-)

^^^^^^^^^^^^^^^^^^^^^ Error writing to database

Debug info: Column 'courseid' cannot be null INSERT INTO mdl_block_xp_filters (courseid,points,ruledata,sortorder,category) VALUES(?,?,?,?,?) [array ( 0 => NULL, 1 => 120, 2 => '{"_class":"block_xp_ruleset","method":"any","rules":[{"_class":"block_xp_rule_event","value":"\\mod_book\\event\\course_module_viewed"},{"_class":"block_xp_rule_event","value":"\\mod_forum\\event\\discussion_subscription_created"},{"_class":"block_xp_rule_event","value":"\\mod_forum\\event\\subscription_created"},{"_class":"block_xp_rule_property","property":"eventname","compare":"contains","value":"assessable_submitted"},{"_class":"block_xp_rule_property","property":"eventname","compare":"contains","value":"assessable_uploaded"}]}', 3 => 0, 4 => 0, )] Error code: dmlwriteexception

Stack trace: line 489 of /lib/dml/moodle_database.php: dml_write_exception thrown line 1357 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end() line 1403 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw() line 275 of /blocks/xp/classes/filter.php: call to mysqli_native_moodle_database->insert_record() line 127 of /blocks/xp/classes/local/controller/admin_rules_controller.php: call to block_xp_filter->save() line 97 of /blocks/xp/classes/local/controller/admin_rules_controller.php: call to block_xp\local\controller\admin_rules_controller->save_filters() line 81 of /blocks/xp/classes/local/controller/admin_rules_controller.php: call to block_xp\local\controller\admin_rules_controller->handle_save() line 214 of /blocks/xp/classes/local/controller/route_controller.php: call to block_xp\local\controller\admin_rules_controller->pre_content() line 80 of /blocks/xp/classes/local/routing/router.php: call to block_xp\local\controller\route_controller->handle() line 38 of /blocks/xp/index.php: call to block_xp\local\routing\router->dispatch() ^^^^^^^^^^^^^^^^^^^^^

acquaalta commented 2 years ago

After trying to pass the first error, another one is produced:

^^^^^^^^^^^^^^^^^^^^^ Coding error detected, it must be fixed by a programmer: Controller for route not found.

Debug info: Error code: codingerror

Stack trace: line 95 of /blocks/xp/classes/local/routing/router.php: coding_exception thrown line 79 of /blocks/xp/classes/local/routing/router.php: call to block_xp\local\routing\router->get_controller_from_request() line 38 of /blocks/xp/index.php: call to block_xp\local\routing\router->dispatch() ^^^^^^^^^^^^^^^^^^^^^

acquaalta commented 2 years ago

I found this help article in your website: https://levelup.plus/docs/article/error-controller-for-route-not-found

But: 1) The ""Site administration -> Server -> HTTP - Use slash arguments (slasharguments)" setting is enabled in our environments for a long time, and we didn't have any related problems with it in the past.

2) I disabled the "Site administration -> Server -> HTTP - Use slash arguments (slasharguments)" setting, and then I tried to edit the "Default rules" settings area again, and save changes. The second error regarding the controller disappeared, but the first error regarding the database still appears.

3) I can customize the default rule as a teacher in a specific course, after adding the block. I even verified as a student that after "obeying" the rule, I got the expected number of experience points and got one level up.

So basically, the plugin seems to work, but the important "Default rules" settings area can't be customized. So a teacher would have to delete manually all the redundant rules each time he/she adds the block to a course.

Could you please clarify this issue? Thanks a lot and sorry for the trouble.

FMCorz commented 2 years ago

Hi @acquaalta,

Thank you very much for the detailed and thorough report. You identified a bug that was a regression from another one (11e094a9488a27d717c58f187aa3e0884a84fcac).

We fixed the bug and released the version v3.12.1.

The other error should be unrelated, if that issue persists, would you please raise another ticket?

Thank you! Fred

acquaalta commented 2 years ago

Hi Frédéric, Thanks a lot for the fast response. I downloaded the updated plugin, installed it, and it seems that the original error is gone, and I can save the default rules in the plugin settings.