Error when deleting data for user
monnardj opened this issue · 2 comments
When a user is deleted from Moodle, a data deletion request is created. And when this request is processed by the cron job, an error is raised :
Error writing to database
#0 /var/www/htdocs/lib/dml/moodle_read_slave_trait.php(293): moodle_database->query_end()
#1 /var/www/htdocs/lib/dml/mysqli_native_moodle_database.php(1703): mysqli_native_moodle_database->query_end()
#2 /var/www/htdocs/mod/hotquestion/classes/privacy/provider.php(366): mysqli_native_moodle_database->delete_records_select()
#3 /var/www/htdocs/lib/moodlelib.php(8144): mod_hotquestion\privacy\provider::delete_data_for_user()
#4 /var/www/htdocs/privacy/classes/manager.php(578): component_class_callback()
#5 /var/www/htdocs/privacy/classes/manager.php(611): core_privacy\manager::component_class_callback()
#6 /var/www/htdocs/privacy/classes/manager.php(415): core_privacy\manager->handled_component_class_callback()
#7 /var/www/htdocs/admin/tool/dataprivacy/classes/task/process_data_request_task.php(138): core_privacy\manager->delete_data_for_user()
#8 /var/www/htdocs/lib/cronlib.php(367): tool_dataprivacy\task\process_data_request_task->execute()
#9 /var/www/htdocs/lib/cronlib.php(198): cron_run_inner_adhoc_task()
#10 /var/www/htdocs/lib/cronlib.php(76): cron_run_adhoc_tasks()
#11 /var/www/htdocs/admin/cli/cron.php(178): cron_run()
#12 {main}
Looking at the code, there seems to be an error in /classes/privacy/provider.php at line 366. An SQL query is executed on table 'hotquestion_votes' which references field 'userid'. But this table contains no such field. The field for the user id in this table is apparently called 'voter'.
The SQL query at line 366 should be modified accordingly (note that tables 'hotquestion_questions' and 'hotquestion_grades' do have a field 'userid', which is used correctly at line 368 in the same file).
Edit : lines 407-409 also contain invalid field names from table 'hotquestion_votes'. They use 'userid' and 'itemid', which both don't exist in the table.
I have been trying to find the time to go back through the provider.php file for quite some time now, but have been too busy with other things, and I have also been sick a lot this year, especially had a lot of problems with my eyes.
I see the error you pointed out and it looks like probably the same type of error in line 408. I think I also forgot to see if there is anything I need to do to handle any comments made by a user on some question. I will have to dig back through my ticket system and see what I can find out.
I will try to work on this file as much as I can, but it might take a couple of days. My eyes started bothering me again yesterday, but hopefully I detected it early enough and started treatment so that maybe I will not have to spend any days sitting in a darkened room doing nothing.
Just pushed changes in provider.php lines 366 and 408 to the master branch. I have only had time to test for personal data export so far which looked okay. Have not tested for a delete request just yet. I need to add some more student data to my new test site, and will not get to that until tomorrow.