From 4f1bf87604cad6b1fbb3632ba973131e0bdb50d5 Mon Sep 17 00:00:00 2001 From: Yura Bakhtin Date: Wed, 20 Apr 2022 11:45:24 +0300 Subject: [PATCH 1/4] Check minimum PHP version from HumHub config --- docs/CHANGELOG.md | 4 +++ libs/UpdatePackage.php | 32 +++++++++++++++++++ module.json | 2 +- .../controllers/InstallController.php | 8 ++++- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e8d4851..c029a2c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +2.1.11 (Unreleased) +------------------------ +- Enh #20: Check minimum PHP version from HumHub config + 2.1.10 (April 13, 2022) ------------------------ - Enh #24: Show current update channel with link to module configuration diff --git a/libs/UpdatePackage.php b/libs/UpdatePackage.php index 6f4ff90..5e9b8d6 100644 --- a/libs/UpdatePackage.php +++ b/libs/UpdatePackage.php @@ -142,6 +142,38 @@ public function checkFilePermissions() return $notWritable; } + /** + * Check if new HumHub version supports the current PHP version + * + * @return bool|string True - on supporting, String as new minimum supported PHP version + */ + public function checkPhpVersion() + { + $newMinPhpVersion = $this->getNewConfigValue('minSupportedPhpVersion'); + if ($newMinPhpVersion === null || version_compare(PHP_VERSION, $newMinPhpVersion, '>=')) { + return true; + } + + return $newMinPhpVersion; + } + + private function getNewConfigValue($configVarName, $defaultValue = null) + { + $changedFiles = $this->getChangedFiles(); + + $configFileName = 'protected/humhub/config/common.php'; + if (isset($changedFiles[$configFileName]['newFileMD5'])) { + $newConfigFilePath = $this->getNewFileDirectory() . DIRECTORY_SEPARATOR . $changedFiles[$configFileName]['newFileMD5']; + if (file_exists($newConfigFilePath)) { + if (preg_match('/[\'"]' . preg_quote($configVarName) . '[\'"]\s+=>\s+[\'"](.+?)[\'"]/', file_get_contents($newConfigFilePath), $match)) { + return $match[1]; + } + } + } + + return $defaultValue; + } + public function install() { $warnings = array(); diff --git a/module.json b/module.json index a25d757..259a115 100644 --- a/module.json +++ b/module.json @@ -9,5 +9,5 @@ "humhub": { "minVersion": "1.0" }, - "version": "2.1.10" + "version": "2.1.11" } diff --git a/modules/packageinstaller/controllers/InstallController.php b/modules/packageinstaller/controllers/InstallController.php index 1e3dc09..f9bb0f7 100644 --- a/modules/packageinstaller/controllers/InstallController.php +++ b/modules/packageinstaller/controllers/InstallController.php @@ -63,7 +63,13 @@ public function actionValidate() public function actionPrepare() { - return ['status' => 'ok']; + $result = $this->updatePackage->checkPhpVersion(); + + if ($result === true) { + return ['status' => 'ok']; + } + + return ['message' => 'Please update PHP up to version "' . $result. '"!']; } public function actionInstallFiles() From 02eb32555180206f7b7e9ec818fe481d18b4aebf Mon Sep 17 00:00:00 2001 From: Lucas Bartholemy Date: Wed, 20 Apr 2022 13:38:06 +0200 Subject: [PATCH 2/4] Update InstallController.php --- modules/packageinstaller/controllers/InstallController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/packageinstaller/controllers/InstallController.php b/modules/packageinstaller/controllers/InstallController.php index f9bb0f7..e2e89b4 100644 --- a/modules/packageinstaller/controllers/InstallController.php +++ b/modules/packageinstaller/controllers/InstallController.php @@ -55,7 +55,7 @@ public function actionValidate() $fileList = implode(', ', $notWritable); $files = (strlen($fileList) > 255) ? substr($fileList, 0, 255) . '...' : $fileList; - throw new \Exception(Yii::t('UpdaterModule.base', 'Make sure all files are writable! (' . $files . ')')); + throw new \Exception(Yii::t('UpdaterModule.base', 'Make sure all files are writable! ({files})', ['files' => $files])); } return ['status' => 'ok']; @@ -69,7 +69,7 @@ public function actionPrepare() return ['status' => 'ok']; } - return ['message' => 'Please update PHP up to version "' . $result. '"!']; + return ['message' => Yii::t('UpdaterModule.base', 'Your installed PHP version is too old. The new minimum required PHP version is: {version}', ['version' => $result])]; } public function actionInstallFiles() From 7a8fcbe4ecc24e88fd4c0e058bdd8fd4333a5dc1 Mon Sep 17 00:00:00 2001 From: Lucas Bartholemy Date: Wed, 20 Apr 2022 13:38:45 +0200 Subject: [PATCH 3/4] Update CHANGELOG.md --- docs/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index c029a2c..45a7ccd 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,8 +1,8 @@ Changelog ========= -2.1.11 (Unreleased) ------------------------- +2.1.11 (Aprofil 20, 2022) +-------------------------- - Enh #20: Check minimum PHP version from HumHub config 2.1.10 (April 13, 2022) From bc057e318ef23d4baafaca4d77eb681f686ba530 Mon Sep 17 00:00:00 2001 From: Lucas Bartholemy Date: Wed, 20 Apr 2022 13:38:53 +0200 Subject: [PATCH 4/4] Update CHANGELOG.md --- docs/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 45a7ccd..7a4fb53 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,7 +1,7 @@ Changelog ========= -2.1.11 (Aprofil 20, 2022) +2.1.11 (April 20, 2022) -------------------------- - Enh #20: Check minimum PHP version from HumHub config