PHP errors from scheduled task
johnhpercival opened this issue ยท 7 comments
Hello
We have recently started receiving errors from our cron script:
PHP Notice: Undefined variable: hotquestion in
/srv/###/public/htdocs/mod/hotquestion/lib.php on line 187
PHP Notice: Trying to get property 'name' of non-object in
/srv/###/public/htdocs/mod/hotquestion/lib.php on line 785
PHP Notice: Trying to get property 'grade' of non-object in
/srv/###/public/htdocs/mod/hotquestion/lib.php on line 788
PHP Notice: Trying to get property 'grade' of non-object in
/srv/###/public/htdocs/mod/hotquestion/lib.php on line 792
PHP Notice: Trying to get property 'course' of non-object in
/srv/###/public/htdocs/mod/hotquestion/lib.php on line 805
PHP Notice: Trying to get property 'id' of non-object in
/srv/###/public/htdocs/mod/hotquestion/lib.php on line 808
Looking at the line numbers, could it be caused by the new grading functionality?
85e0033
I have not yet been able to locate the cause of this in Moodle's scheduled task log, but will update when I do. My guess is that it is triggered by core\task\grade_cron_task
Hi,
By any chance, did you have a pre-existing HotQuestion that already had multiple questions posted, and try and change it to a "graded" HotQuestion activity?
I need a lot more details to be able to try and duplicate the problem. What OS, Web Server, PHP, Database, and Moodle are you using?
The info requested:
Debian 10.10
Apache/2.4.38 (Debian)
PHP 7.3.30-1+020210826.87+debian101.gbpe56a7b
MariaDB 10.3.29-MariaDB-0+deb10u1 Debian 10
Moodle $version = 2021051708.01 $release = 3.11.8+ (Build: 20220714)
Hotquestion 2022070702
I have not been able to replicate the issue yet, just picking up things from the cron logs, which we will continue to monitor for further details. I wonder if the fundamental issue is that $hotquestion does not appear to be set in the lib.php function reset_instance() - the line 187 error. This is then be making the call to hotquestion_grade_item_update() that is generating the errors in lines 785-808.
Sorry to say I was too busy with other things to really look at this yesterday, but now I see that it should be fairly simple to fix, just need the time to do it. The line of code in, lib.php, at 187 is in the, function reset_instance($hotquestionid). Notice that it is an ID being passed into the function. Nowhere in the function is the ID being used to get the actual $hotquestion record, yet line 187 is trying to use it, which leads to the undefined variable error. This is possibly going to lead to a few orphaned grades, but I will need to do some testing to make sure. I will try to publish a fix as soon as I can.
I have some issues to take care of here at home, and do not have time to recreate your setup. Could you add the following code snippet as line 167 in lib.php, and see if it fixes your error?
$hotquestion = $DB->get_record('hotquestion', array('id' => $hotquestionid));
Let me know if it does, and I will make sure it is in the next upgrade.
Thanks, have applied change and will monitor. It looks like you have identified the problem. Since it's an intermittent problem, I don't have any way of reproducing it. If you've got any ideas what user actions trigger this then let me know. Otherwise I will continue to monitor - so if you hear nothing more it means it's worked (or not been repeated!). Thanks again and I hope things at home go ok :)
It was intermittent as it occurred when a HQ activity was reset in any way. However, there was enough redundancy so that, even though this function was not resetting the user grades when it should, they were being updated by other functions. You just happened to catch the fact that there was an undefined variable error being generated and this change fixes that so the grade reset occurs promptly when it should and doesn't depend on another function to clean up after it. Thanks again for posting the error.
Fix is in v4.1.2.00.