From f0ae7c434347889bd0a867447647392f07e87165 Mon Sep 17 00:00:00 2001 From: Huong Nguyen Date: Tue, 5 Mar 2024 11:40:07 +0700 Subject: [PATCH] MDL-80167 admin: Add environment check for Oracle database --- admin/environment.xml | 8 ++++++++ lang/en/admin.php | 1 + lib/tests/upgradelib_test.php | 32 ++++++++++++++++++++++++++++++++ lib/upgradelib.php | 23 +++++++++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/admin/environment.xml b/admin/environment.xml index 4925aafb1c8..e031c7fc270 100644 --- a/admin/environment.xml +++ b/admin/environment.xml @@ -3923,6 +3923,8 @@ + + @@ -4113,6 +4115,8 @@ + + @@ -4305,6 +4309,8 @@ + + @@ -4496,6 +4502,8 @@ + + diff --git a/lang/en/admin.php b/lang/en/admin.php index f6cb4d630bb..3b5a456836d 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -942,6 +942,7 @@ $string['opensslrecommended'] = 'Installing the optional OpenSSL library is high $string['opensslrequired'] = 'The OpenSSL PHP extension is now required by Moodle to provide stronger cryptographic services.'; $string['opentowebcrawlers'] = 'Open to search engines'; $string['optionalmaintenancemessage'] = 'Optional maintenance message'; +$string['oracledatabaseinuse'] = 'We are changing Oracle DB support in Moodle LMS. Moodle version 4.5 will be the last version that supports Oracle as a database architecture. Further information can be found here'; $string['order1'] = 'First'; $string['order2'] = 'Second'; $string['order3'] = 'Third'; diff --git a/lib/tests/upgradelib_test.php b/lib/tests/upgradelib_test.php index 994aa7fff34..ff04fd23df1 100644 --- a/lib/tests/upgradelib_test.php +++ b/lib/tests/upgradelib_test.php @@ -1386,6 +1386,38 @@ class upgradelib_test extends advanced_testcase { } } + /** + * Test the check_oracle_usage check when the Moodle instance is not using Oracle as a database architecture. + * + * @covers ::check_oracle_usage + */ + public function test_check_oracle_usage_is_not_used(): void { + global $CFG; + + $this->resetAfterTest(); + $CFG->dbtype = 'pgsql'; + + $result = new environment_results('custom_checks'); + $this->assertNull(check_oracle_usage($result)); + } + + /** + * Test the check_oracle_usage check when the Moodle instance is using Oracle as a database architecture. + * + * @covers ::check_oracle_usage + */ + public function test_check_oracle_usage_is_used(): void { + global $CFG; + + $this->resetAfterTest(); + $CFG->dbtype = 'oci'; + + $result = new environment_results('custom_checks'); + $this->assertInstanceOf(environment_results::class, check_oracle_usage($result)); + $this->assertEquals('oracle_database_usage', $result->getInfo()); + $this->assertFalse($result->getStatus()); + } + /** * Data provider of usermenu items. * diff --git a/lib/upgradelib.php b/lib/upgradelib.php index 1551ef3f163..d53bfb82fe8 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -2835,3 +2835,26 @@ function check_mod_assignment(environment_results $result): ?environment_results return null; } + +/** + * Check whether the Oracle database is currently being used and warn if so. + * + * The Oracle database support will be removed in a future version (4.5) as it is no longer supported by PHP. + * + * @param environment_results $result object to update, if relevant + * @return environment_results|null updated results or null if the current database is not Oracle. + * + * @see https://tracker.moodle.org/browse/MDL-80166 for further information. + */ +function check_oracle_usage(environment_results $result): ?environment_results { + global $CFG; + + // Checking database type. + if ($CFG->dbtype === 'oci') { + $result->setInfo('oracle_database_usage'); + $result->setFeedbackStr('oracledatabaseinuse'); + return $result; + } + + return null; +}