From 8bb9fe14ca8b4d12ea910b7b3282031811dc803c Mon Sep 17 00:00:00 2001 From: meirzamoodle Date: Fri, 23 May 2025 10:59:56 +0700 Subject: [PATCH] MDL-85316 admin: Add environment check for AWS Aurora database --- admin/environment.xml | 6 ++++ lang/en/admin.php | 1 + .../auroramysql_native_moodle_database.php | 2 +- lib/tests/upgradelib_test.php | 32 +++++++++++++++++++ lib/upgradelib.php | 20 ++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) diff --git a/admin/environment.xml b/admin/environment.xml index 1e05329b721..65df3e7b76c 100644 --- a/admin/environment.xml +++ b/admin/environment.xml @@ -4716,6 +4716,7 @@ + @@ -4895,6 +4896,8 @@ + + @@ -4908,6 +4911,7 @@ + @@ -5092,6 +5096,8 @@ + + diff --git a/lang/en/admin.php b/lang/en/admin.php index 58b8840b5d9..1cd7d469a13 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -621,6 +621,7 @@ $string['enroladminnewcourse_help'] = 'When an admin adds a new course, should t $string['enrolinstancedefaults'] = 'Enrolment instance defaults'; $string['enrolinstancedefaults_desc'] = 'Default enrolment settings in new courses.'; $string['enrolmultipleusers'] = 'Enrol the users'; +$string['ensureauroraversion'] = 'Your site is running on Amazon Aurora database engine. Please ensure that the MySQL version in Amazon Aurora is compatible with the Moodle version you are installing or upgrading to. You can check the compatibility in the Database engine updates for Amazon Aurora MySQL version 3.'; $string['environment'] = 'Environment'; $string['environmenterrortodo'] = 'You must solve all the environmental problems (errors) found above before proceeding to install this Moodle version!'; $string['environmenterrorupgrade'] = 'Warning: you should solve all the environmental problems (errors) found above before proceeding to upgrade this Moodle version! Upgrading without fixing these requirements could cause problems such as data loss. Are you sure you want to continue with the upgrade?'; diff --git a/lib/dml/auroramysql_native_moodle_database.php b/lib/dml/auroramysql_native_moodle_database.php index 88e0c83a78b..902ace66839 100644 --- a/lib/dml/auroramysql_native_moodle_database.php +++ b/lib/dml/auroramysql_native_moodle_database.php @@ -68,7 +68,7 @@ class auroramysql_native_moodle_database extends mysqli_native_moodle_database { * @return string The db vendor name, usually the same as db family name. */ public function get_dbvendor(): ?string { - return 'mysql'; + return 'auroramysql'; } /** diff --git a/lib/tests/upgradelib_test.php b/lib/tests/upgradelib_test.php index 187c793e8b9..b373d05988e 100644 --- a/lib/tests/upgradelib_test.php +++ b/lib/tests/upgradelib_test.php @@ -1731,4 +1731,36 @@ calendar,core_calendar|/calendar/view.php?view=month', $this->assertEquals('/page2', get_user_preferences('user_home_page_preference', null, $user1->id)); $this->assertEquals(HOMEPAGE_MY, get_user_preferences('user_home_page_preference', null, $user2->id)); } + + /** + * Test the check_aurora_version check when the Moodle instance is not using Amazon Aurora as a database architecture. + * + * @covers ::check_aurora_version + */ + public function test_check_aurora_version_is_not_used(): void { + global $CFG; + + $this->resetAfterTest(); + $CFG->dbtype = 'pgsql'; + + $result = new environment_results('custom_checks'); + $this->assertNull(check_aurora_version($result)); + } + + /** + * Test the check_aurora_version check when the Moodle instance is using Amazon Aurora as a database architecture. + * + * @covers ::check_aurora_version + */ + public function test_check_aurora_version_is_used(): void { + global $CFG; + + $this->resetAfterTest(); + $CFG->dbtype = 'auroramysql'; + + $result = new environment_results('custom_checks'); + $this->assertInstanceOf(environment_results::class, check_aurora_version($result)); + $this->assertEquals('Aurora compatibility', $result->getInfo()); + $this->assertFalse($result->getStatus()); + } } diff --git a/lib/upgradelib.php b/lib/upgradelib.php index 665d2f56d51..5555d011c59 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -2798,3 +2798,23 @@ function check_async_backup(environment_results $result): ?environment_results { return null; } + +/** + * Checks if the current database vendor is Aurora MySQL. + * + * If the database vendor is 'auroramysql', this function sets additional information. + * + * @param environment_results $result The environment results object to update. + * @return environment_results|null The updated environment results object if Aurora is detected, or null otherwise. + */ +function check_aurora_version(environment_results $result): ?environment_results { + global $CFG; + + if ($CFG->dbtype === 'auroramysql') { + $result->setInfo('Aurora compatibility'); + $result->setFeedbackStr('ensureauroraversion'); + return $result; + } + + return null; +}