From fb71171fc67c2b17a4ae58213dec04b48e5e180d Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Fri, 15 Aug 2014 17:17:17 +0800 Subject: [PATCH] MDL-46589 scheduled task does not send emails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to Luděk Šulák for the patch --- lib/classes/task/send_new_user_passwords_task.php | 3 ++- lib/moodlelib.php | 5 +++++ lib/tests/moodlelib_test.php | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/classes/task/send_new_user_passwords_task.php b/lib/classes/task/send_new_user_passwords_task.php index f0926fc3290..bdf55be6781 100644 --- a/lib/classes/task/send_new_user_passwords_task.php +++ b/lib/classes/task/send_new_user_passwords_task.php @@ -48,7 +48,8 @@ class send_new_user_passwords_task extends scheduled_task { if ($DB->count_records('user_preferences', array('name' => 'create_password', 'value' => '1'))) { mtrace('Creating passwords for new users...'); $usernamefields = get_all_user_name_fields(true, 'u'); - $newusers = $DB->get_recordset_sql("SELECT u.id as id, u.email, + $newusers = $DB->get_recordset_sql("SELECT u.id as id, u.email, u.auth, u.deleted, + u.suspended, u.emailstop, u.mnethostid, u.mailformat, $usernamefields, u.username, u.lang, p.id as prefid FROM {user} u diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 258e28d5813..1506890cc98 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -4742,6 +4742,11 @@ function update_internal_user_password($user, $password, $fasthash = false) { require_once($CFG->libdir.'/password_compat/lib/password.php'); // Figure out what the hashed password should be. + if (!isset($user->auth)) { + debugging('User record in update_internal_user_password() must include field auth', + DEBUG_DEVELOPER); + $user->auth = $DB->get_field('user', 'auth', array('id' => $user->id)); + } $authplugin = get_auth_plugin($user->auth); if ($authplugin->prevent_local_passwords()) { $hashedpassword = AUTH_PASSWORD_NOT_CACHED; diff --git a/lib/tests/moodlelib_test.php b/lib/tests/moodlelib_test.php index 50cd1a37c38..016d656b145 100644 --- a/lib/tests/moodlelib_test.php +++ b/lib/tests/moodlelib_test.php @@ -2262,6 +2262,13 @@ class core_moodlelib_testcase extends advanced_testcase { $this->assertSame($user->id, $event->relateduserid); $this->assertEquals(context_user::instance($user->id), $event->get_context()); $this->assertEventContextNotUsed($event); + + // Verify recovery of property 'auth'. + unset($user->auth); + update_internal_user_password($user, 'newpassword'); + $this->assertDebuggingCalled('User record in update_internal_user_password() must include field auth', + DEBUG_DEVELOPER); + $this->assertEquals('manual', $user->auth); } public function test_fullname() {