Commit 29b2451c authored by xjm's avatar xjm

Issue #2908079 by jungle, voleger, mpdonadio, zahord, andypost, RoSk0, Mile23,...

Issue #2908079 by jungle, voleger, mpdonadio, zahord, andypost, RoSk0, Mile23, claudiu.cristea, alexpott, xjm, Krzysztof Domański, naveenvalecha, piggito, Suresh Prabhu Parkala, daffie, dawehner, gumanist: Move some of the bootstrap.inc PHP-related constants to \Drupal and deprecate the old versions
parent 5c96d911
......@@ -13,7 +13,7 @@
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
/**
* Minimum allowed version of PHP.
* Minimum allowed version of PHP for Drupal to be bootstrapped.
*
* Below this version:
* - The installer cannot be run.
......@@ -22,12 +22,13 @@
* - If a site managed to bypass all of the above, then an error is shown in
* the status report and various fatal errors occur on various pages.
*
* @see install.php
* @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
* \Drupal::MINIMUM_PHP instead.
*
* @todo Move this to an appropriate autoloadable class. See
* https://www.drupal.org/project/drupal/issues/2908079
* @see https://www.drupal.org/node/2909361
* @see install.php
*/
const DRUPAL_MINIMUM_PHP = '7.3.0';
const DRUPAL_MINIMUM_PHP = \Drupal::MINIMUM_PHP;
/**
* Minimum supported version of PHP.
......@@ -38,10 +39,12 @@
* that Drupal no longer supports that PHP version.
* - An error is shown in the status report that the PHP version is too old.
*
* @todo Move this to an appropriate autoloadable class. See
* https://www.drupal.org/project/drupal/issues/2908079
* @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
* \Drupal::MINIMUM_SUPPORTED_PHP instead.
*
* @see https://www.drupal.org/node/2909361
*/
const DRUPAL_MINIMUM_SUPPORTED_PHP = '7.3.0';
const DRUPAL_MINIMUM_SUPPORTED_PHP = \Drupal::MINIMUM_SUPPORTED_PHP;
/**
* Minimum recommended version of PHP.
......@@ -50,10 +53,12 @@
* message, but Drupal can still be installed. Used for (e.g.) PHP versions
* that have reached their EOL or will in the near future.
*
* @todo Move this to an appropriate autoloadable class. See
* https://www.drupal.org/project/drupal/issues/2908079
* @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
* \Drupal::RECOMMENDED_PHP instead.
*
* @see https://www.drupal.org/node/2909361
*/
const DRUPAL_RECOMMENDED_PHP = '7.3';
const DRUPAL_RECOMMENDED_PHP = \Drupal::RECOMMENDED_PHP;
/**
* Minimum recommended value of PHP memory_limit.
......@@ -62,10 +67,12 @@
* contributed modules to be installed prior to hitting the limit. However,
* 40M is the target for the Standard installation profile.
*
* @todo Move this to an appropriate autoloadable class. See
* https://www.drupal.org/project/drupal/issues/2908079
* @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
* \Drupal::MINIMUM_PHP_MEMORY_LIMIT instead.
*
* @see https://www.drupal.org/node/2909361
*/
const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = '64M';
const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = \Drupal::MINIMUM_PHP_MEMORY_LIMIT;
/**
* Error reporting level: display no errors.
......
......@@ -1099,7 +1099,7 @@ function install_profile_info($profile, $langcode = 'en') {
'description' => '',
'version' => NULL,
'hidden' => FALSE,
'php' => DRUPAL_MINIMUM_PHP,
'php' => \Drupal::MINIMUM_PHP,
'config_install_path' => NULL,
];
$profile_path = drupal_get_path('profile', $profile);
......
......@@ -21,12 +21,16 @@
*/
define('MAINTENANCE_MODE', 'install');
// Exit early if running an incompatible PHP version to avoid fatal errors.
// The minimum version is specified explicitly, as DRUPAL_MINIMUM_PHP is not
// yet available. It is defined in bootstrap.inc, but it is not possible to
// load that file yet as it would cause a fatal error on older versions of PHP.
// Exit early if an incompatible PHP version is in use, so that the user sees a
// helpful error message rather than a whitescreen from any fatal errors due to
// the incompatible version. The minimum version is also hardcoded (instead of
// \Drupal::MINIMUM_PHP), to avoid any fatal errors that might result from
// loading the autoloader or core/lib/Drupal.php. Note: Remember to update the
// hardcoded minimum PHP version below (both in the version_compare() call and
// in the printed message to the user) whenever \Drupal::MINIMUM_PHP is
// updated.
if (version_compare(PHP_VERSION, '7.3.0') < 0) {
print 'Your PHP installation is too old. Drupal requires at least PHP 7.3.0. See the <a href="https://www.drupal.org/requirements">system requirements</a> page for more information.';
print 'Your PHP installation is too old. Drupal requires at least PHP 7.3.0. See the <a href="https://www.drupal.org/docs/9/how-drupal-9-is-made-and-what-is-included/environment-requirements-of-drupal-9#s-php-version-requirement">Environment requirements of Drupal 9</a> page for more information.';
exit;
}
......
......@@ -92,6 +92,53 @@ class Drupal {
*/
const CORE_MINIMUM_SCHEMA_VERSION = 8000;
/**
* Minimum supported version of PHP.
*
* Below this version:
* - New sites cannot be installed, except from within tests.
* - Updates from previous Drupal versions can be run, but users are warned
* that Drupal no longer supports that PHP version.
* - An error is shown in the status report that the PHP version is too old.
*/
const MINIMUM_SUPPORTED_PHP = '7.3.0';
/**
* Minimum allowed version of PHP for Drupal to be bootstrapped.
*
* Below this version:
* - The installer cannot be run.
* - Updates cannot be run.
* - Modules and themes cannot be enabled.
* - If a site managed to bypass all of the above, then an error is shown in
* the status report and various fatal errors occur on various pages.
*
* Note: To prevent the installer from having fatal errors on older versions
* of PHP, the value of this constant is hardcoded twice in core/install.php:
* - Once as a parameter of version_compare()
* - Once in the error message printed to the user immediately after.
* Remember to update both whenever this constant is updated.
*/
const MINIMUM_PHP = '7.3.0';
/**
* Minimum recommended value of PHP memory_limit.
*
* 64M was chosen as a minimum requirement in order to allow for additional
* contributed modules to be installed prior to hitting the limit. However,
* 40M is the target for the Standard installation profile.
*/
const MINIMUM_PHP_MEMORY_LIMIT = '64M';
/**
* Minimum recommended version of PHP.
*
* Sites installing Drupal on PHP versions lower than this will see a warning
* message, but Drupal can still be installed. Used for (e.g.) PHP versions
* that have reached their EOL or will in the near future.
*/
const RECOMMENDED_PHP = '7.3';
/**
* The currently active container object, or NULL if not initialized yet.
*
......
......@@ -28,7 +28,7 @@ class ModuleExtensionList extends ExtensionList {
'description' => '',
'package' => 'Other',
'version' => NULL,
'php' => DRUPAL_MINIMUM_PHP,
'php' => \Drupal::MINIMUM_PHP,
];
/**
......
......@@ -22,7 +22,7 @@ class ProfileExtensionList extends ExtensionList {
'description' => '',
'package' => 'Other',
'version' => NULL,
'php' => DRUPAL_MINIMUM_PHP,
'php' => \Drupal::MINIMUM_PHP,
];
/**
......
......@@ -21,7 +21,7 @@ class ThemeEngineExtensionList extends ExtensionList {
'description' => '',
'package' => 'Other',
'version' => NULL,
'php' => DRUPAL_MINIMUM_PHP,
'php' => \Drupal::MINIMUM_PHP,
];
/**
......
......@@ -48,7 +48,7 @@ class ThemeExtensionList extends ExtensionList {
],
'screenshot' => 'screenshot.png',
'version' => NULL,
'php' => DRUPAL_MINIMUM_PHP,
'php' => \Drupal::MINIMUM_PHP,
'libraries' => [],
'libraries_extend' => [],
'libraries_override' => [],
......
......@@ -987,8 +987,8 @@ function hook_requirements($phase) {
'title' => t('PHP'),
'value' => ($phase == 'runtime') ? Link::fromTextAndUrl(phpversion(), Url::fromRoute('system.php'))->toString() : phpversion(),
];
if (version_compare(phpversion(), DRUPAL_MINIMUM_PHP) < 0) {
$requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version.', ['%version' => DRUPAL_MINIMUM_PHP]);
if (version_compare(phpversion(), \Drupal::MINIMUM_PHP) < 0) {
$requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version.', ['%version' => \Drupal::MINIMUM_PHP]);
$requirements['php']['severity'] = REQUIREMENT_ERROR;
}
......
......@@ -202,19 +202,19 @@ function system_requirements($phase) {
}
// Check if the PHP version is below what Drupal supports.
if (version_compare($phpversion, DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) {
$requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version. It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See <a href="http://php.net/supported-versions.php">PHP\'s version support documentation</a> and the <a href=":php_requirements">Drupal 8 PHP requirements handbook page</a> for more information.',
if (version_compare($phpversion, \Drupal::MINIMUM_SUPPORTED_PHP) < 0) {
$requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version. It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See <a href="http://php.net/supported-versions.php">PHP\'s version support documentation</a> and the <a href=":php_requirements">Environment requirements of Drupal 9</a> page for more information.',
[
'%version' => DRUPAL_MINIMUM_SUPPORTED_PHP,
'%recommended' => DRUPAL_RECOMMENDED_PHP,
':php_requirements' => 'https://www.drupal.org/docs/8/system-requirements/php',
'%version' => \Drupal::MINIMUM_SUPPORTED_PHP,
'%recommended' => \Drupal::RECOMMENDED_PHP,
':php_requirements' => 'https://www.drupal.org/docs/9/how-drupal-9-is-made-and-what-is-included/environment-requirements-of-drupal-9#s-php-version-requirement',
]
);
$requirements['php']['severity'] = REQUIREMENT_ERROR;
// If the PHP version is also below the absolute minimum allowed, it's not
// safe to continue with the requirements check.
if (version_compare($phpversion, DRUPAL_MINIMUM_PHP) < 0) {
if (version_compare($phpversion, \Drupal::MINIMUM_PHP) < 0) {
return $requirements;
}
// Otherwise downgrade the error to a warning during updates. Even if there
......@@ -235,8 +235,8 @@ function system_requirements($phase) {
// For PHP versions that are still supported but no longer recommended,
// inform users of what's recommended, allowing them to take action before it
// becomes urgent.
elseif ($phase === 'runtime' && version_compare($phpversion, DRUPAL_RECOMMENDED_PHP) < 0) {
$requirements['php']['description'] = t('It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See <a href="http://php.net/supported-versions.php">PHP\'s version support documentation</a> and the <a href=":php_requirements">Drupal 8 PHP requirements handbook page</a> for more information.', ['%recommended' => DRUPAL_RECOMMENDED_PHP, ':php_requirements' => 'https://www.drupal.org/docs/8/system-requirements/php']);
elseif ($phase === 'runtime' && version_compare($phpversion, \Drupal::RECOMMENDED_PHP) < 0) {
$requirements['php']['description'] = t('It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See <a href="http://php.net/supported-versions.php">PHP\'s version support documentation</a> and the <a href=":php_requirements">Drupal 8 PHP requirements handbook page</a> for more information.', ['%recommended' => \Drupal::RECOMMENDED_PHP, ':php_requirements' => 'https://www.drupal.org/docs/8/system-requirements/php']);
$requirements['php']['severity'] = REQUIREMENT_INFO;
}
......@@ -463,16 +463,16 @@ function system_requirements($phase) {
'value' => $memory_limit == -1 ? t('-1 (Unlimited)') : $memory_limit,
];
if (!Environment::checkMemoryLimit(DRUPAL_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {
if (!Environment::checkMemoryLimit(\Drupal::MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {
$description = [];
if ($phase == 'install') {
$description['phase'] = t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the installation process.', ['%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT]);
$description['phase'] = t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the installation process.', ['%memory_minimum_limit' => \Drupal::MINIMUM_PHP_MEMORY_LIMIT]);
}
elseif ($phase == 'update') {
$description['phase'] = t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the update process.', ['%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT]);
$description['phase'] = t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the update process.', ['%memory_minimum_limit' => \Drupal::MINIMUM_PHP_MEMORY_LIMIT]);
}
elseif ($phase == 'runtime') {
$description['phase'] = t('Depending on your configuration, Drupal can run with a %memory_limit PHP memory limit. However, a %memory_minimum_limit PHP memory limit or above is recommended, especially if your site uses additional custom or contributed modules.', ['%memory_limit' => $memory_limit, '%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT]);
$description['phase'] = t('Depending on your configuration, Drupal can run with a %memory_limit PHP memory limit. However, a %memory_minimum_limit PHP memory limit or above is recommended, especially if your site uses additional custom or contributed modules.', ['%memory_limit' => $memory_limit, '%memory_minimum_limit' => \Drupal::MINIMUM_PHP_MEMORY_LIMIT]);
}
if (!empty($description['phase'])) {
......
......@@ -82,7 +82,3 @@ public function testFind() {
}
}
if (!defined('DRUPAL_MINIMUM_PHP')) {
define('DRUPAL_MINIMUM_PHP', '7.0.8');
}
......@@ -86,7 +86,7 @@ public function tearDown(): void {
* Tests the quick-start command.
*/
public function testQuickStartCommand() {
if (version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) {
if (version_compare(phpversion(), \Drupal::MINIMUM_SUPPORTED_PHP) < 0) {
$this->markTestSkipped();
}
if (version_compare(\SQLite3::version()['versionString'], Tasks::SQLITE_MINIMUM_VERSION) < 0) {
......@@ -144,7 +144,7 @@ public function testQuickStartCommand() {
* Tests that the installer throws a requirement error on older PHP versions.
*/
public function testPhpRequirement() {
if (version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) >= 0) {
if (version_compare(phpversion(), \Drupal::MINIMUM_SUPPORTED_PHP) >= 0) {
$this->markTestSkipped();
}
......@@ -167,7 +167,7 @@ public function testPhpRequirement() {
$error_output = $process->getErrorOutput();
$this->assertStringContainsString('Your PHP installation is too old.', $error_output);
$this->assertStringContainsString('Drupal requires at least PHP', $error_output);
$this->assertStringContainsString(DRUPAL_MINIMUM_SUPPORTED_PHP, $error_output);
$this->assertStringContainsString(\Drupal::MINIMUM_SUPPORTED_PHP, $error_output);
// Stop the web server.
$process->stop();
......@@ -177,7 +177,7 @@ public function testPhpRequirement() {
* Tests the quick-start commands.
*/
public function testQuickStartInstallAndServerCommands() {
if (version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) {
if (version_compare(phpversion(), \Drupal::MINIMUM_SUPPORTED_PHP) < 0) {
$this->markTestSkipped();
}
if (version_compare(\SQLite3::version()['versionString'], Tasks::SQLITE_MINIMUM_VERSION) < 0) {
......
......@@ -155,7 +155,3 @@ public function testValidateTwoThemeDependencies() {
}
}
if (!defined('DRUPAL_MINIMUM_PHP')) {
define('DRUPAL_MINIMUM_PHP', '7.3.0');
}
......@@ -259,7 +259,3 @@ class TestThemeEngineExtensionList extends ThemeEngineExtensionList {
use SettableDiscoveryExtensionListTrait;
}
if (!defined('DRUPAL_MINIMUM_PHP')) {
define('DRUPAL_MINIMUM_PHP', '7.3.0');
}
......@@ -145,7 +145,3 @@ protected function themeRegistryRebuild() {
}
}
if (!defined('DRUPAL_MINIMUM_PHP')) {
define('DRUPAL_MINIMUM_PHP', '7.3.0');
}
......@@ -13,7 +13,7 @@ trait RequirementsPageTrait {
protected function updateRequirementsProblem() {
// Assert a warning is shown on older test environments.
$links = $this->getSession()->getPage()->findAll('named', ['link', 'try again']);
if ($links && version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) {
if ($links && version_compare(phpversion(), \Drupal::MINIMUM_SUPPORTED_PHP) < 0) {
$this->assertNoText('Errors found');
$this->assertWarningSummaries(['PHP']);
$this->clickLink('try again');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment