From 243b25d946cff1fbd9db5740c42ab09fa97ec40a Mon Sep 17 00:00:00 2001 From: Andrew Hunt Date: Wed, 11 Mar 2020 19:30:35 -0400 Subject: [PATCH 1/2] Consolidate to single constant for minimum PHP version --- CRM/Upgrade/Form.php | 13 ++----------- tests/phpunit/CRM/Upgrade/FormTest.php | 5 +++-- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/CRM/Upgrade/Form.php b/CRM/Upgrade/Form.php index 176b0db558ff..46d0ac92684f 100644 --- a/CRM/Upgrade/Form.php +++ b/CRM/Upgrade/Form.php @@ -31,15 +31,6 @@ class CRM_Upgrade_Form extends CRM_Core_Form { */ const MINIMUM_UPGRADABLE_VERSION = '4.2.9'; - /** - * Minimum php version required to run (equal to or lower than the minimum install version) - * - * As of Civi 5.16, using PHP 5.x will lead to a hard crash during bootstrap. - * - * Tip: Keep in sync with composer.json ("config => platform => php") - */ - const MINIMUM_PHP_VERSION = '7.1.0'; - /** * @var \CRM_Core_Config */ @@ -457,10 +448,10 @@ public function checkUpgradeableVersion($currentVer, $latestVer) { ); } - if (version_compare(phpversion(), self::MINIMUM_PHP_VERSION) < 0) { + if (version_compare(phpversion(), CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER) < 0) { $error = ts('CiviCRM %3 requires PHP version %1 (or newer), but the current system uses %2 ', [ - 1 => self::MINIMUM_PHP_VERSION, + 1 => CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER, 2 => phpversion(), 3 => $latestVer, ]); diff --git a/tests/phpunit/CRM/Upgrade/FormTest.php b/tests/phpunit/CRM/Upgrade/FormTest.php index a9af358959df..7a3d82567a14 100644 --- a/tests/phpunit/CRM/Upgrade/FormTest.php +++ b/tests/phpunit/CRM/Upgrade/FormTest.php @@ -7,7 +7,8 @@ class CRM_Upgrade_FormTest extends CiviUnitTestCase { /** - * "php" requirement (composer.json) should match MINIMUM_PHP_VERSION (CRM/Upgrade/Form.php). + * "php" requirement (composer.json) should match + * CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER. */ public function testComposerRequirementMatch() { global $civicrm_root; @@ -16,7 +17,7 @@ public function testComposerRequirementMatch() { $composerJson = json_decode(file_get_contents($composerJsonPath), 1); $composerJsonRequirePhp = preg_replace(';[~^];', '', $composerJson['require']['php']); $actualMajorMinor = preg_replace(';^[\^]*(\d+\.\d+)\..*$;', '\1', $composerJsonRequirePhp); - $expectMajorMinor = preg_replace(';^[\^]*(\d+\.\d+)\..*$;', '\1', \CRM_Upgrade_Form::MINIMUM_PHP_VERSION); + $expectMajorMinor = preg_replace(';^[\^]*(\d+\.\d+)\..*$;', '\1', \CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER); $this->assertEquals($expectMajorMinor, $actualMajorMinor, "The PHP version requirements in CRM_Upgrade_Form ($expectMajorMinor) and composer.json ($actualMajorMinor) should specify same major+minor versions."); } From f955c30c5a2292236f9e8216257b7d9f35093bb5 Mon Sep 17 00:00:00 2001 From: Andrew Hunt Date: Wed, 11 Mar 2020 21:02:18 -0400 Subject: [PATCH 2/2] Full PHP versions as recommendations --- CRM/Upgrade/Incremental/General.php | 15 ++++++++++----- CRM/Utils/Check/Component/Env.php | 8 ++++---- install/index.php | 2 +- tests/phpunit/CRM/Upgrade/FormTest.php | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CRM/Upgrade/Incremental/General.php b/CRM/Upgrade/Incremental/General.php index 440e594079ec..013bd70b7363 100644 --- a/CRM/Upgrade/Incremental/General.php +++ b/CRM/Upgrade/Incremental/General.php @@ -24,20 +24,25 @@ class CRM_Upgrade_Incremental_General { /** * The recommended PHP version. + * + * The point release will be dropped in recommendations unless it's .1 or + * higher. */ - const RECOMMENDED_PHP_VER = '7.3'; + const RECOMMENDED_PHP_VER = '7.3.0'; /** - * The previous recommended PHP version. + * The minimum recommended PHP version. + * + * A site running an earlier version will be told to upgrade. */ - const MIN_RECOMMENDED_PHP_VER = '7.2'; + const MIN_RECOMMENDED_PHP_VER = '7.2.0'; /** * The minimum PHP version required to install Civi. * * @see install/index.php */ - const MIN_INSTALL_PHP_VER = '7.1'; + const MIN_INSTALL_PHP_VER = '7.1.0'; /** * Compute any messages which should be displayed before upgrade. @@ -54,7 +59,7 @@ public static function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $l $preUpgradeMessage .= ts('You may proceed with the upgrade and CiviCRM %1 will continue working normally, but future releases will require PHP %2 or above. We recommend PHP version %3.', [ 1 => $latestVer, 2 => self::MIN_RECOMMENDED_PHP_VER, - 3 => self::RECOMMENDED_PHP_VER, + 3 => preg_replace(';^(\d+\.\d+(?:\.[1-9]\d*)?).*$;', '\1', self::RECOMMENDED_PHP_VER), ]); $preUpgradeMessage .= '

'; } diff --git a/CRM/Utils/Check/Component/Env.php b/CRM/Utils/Check/Component/Env.php index b6ebd4e7d678..d5c9451fcaf4 100644 --- a/CRM/Utils/Check/Component/Env.php +++ b/CRM/Utils/Check/Component/Env.php @@ -29,7 +29,7 @@ public function checkPhpVersion() { ts('This system uses PHP version %1 which meets or exceeds the recommendation of %2.', [ 1 => $phpVersion, - 2 => CRM_Upgrade_Incremental_General::RECOMMENDED_PHP_VER, + 2 => preg_replace(';^(\d+\.\d+(?:\.[1-9]\d*)?).*$;', '\1', CRM_Upgrade_Incremental_General::RECOMMENDED_PHP_VER), ]), ts('PHP Up-to-Date'), \Psr\Log\LogLevel::INFO, @@ -56,7 +56,7 @@ public function checkPhpVersion() { [ 1 => $phpVersion, 2 => CRM_Upgrade_Incremental_General::MIN_RECOMMENDED_PHP_VER, - 3 => CRM_Upgrade_Incremental_General::RECOMMENDED_PHP_VER, + 3 => preg_replace(';^(\d+\.\d+(?:\.[1-9]\d*)?).*$;', '\1', CRM_Upgrade_Incremental_General::RECOMMENDED_PHP_VER), ]), ts('PHP Out-of-Date'), \Psr\Log\LogLevel::WARNING, @@ -66,11 +66,11 @@ public function checkPhpVersion() { else { $messages[] = new CRM_Utils_Check_Message( __FUNCTION__, - ts('This system uses PHP version %1. To ensure the continued operation of CiviCRM, upgrade your server now. At least PHP version %2 is recommended; the preferrred version is %3.', + ts('This system uses PHP version %1. To ensure the continued operation of CiviCRM, upgrade your server now. At least PHP version %2 is recommended; the preferred version is %3.', [ 1 => $phpVersion, 2 => CRM_Upgrade_Incremental_General::MIN_RECOMMENDED_PHP_VER, - 3 => CRM_Upgrade_Incremental_General::RECOMMENDED_PHP_VER, + 3 => preg_replace(';^(\d+\.\d+(?:\.[1-9]\d*)?).*$;', '\1', CRM_Upgrade_Incremental_General::RECOMMENDED_PHP_VER), ]), ts('PHP Out-of-Date'), \Psr\Log\LogLevel::ERROR, diff --git a/install/index.php b/install/index.php index 585cea24ac01..5ca472f63a1b 100644 --- a/install/index.php +++ b/install/index.php @@ -904,7 +904,7 @@ public function requirePHPVersion($testDetails) { $testDetails[2] = ts('This webserver is running an outdated version of PHP (%1). It is strongly recommended to upgrade to PHP %2 or later, as older versions can present a security risk. The preferred version is %3.', array( 1 => $phpVersion, 2 => CRM_Upgrade_Incremental_General::MIN_RECOMMENDED_PHP_VER, - 3 => CRM_Upgrade_Incremental_General::RECOMMENDED_PHP_VER, + 3 => preg_replace(';^(\d+\.\d+(?:\.[1-9]\d*)?).*$;', '\1', CRM_Upgrade_Incremental_General::RECOMMENDED_PHP_VER), )); $this->warning($testDetails); } diff --git a/tests/phpunit/CRM/Upgrade/FormTest.php b/tests/phpunit/CRM/Upgrade/FormTest.php index 7a3d82567a14..c5427e698abc 100644 --- a/tests/phpunit/CRM/Upgrade/FormTest.php +++ b/tests/phpunit/CRM/Upgrade/FormTest.php @@ -17,7 +17,7 @@ public function testComposerRequirementMatch() { $composerJson = json_decode(file_get_contents($composerJsonPath), 1); $composerJsonRequirePhp = preg_replace(';[~^];', '', $composerJson['require']['php']); $actualMajorMinor = preg_replace(';^[\^]*(\d+\.\d+)\..*$;', '\1', $composerJsonRequirePhp); - $expectMajorMinor = preg_replace(';^[\^]*(\d+\.\d+)\..*$;', '\1', \CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER); + $expectMajorMinor = preg_replace(';^(\d+\.\d+)\..*$;', '\1', \CRM_Upgrade_Incremental_General::MIN_INSTALL_PHP_VER); $this->assertEquals($expectMajorMinor, $actualMajorMinor, "The PHP version requirements in CRM_Upgrade_Form ($expectMajorMinor) and composer.json ($actualMajorMinor) should specify same major+minor versions."); }