External DB Authentication Failing: Error inserting user

External DB Authentication Failing: Error inserting user

by Michael Chandler -
Number of replies: 1
I am trying to use external DB auth and it is failing with every possible test. Here is what I get on debugging: 


Execute scheduled task: Synchronise users task (auth_db\task\sync_users)
... started 17:45:52. Current memory use 8.2MB.

(mysqli): SELECT email_address
                                  FROM member    

User entries to add: 2

(mysqli): SELECT email_address AS F0, email_address AS F1
                      FROM member
                     WHERE email_address = 'saad@reticlesystems.com'   

This page should be using theme Tikli which cannot be initialised. Falling back to the site theme tikli
  • line 512 of /lib/outputlib.php: call to debugging()
  • line 7170 of /lib/moodlelib.php: call to theme_config::load()
  • line 467 of /lib/classes/user.php: call to get_list_of_themes()
  • line 628 of /lib/classes/user.php: call to core_user::fill_properties_cache()
  • line 597 of /lib/classes/user.php: call to core_user::get_property_type()
  • line 47 of /user/lib.php: call to core_user::clean_field()
  • line 464 of /auth/db/auth.php: call to user_create_user()
  • line 60 of /auth/db/classes/task/sync_users.php: call to auth_plugin_db->sync_users()
  • line 141 of /lib/cronlib.php: call to auth_db\task\sync_users->execute()
  • line 249 of /lib/cronlib.php: call to cron_run_inner_scheduled_task()
  • line 91 of /admin/tool/task/schedule_task.php: call to cron_run_single_task()
Error inserting user saad@reticlesystems.com
(mysqli): SELECT email_address AS F0, email_address AS F1 FROM member WHERE email_address = 'saad.saleem@edequal.com'  
Error inserting user saad.saleem@edequal.com ... used 7 dbqueries ... used 0.011574983596802 seconds Scheduled task complete: Synchronise users task (auth_db\task\sync_users)
Average of ratings: -
In reply to Michael Chandler

Re: External DB Authentication Failing: Error inserting user

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi Michael,

something (which is not appearing in your debug messages) is failing while trying to create the missing users. As you are using a non-standard theme (Tikli, apparently) and there's some debugging messages due to problems related to the theme, I can't reproduce your setup and debug the problem. So you will need to modify Moodle code a bit to get additional information about the underlying problem.

If you edit .../auth/db/auth.php, and find these lines of code (around line 463 in Moodle 3.3):

try {
    $id = user_create_user($user, false); // It is truly a new user.
    $trace->output(get_string('auth_dbinsertuser', 'auth_db', array('name'=>$user->username, 'id'=>$id)), 1);
} catch (moodle_exception $e) {
    $trace->output(get_string('auth_dbinsertusererror', 'auth_db', $user->username), 1);
    continue;
}

We need to change this line:

    $trace->output(get_string('auth_dbinsertusererror', 'auth_db', $user->username), 1);

to this:

    $trace->output(get_string('auth_dbinsertusererror', 'auth_db', $user->username) . print_r($e, true), 1);

so the final code block would look like this:

try {
    $id = user_create_user($user, false); // It is truly a new user.
    $trace->output(get_string('auth_dbinsertuser', 'auth_db', array('name'=>$user->username, 'id'=>$id)), 1);
} catch (moodle_exception $e) {
    $trace->output(get_string('auth_dbinsertusererror', 'auth_db', $user->username) . print_r($e, true), 1);
    continue;
}

That should display detailed information about the exception thrown by the code having trouble creating your users.

Saludos.

Iñaki.