Skip to content

Commit

Permalink
MDL-50624 environment: add PHP7 as unsupported version
Browse files Browse the repository at this point in the history
Added PHP7 as an unsupported version for Moodle 2.8 and 2.9 in
the environment checks
  • Loading branch information
ryanwyllie committed Aug 3, 2015
1 parent d846254 commit 19452dc
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
2 changes: 2 additions & 0 deletions admin/environment.xml
Expand Up @@ -1150,6 +1150,7 @@
<VENDOR name="oracle" version="10.2" />
</DATABASE>
<PHP version="5.4.4" level="required">
<RESTRICT function="restrict_php_version_7" message="unsupportedphpversion7" />
</PHP>
<PCREUNICODE level="optional">
<FEEDBACK>
Expand Down Expand Up @@ -1273,6 +1274,7 @@
<VENDOR name="oracle" version="10.2" />
</DATABASE>
<PHP version="5.4.4" level="required">
<RESTRICT function="restrict_php_version_7" message="unsupportedphpversion7" />
</PHP>
<PCREUNICODE level="optional">
<FEEDBACK>
Expand Down
1 change: 1 addition & 0 deletions lang/en/admin.php
Expand Up @@ -1072,6 +1072,7 @@
$string['unsupported'] = 'Unsupported';
$string['unsupporteddbstorageengine'] = 'The database storage engine being used is no longer supported.';
$string['unsupporteddbtablerowformat'] = 'Your database has tables using Antelope as the file format. You are recommended to convert the tables to the Barracuda file format. See the documentation <a href="https://docs.moodle.org/en/cli">Administration via command line</a> for details of a tool for converting InnoDB tables to Barracuda.';
$string['unsupportedphpversion7'] = 'PHP version 7 is not supported.';
$string['unsuspenduser'] = 'Activate user account';
$string['updateaccounts'] = 'Update existing accounts';
$string['updatecomponent'] = 'Update component';
Expand Down
34 changes: 34 additions & 0 deletions lib/environmentlib.php
Expand Up @@ -1538,3 +1538,37 @@ function process_environment_result($element, &$result) {
/// Process restrict, modifying $result if needed.
process_environment_restrict($element, $result);
}

/**
* Check if the current PHP version is greater than or equal to
* PHP version 7.
*
* @param object $result an environment_results instance
* @return bool result of version check
*/
function restrict_php_version_7(&$result) {
return restrict_php_version($result, '7');
}

/**
* Check if the current PHP version is greater than or equal to an
* unsupported version.
*
* @param object $result an environment_results instance
* @param string $version the version of PHP that can't be used
* @return bool result of version check
*/
function restrict_php_version(&$result, $version) {

// Get the current PHP version.
$currentversion = normalize_version(phpversion());

// Confirm we're using a supported PHP version.
if (version_compare($currentversion, $version, '<')) {
// Everything is ok, the restriction doesn't apply.
return false;
} else {
// We're using an unsupported PHP version, apply restriction.
return true;
}
}
65 changes: 65 additions & 0 deletions lib/tests/environment_test.php
Expand Up @@ -128,4 +128,69 @@ public function test_verify_plugin() {
$this->assertFalse(environment_verify_plugin('mod_someother', $plugin1['PLUGIN']));
$this->assertFalse(environment_verify_plugin('mod_someother', $plugin2['PLUGIN']));
}

/**
* Test the restrict_php_version() function returns true if the current
* PHP version is greater than the restricted version
*/
public function test_restrict_php_version_greater_than_restricted_version() {
global $CFG;
require_once($CFG->libdir.'/environmentlib.php');

$result = new environment_results('php');
$delimiter = '.';
// Get the current PHP version.
$currentversion = explode($delimiter, normalize_version(phpversion()));
// Lets drop back one major version to ensure we trip the restriction.
$currentversion[0]--;
$restrictedversion = implode($delimiter, $currentversion);

// Make sure the status is true before the test to see it flip to false.
$result->setStatus(true);

$this->assertTrue(restrict_php_version($result, $restrictedversion),
'restrict_php_version returns true if the current version exceeds the restricted version');
}

/**
* Test the restrict_php_version() function returns true if the current
* PHP version is equal to the restricted version
*/
public function test_restrict_php_version_equal_to_restricted_version() {
global $CFG;
require_once($CFG->libdir.'/environmentlib.php');

$result = new environment_results('php');
// Get the current PHP version.
$currentversion = normalize_version(phpversion());

// Make sure the status is true before the test to see it flip to false.
$result->setStatus(true);

$this->assertTrue(restrict_php_version($result, $currentversion),
'restrict_php_version returns true if the current version is equal to the restricted version');
}

/**
* Test the restrict_php_version() function returns false if the current
* PHP version is less than the restricted version
*/
public function test_restrict_php_version_less_than_restricted_version() {
global $CFG;
require_once($CFG->libdir.'/environmentlib.php');

$result = new environment_results('php');
$delimiter = '.';
// Get the current PHP version.
$currentversion = explode($delimiter, normalize_version(phpversion()));
// Lets increase the major version to ensure don't trip the restriction.
$currentversion[0]++;
$restrictedversion = implode($delimiter, $currentversion);

// Make sure the status is true before the test to see it flip to false.
$result->setStatus(true);

$this->assertFalse(restrict_php_version($result, $restrictedversion),
'restrict_php_version returns false if the current version is less than the restricted version');
}
}

0 comments on commit 19452dc

Please sign in to comment.