MDL-57432 lib: unify PHP version checks
* Introduce a new php compatible library which can be used early in execution, without Moodle dependencies * Use it where we previously had hardcoded checks This was originally suggested in MDL-39007.
This commit is contained in:
@@ -146,14 +146,9 @@ define('PHPUNIT_TEST', false);
|
||||
|
||||
define('IGNORE_COMPONENT_CACHE', true);
|
||||
|
||||
// Check that PHP is of a sufficient version
|
||||
if (version_compare(phpversion(), "5.6.5") < 0) {
|
||||
$phpversion = phpversion();
|
||||
// do NOT localise - lang strings would not work here and we CAN NOT move it after installib
|
||||
fwrite(STDERR, "Moodle 3.2 or later requires at least PHP 5.6.5 (currently using version $phpversion).\n");
|
||||
fwrite(STDERR, "Please upgrade your server software or install older Moodle version.\n");
|
||||
exit(1);
|
||||
}
|
||||
// Check that PHP is of a sufficient version as soon as possible.
|
||||
require_once(__DIR__.'/../../lib/phpminimumversionlib.php');
|
||||
moodle_require_minimum_php_version();
|
||||
|
||||
// set up configuration
|
||||
global $CFG;
|
||||
|
||||
@@ -62,14 +62,9 @@ Example:
|
||||
\$sudo -u www-data /usr/bin/php admin/cli/install_database.php --lang=cs --adminpass=soMePass123 --agree-license
|
||||
";
|
||||
|
||||
// Check that PHP is of a sufficient version
|
||||
if (version_compare(phpversion(), "5.6.5") < 0) {
|
||||
$phpversion = phpversion();
|
||||
// do NOT localise - lang strings would not work here and we CAN NOT move it after installib
|
||||
fwrite(STDERR, "Moodle 3.2 or later requires at least PHP 5.6.5 (currently using version $phpversion).\n");
|
||||
fwrite(STDERR, "Please upgrade your server software or install older Moodle version.\n");
|
||||
exit(1);
|
||||
}
|
||||
// Check that PHP is of a sufficient version as soon as possible.
|
||||
require_once(__DIR__.'/../../lib/phpminimumversionlib.php');
|
||||
moodle_require_minimum_php_version();
|
||||
|
||||
// Nothing to do if config.php does not exist
|
||||
$configfile = __DIR__.'/../../config.php';
|
||||
|
||||
+3
-8
@@ -29,14 +29,9 @@ if (!file_exists('../config.php')) {
|
||||
die();
|
||||
}
|
||||
|
||||
// Check that PHP is of a sufficient version as soon as possible
|
||||
if (version_compare(phpversion(), '5.6.5') < 0) {
|
||||
$phpversion = phpversion();
|
||||
// do NOT localise - lang strings would not work here and we CAN NOT move it to later place
|
||||
echo "Moodle 3.2 or later requires at least PHP 5.6.5 (currently using version $phpversion).<br />";
|
||||
echo "Please upgrade your server software or install older Moodle version.";
|
||||
die();
|
||||
}
|
||||
// Check that PHP is of a sufficient version as soon as possible.
|
||||
require_once(__DIR__.'/../lib/phpminimumversionlib.php');
|
||||
moodle_require_minimum_php_version();
|
||||
|
||||
// make sure iconv is available and actually works
|
||||
if (!function_exists('iconv')) {
|
||||
|
||||
+3
-8
@@ -61,14 +61,9 @@ date_default_timezone_set(@date_default_timezone_get());
|
||||
@error_reporting(E_ALL);
|
||||
@ini_set('display_errors', '1');
|
||||
|
||||
// Check that PHP is of a sufficient version.
|
||||
if (version_compare(phpversion(), '5.6.5') < 0) {
|
||||
$phpversion = phpversion();
|
||||
// do NOT localise - lang strings would not work here and we CAN not move it after installib
|
||||
echo "Moodle 3.2 or later requires at least PHP 5.6.5 (currently using version $phpversion).<br />";
|
||||
echo "Please upgrade your server software or install older Moodle version.";
|
||||
die;
|
||||
}
|
||||
// Check that PHP is of a sufficient version as soon as possible.
|
||||
require_once(__DIR__.'/../../lib/phpminimumversionlib.php');
|
||||
moodle_require_minimum_php_version();
|
||||
|
||||
// make sure iconv is available and actually works
|
||||
if (!function_exists('iconv')) {
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// MOODLE_INTERNAL check intentionally missing to allow this to be used more widely!
|
||||
|
||||
/**
|
||||
* A set of PHP-compatible convenience functions to check Moodle minimum PHP version in
|
||||
* a unified place.
|
||||
*
|
||||
* PLEASE NOTE: This file is made to be both php-version compatible and without requirement on
|
||||
* any moodle functions or installation so it can be used in installer or incompatible PHP versions.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2017 Dan Poltawski <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Require our minimum php version or halt execution if requirement not met.
|
||||
* @return void Execution is halted if version is not met.
|
||||
*/
|
||||
function moodle_require_minimum_php_version() {
|
||||
// PLEASE NOTE THIS FUNCTION MUST BE COMPATIBLE WITH OLD UNSUPPORTED VERSIONS OF PHP!
|
||||
moodle_minimum_php_version_is_met(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the current PHP version against Moodle's minimum requirement. When requirement
|
||||
* is not met returns false or halts execution depending $haltexecution param.
|
||||
*
|
||||
* @param bool $haltexecution Should execution be halted when requirement not met? Defaults to false.
|
||||
* @return bool returns true if requirement is met (false if not)
|
||||
*/
|
||||
function moodle_minimum_php_version_is_met($haltexecution = false) {
|
||||
// PLEASE NOTE THIS FUNCTION MUST BE COMPATIBLE WITH OLD UNSUPPORTED VERSIONS OF PHP.
|
||||
// Do not use modern php features or Moodle convenience functions (e.g. localised strings).
|
||||
|
||||
$minimumversion = '5.6.5';
|
||||
$moodlerequirementchanged = '3.2';
|
||||
|
||||
if (version_compare(PHP_VERSION, $minimumversion) < 0) {
|
||||
if ($haltexecution) {
|
||||
$error = "Moodle ${moodlerequirementchanged} or later requires at least PHP ${minimumversion} "
|
||||
. "(currently using version " . PHP_VERSION .").\n"
|
||||
. "Some servers may have multiple PHP versions installed, are you using the correct executable?\n";
|
||||
|
||||
// Our CLI scripts define CLI_SCRIPT before running this test, so make use of
|
||||
// to send error on STDERR.
|
||||
if (defined('CLI_SCRIPT') && defined('STDERR')) {
|
||||
fwrite(STDERR, $error);
|
||||
} else {
|
||||
echo $error;
|
||||
}
|
||||
exit(1);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// DO NOT ADD EXTRA FUNCTIONS TO THIS FILE!!
|
||||
// This file must be functioning on all versions of PHP, extra functions belong elsewhere.
|
||||
Reference in New Issue
Block a user