### Can not find data record in DB table course

Can not find data record in DB table course

Moodle 3.1.7

Since updating our system a few months ago. I now have trouble deleting one particular user. I can edit the user. Enrol the user into courses but cannot delete them. Can someone help me query the DB to check if this is the only user in the database with this same problem? It makes me want to know if this is an isolated event or a wider issue.

I guess the error is enrolment plugins but I need help with running a query to find out where the problem is.

What query would I run to find where the problem is? Any help appriecated.

Error

Debug info: SELECT id,category FROM {course} WHERE id = ?
[array (
0 => '1938',
)]
Error code: invalidrecord
Stack trace:
• line 1526 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
• line 1502 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
• line 6984 of /lib/accesslib.php: call to moodle_database->get_record()
• line 1459 of /lib/enrollib.php: call to context_course::instance()
• line 2010 of /lib/enrollib.php: call to enrol_plugin->unenrol_user()
• line 880 of /lib/enrollib.php: call to enrol_plugin->user_delete()
• line 4005 of /lib/moodlelib.php: call to enrol_user_delete()
• line 90 of /admin/user.php: call to delete_user()

Regards,

Yvonne

Average of ratings: -
Re: Can not find data record in DB table course

Any ideas on this one people?

Regards,

Yvonne

Average of ratings: -
Re: Can not find data record in DB table course

Haven't had the same problem so this an attempt to address yours ...

The error points to a course category?

The id of the the course or category is 1938 ... that's a lot of categories as id's are usually sequential and never attempt to reuse an ID number but, rather, continue to add.   OR it's a course.

What do you get for:

select * from mdl_course where category like '1938';

OR same table ...

select * from mdl_course where id like '1938';

Go to the course first if found and see about status of course (hidden, etc.) and enrolled users

Then check out site Categories to see if  that course shows and what it's order is.

Other than that .... ????

'spirit of sharing', Ken

Average of ratings: Useful (1)
Re: Can not find data record in DB table course

Your comments helped. And you are correct we do not have anywhere near that number of categories. All I can guess is somehow a category level enrolment/role has lingered after a course was deleted...maybe 'Other users' creates an enrol entry??  I do, and would've in this case too, applied a category level role to this user.

Under mdl_course, no course with id: 1938 exists, and I am confident it would've existed in the past but has since been deleted as the sequential order of adjacent courses fits the correct cluster of courses/category the user I am trying to delete would've been enrolled in, so a good start.

The userid for the person I am trying to delete is 32733.

The error message mentions enrol id (/lib/enrollib.php: call to enrol_plugin->unenrol_user()) so I looked in mdl_user_enrolments l and found the entry below relating to userid 32733 shown below.. This user doesn't show in the front end as being enrolled in any courses at all.

Also, under mdl_enrol I can see this entry below relating to courseid 1938. I would be happy to delete the entry under mdl_enrol relating to courseid 1938 as I know this course doesn't exist. My question is, do I also need to delete the mdl_user_enrolment entry for userid: 32733 as this user isn't showing as being enrolled in any courses at all.

Any further recommendations would be appreciated.

Regards,

Yvonne

Average of ratings: -
Re: Can not find data record in DB table course

Removing any user record(s) in db is sorta taking a chance on 'orphaned' whatever - ditto for a course by id.

I know this is gonna sound strange, but, error is kinda strange ...

In admin/cli/ there is a backup.php script that can be used to backup a single course and that backup can be saved outside the 'sea' of files in /moodledata/filedir/.   You know the course ID ... 1938

So let's see if there's anything tied to the course:

mkdir /path/to/moodleDATA/check

﻿php backup.php --courseid=1938 --destination=/path/to/moodleDATA/check/﻿

That might very well error out ... which, in this case is a good sign that the backup can't find stuff for that course.

**Might** need to inspect what Moodle was able to build for the backup ...  in /path/to/moodleDATA/temp/backup/.  There **might** be a moodle_backup.xml file or other .xml files and from them, **might** be able to see other things that are related and **might** need to be investigated.

If user had a teacher/manager/admin role there could be files associated to user ... and one really doesn't want to get and orphaned files situation/started with moodledata/fileir/ ... especially large backups.

As far as the user ... search mdl_users for that user ID ... which is actually the row ID.

Needless to say ... make a backup of the DB before ... just in case.

'spirit of sharing', Ken

Average of ratings: -
Re: Can not find data record in DB table course

Thanks,

I only have adminer access not server side so might err on the side of caution at this point. Thanks for the suggestions, will see if I can get IT to try your suggestions when they are able.

Regards,

Yvonne

Average of ratings: -