The $USER variable can be null in certain situations, so this should be checked in the settings file.
dml_missing_record_exception: Invalid user (SELECT id FROM {user} WHERE id = ? AND deleted = ?
[array (
0 => 0,
1 => 0,
)])
lib/dml/moodle_database.php:1654
lib/dml/moodle_database.php:1630
lib/classes/context/user.php:166
local/course_templates/settings.php:29
The $USER variable can be null in certain situations, so this should be checked in the settings file.