moodle-local_datacleaner
moodle-local_datacleaner copied to clipboard
Table not found when using 'USING' (courses/delete_dangling_course_contexts)
I have tested this plugin in Moodle3.8 There seems to be an issue in the Courses/delete_dangling_course_contexts function.
ERROR
Default exception handler: Error writing to database Debug: Unknown table 'mdl_context' in MULTI DELETE
DELETE FROM mdl_context USING mdl_course
WHERE contextlevel = 50
AND mdl_context.instanceid = mdl_course.id
AND mdl_course.id IS NULL
The Error is produced with the execution of the following statement
$DB->execute("DELETE FROM {context} USING {course}
WHERE contextlevel = 50
AND {context}.instanceid = {course}.id
AND {course}.id IS NULL");
This is the correcting statement I used to successfully remove the dangling course context.
$DB->execute("DELETE {context} FROM {context}
LEFT JOIN {course}
ON {context}.instanceid = {course}.id
WHERE {course}.id IS NULL
AND {context}.contextlevel = 50");
thanks @Kevin-Hipwell can you please submit a pull request?