moodle-local_datacleaner icon indicating copy to clipboard operation
moodle-local_datacleaner copied to clipboard

Table not found when using 'USING' (courses/delete_dangling_course_contexts)

Open Kevin-Hipwell opened this issue 5 years ago • 1 comments

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");

Kevin-Hipwell avatar Jan 16 '20 13:01 Kevin-Hipwell

thanks @Kevin-Hipwell can you please submit a pull request?

brendanheywood avatar Jan 16 '20 13:01 brendanheywood