Unable to delete course which used to have hotpot activity

Unable to delete course which used to have hotpot activity

by Markus Kwaśnicki -
Number of replies: 3

Hello dear all,

the Moodle instance I am administrating used to have mod_hotpot plug-in installed and it was used in various courses. Nevertheless, there came  a decision to uninstall mod_hotpot, because we don't want to use it anymore. So, all courses with usage of mod_hotpot were edited, respectively—mod_hotpot was removed.

Now I want to delete a course which used to have hotpot activity. My attempts to delete this particular course result in an error, as shown below.

Database transaction aborted automatically in /var/www/html/moodle
Default exception handler: Error reading from database Debug: SQLState: 42S02
Error Code: 208
Message: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid object name 'mdl_hotpot'.
SELECT cm.*, m.name, md.name AS modname FROM mdl_course_modules cm JOIN mdl_modules md ON md.id = cm.module JOIN mdl_hotpot m ON m.id = cm.instance WHERE m.id = '20765' AND md.name = N'hotpot' AND cm.course = '66902' [array ( 0 => '20765', 1 => 'hotpot', 2 => '66902', )] Error code: dmlreadexception * line 486 of /lib/dml/moodle_database.php: dml_read_exception thrown * line 324 of /lib/dml/sqlsrv_native_moodle_database.php: call to moodle_database->query_end() * line 431 of /lib/dml/sqlsrv_native_moodle_database.php: call to sqlsrv_native_moodle_database->query_end() * line 900 of /lib/dml/sqlsrv_native_moodle_database.php: call to sqlsrv_native_moodle_database->do_query() * line 976 of /lib/dml/sqlsrv_native_moodle_database.php: call to sqlsrv_native_moodle_database->get_recordset_sql() * line 1671 of /lib/dml/moodle_database.php: call to sqlsrv_native_moodle_database->get_records_sql() * line 1313 of /lib/datalib.php: call to moodle_database->get_record_sql() * line 1188 of /lib/grade/grade_grade.php: call to get_coursemodule_from_instance() * line 301 of /lib/grade/grade_object.php: call to grade_grade->notify_changed() * line 1125 of /lib/grade/grade_grade.php: call to grade_object->delete() * line 447 of /lib/grade/grade_item.php: call to grade_grade->delete() * line 418 of /lib/grade/grade_item.php: call to grade_item->delete_all_grades() * line 313 of /lib/grade/grade_category.php: call to grade_item->delete() * line 1454 of /lib/gradelib.php: call to grade_category->delete() * line 5093 of /lib/moodlelib.php: call to remove_course_grades() * line 5007 of /lib/moodlelib.php: call to remove_course_contents() * line 41 of /opt/moosh/Moosh/Command/Moodle39/Course/CourseDelete.php: call to delete_course() * line 361 of /opt/moosh/moosh.php: call to Moosh\Command\Moodle39\Course\CourseDelete->execute() !!! Error reading from database !!!

As one can see, the delete process tries to query the database table mdl_hotpot, which is not present anymore. This is the reason for the database error. Because of that, I am asking myself, why does it try to query that particular not existing database table, in the first-place? My guess is, that somewhere are artifacts of mod_hotpot left over. Unfortunately, I was not successful in searching the code base of Moodle or the plug-in itself to find anything helpful.—However, I can assure, that this particular course has no mod_hoptpot activity.

Did anyone encounter (and hopefully solved) such an issue before?

Thanks in advance and

best regards,
Markus

Average of ratings: -
In reply to Markus Kwaśnicki

Re: Unable to delete course which used to have hotpot activity

by Gordon Bateson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi there, despite your assurances,
Moodle thinks there is still a HotPot somewhere in the course. Specifically, there is an item in the gradebook that points to a HotPot that no longer exists.

There is no straightforward way to fix the problem using just the Moodle front end. However, because you show us the output of a "moosh" command, I guess that you also have access to the server. In that case, there are two ways you could proceed:

[1] temporarily modify the Moodle scripts to skip incomplete activities, such as the HotPot you are having trouble with
The line numbers in your mesage suggest you are using Moodle 4.00. In that case, please open up "lib/datalib.php" with you favorite text editor and locate the "get_coursemodule_from_instance()" function. It should be around line 1282. A few lines into that function, you should see the following line:
$params = array('instance'=>$instance, 'modulename'=>$modulename);
Directly after that line, insert the following lines:
    if (! $DB->get_manager()->table_exists($modulename)) {
        return false;
    }
    if (! $DB->record_exists($modulename, array('id' => $instance))) {
        return false;
    }
[2] modify the database manually to remove references to the incomplete activity
The problem lies in the gradebook. There is an item there that points to the missing HotPot. Maybe you can find that item (and others like it) with the following SQL:
SELECT * FROM mdl_grade_items WHERE itemtype = "mod" AND itemmodule = "hotpot"
I don't think you need those items, so you can delete them, but ONLY DELETE STUFF AT YOUR OWN RISK smile

You don't need to do both of the above actions. One should suffice.

Hope that helps,
Gordon BATESON

Average of ratings: Useful (1)
In reply to Gordon Bateson

Re: Unable to delete course which used to have hotpot activity

by Markus Kwaśnicki -
Hi Gordon!

Thank you very much for your answer. It helped me very much, solving my problem.
Using your SQL statement I found a lot more courses still having hotpot gradebook items, which could possibly lead to issues in the future.
So, I decided to patch my lib/datalib.php file in-place.

Kind regards,
Markus
In reply to Markus Kwaśnicki

Re: Unable to delete course which used to have hotpot activity

by Gordon Bateson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
Hi Markus,
thanks for the feedback. I'm glad that your site is back to full working order.

On further investigation, it seems that between us we have a found a bug in the HotPot module. When deleting an activity, the software for that activity is supposed to delete the grade item first and then the activity's main record, but the HotPot module did not do this. Instead, it deleted the activity record first. This appears to be why the grade items for your HotPot records got left behind.

The good news is that I have fixed the bug now and arranged for all orphan grade items for HotPots to be removed the next time anyone updates their HotPot module.

Many thanks,
and best regards
Gordon