From aa03ced86ca4a8e4058b6cad5e5f3f2fa22845f3 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 26 May 2016 13:57:31 +0800 Subject: [PATCH 1/2] MDL-54734 user: Add tests to demonstrate multi-user issues --- lib/tests/user_test.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/tests/user_test.php b/lib/tests/user_test.php index 03192a5c652..7aea5a4ec53 100644 --- a/lib/tests/user_test.php +++ b/lib/tests/user_test.php @@ -404,4 +404,28 @@ class core_user_testcase extends advanced_testcase { $this->setExpectedException('coding_exception', 'Invalid property requested, or the property does not has a default value.'); core_user::get_property_default('firstname'); } + + /** + * Ensure that the noreply user is not cached. + */ + public function test_get_noreply_user() { + global $CFG; + + // Create a new fake language 'xx' with the 'noreplyname'. + $langfolder = $CFG->dataroot . '/lang/xx'; + check_dir_exists($langfolder); + $langconfig = "lang='en'; + $enuser = \core_user::get_noreply_user(); + + $CFG->lang='xx'; + $xxuser = \core_user::get_noreply_user(); + + $this->assertNotEquals($enuser, $xxuser); + } + } From ec907228701299fa50634cc88d5206e061b18971 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Wed, 8 Jun 2016 10:18:45 +0800 Subject: [PATCH 2/2] MDL-54734 core_user: do not cache dummy user records --- lib/classes/user.php | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/classes/user.php b/lib/classes/user.php index 5a94658ed47..6a10819a94f 100644 --- a/lib/classes/user.php +++ b/lib/classes/user.php @@ -152,14 +152,15 @@ class core_user { // If noreply user is set then use it, else create one. if (!empty($CFG->noreplyuserid)) { self::$noreplyuser = self::get_user($CFG->noreplyuserid); + self::$noreplyuser->emailstop = 1; // Force msg stop for this user. + return self::$noreplyuser; + } else { + // Do not cache the dummy user record to avoid language internationalization issues. + $noreplyuser = self::get_dummy_user_record(); + $noreplyuser->maildisplay = '1'; // Show to all. + $noreplyuser->emailstop = 1; + return $noreplyuser; } - - if (empty(self::$noreplyuser)) { - self::$noreplyuser = self::get_dummy_user_record(); - self::$noreplyuser->maildisplay = '1'; // Show to all. - } - self::$noreplyuser->emailstop = 1; // Force msg stop for this user. - return self::$noreplyuser; } /** @@ -182,18 +183,19 @@ class core_user { // If custom support user is set then use it, else if supportemail is set then use it, else use noreply. if (!empty($CFG->supportuserid)) { self::$supportuser = self::get_user($CFG->supportuserid, '*', MUST_EXIST); - } - - // Try sending it to support email if support user is not set. - if (empty(self::$supportuser) && !empty($CFG->supportemail)) { - self::$supportuser = self::get_dummy_user_record(); - self::$supportuser->id = self::SUPPORT_USER; - self::$supportuser->email = $CFG->supportemail; + } else if (empty(self::$supportuser) && !empty($CFG->supportemail)) { + // Try sending it to support email if support user is not set. + $supportuser = self::get_dummy_user_record(); + $supportuser->id = self::SUPPORT_USER; + $supportuser->email = $CFG->supportemail; if ($CFG->supportname) { - self::$supportuser->firstname = $CFG->supportname; + $supportuser->firstname = $CFG->supportname; } - self::$supportuser->username = 'support'; - self::$supportuser->maildisplay = '1'; // Show to all. + $supportuser->username = 'support'; + $supportuser->maildisplay = '1'; // Show to all. + // Unset emailstop to make sure support message is sent. + $supportuser->emailstop = 0; + return $supportuser; } // Send support msg to admin user if nothing is set above.