From 86c22b202db22cf4461cd6c214224df8202cd89f Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Wed, 2 Nov 2016 16:06:20 +0530 Subject: [PATCH] MDL-55777 installation: Check libcurl version on install --- admin/environment.xml | 25 +++++++++++++++++++++++++ lang/en/admin.php | 1 + lib/tests/upgradelib_test.php | 17 +++++++++++++++++ lib/upgradelib.php | 29 +++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) diff --git a/admin/environment.xml b/admin/environment.xml index 1f522ab379d..032b8d7a8d5 100644 --- a/admin/environment.xml +++ b/admin/environment.xml @@ -1145,6 +1145,11 @@ + + + + + @@ -1418,6 +1423,11 @@ + + + + + @@ -1556,6 +1566,11 @@ + + + + + @@ -1696,6 +1711,11 @@ + + + + + @@ -1841,6 +1861,11 @@ + + + + + diff --git a/lang/en/admin.php b/lang/en/admin.php index ba8cd6bb565..b0c7b2f74ba 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -612,6 +612,7 @@ $string['legacyfilesaddallowed'] = 'Allow adding to legacy course files'; $string['legacyfilesaddallowed_help'] = 'If a course has legacy course files, allow new files and folders to be added to it.'; $string['legacyfilesinnewcourses'] = 'Legacy course files in new courses'; $string['legacyfilesinnewcourses_help'] = 'By default, legacy course files areas are available in upgraded courses only. Please note that some features such as activity backup and restore are not compatible with this setting.'; +$string['libcurlwarning'] = 'Libcurl with CURLOPT_PROTOCOL support has not been detected. It is recommended to have an up to date libcurl installation for security reasons.'; $string['licensesettings'] = 'Licence settings'; $string['linkadmincategories'] = 'Link admin categories'; $string['linkadmincategories_help'] = 'If enabled admin setting categories will be displayed as links in the navigation and will lead to the admin category pages.'; diff --git a/lib/tests/upgradelib_test.php b/lib/tests/upgradelib_test.php index fc060958f8a..81eb6c30eaa 100644 --- a/lib/tests/upgradelib_test.php +++ b/lib/tests/upgradelib_test.php @@ -741,4 +741,21 @@ class core_upgradelib_testcase extends advanced_testcase { $this->assertEquals($gradecategoryitem->grademax, $grade->rawgrademax); $this->assertEquals($gradecategoryitem->grademin, $grade->rawgrademin); } + + /** + * Test libcurl custom check api. + */ + public function test_check_libcurl_version() { + $supportedversion = 0x071304; + $curlinfo = curl_version(); + $currentversion = $curlinfo['version_number']; + + $result = new environment_results("custom_checks"); + if ($currentversion < $supportedversion) { + $this->assertFalse(check_libcurl_version($result)->getStatus()); + } else { + $this->assertNull(check_libcurl_version($result)); + } + } + } diff --git a/lib/upgradelib.php b/lib/upgradelib.php index 8cc30c3de82..0a9301a2246 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -2331,3 +2331,32 @@ function upgrade_minmaxgrade() { } $rs->close(); } + +/** + * Check if recommended version of libcurl is installed or not. + * + * @param environment_results $result object to update, if relevant. + * @return environment_results|null updated results or null. + */ +function check_libcurl_version(environment_results $result) { + + // Supported version and version number. + $supportedversion = 0x071304; + $supportedversionstring = "7.19.4"; + + // Installed version. + $curlinfo = curl_version(); + $currentversion = $curlinfo['version_number']; + + if ($currentversion < $supportedversion) { + // Test fail. + // Set info, we want to let user know how to resolve the problem. + $result->setInfo('Libcurl version check'); + $result->setNeededVersion($supportedversionstring); + $result->setCurrentVersion($curlinfo['version']); + $result->setStatus(false); + return $result; + } + + return null; +}