Prerequisites - check for mixed php version/user (#7127)

* Prerequisites: add a warning in case of cron commands executed with a wrong user of PHP version

* Prerequisites: add a warning in case of cron commands executed with a wrong user of PHP version

---------

Co-authored-by: Lucas Bartholemy <luke-@users.noreply.github.com>
This commit is contained in:
Gevorg Mansuryan 2024-07-19 12:30:13 +04:00 committed by GitHub
parent d30aa1c2e5
commit c6b7cf17d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 54 additions and 1 deletions

View File

@ -7,12 +7,13 @@ HumHub Changelog
- Enh #7070: Add GitHub action for PHP CS Fixer
- Enh #7073: Add a link to notification settings on top dropdown list
- Fix #7100: Enable all file handlers on RichText editor toolbar
- Enh #7127: Prerequisites - Check that Web and Cli php version and user is the same
- Enh #7128: Prerequisites - check for mixed table collations
1.16.2 (Unreleased)
---------------------
- Fix #7102: Fix content search with word ending with hyphen
- Fix #7104: Missing `--text-color-default` CSS variable
- Enh #7128: Prerequisites - check for mixed table collations
1.16.1 (July 1, 2024)
---------------------

View File

@ -9,6 +9,7 @@
namespace humhub\commands;
use DateTime;
use humhub\libs\SelfTest;
use Yii;
use yii\console\Controller;
use yii\console\ExitCode;
@ -37,6 +38,16 @@ class CronController extends Controller
*/
public const MUTEX_ID = 'cron-mutex';
public function beforeAction($action)
{
Yii::$app->cache->set(SelfTest::PHP_INFO_CACHE_KEY, [
'version' => phpversion(),
'user' => get_current_user(),
]);
return parent::beforeAction($action);
}
/**
* Runs the cron jobs

View File

@ -24,6 +24,8 @@ use yii\helpers\UnsetArrayValue;
*/
class SelfTest
{
public const PHP_INFO_CACHE_KEY = 'cron_php_info';
/**
* Get Results of the Application SelfTest.
*
@ -481,6 +483,45 @@ class SelfTest
}
}
// Checks that WebApp and ConsoleApp uses the same php version and same user
if (Yii::$app->cache->exists(self::PHP_INFO_CACHE_KEY)) {
$cronPhpInfo = Yii::$app->cache->get(self::PHP_INFO_CACHE_KEY);
if ($cronPhpVersion = ArrayHelper::getValue($cronPhpInfo, 'version')) {
$title = Yii::t('AdminModule.information', 'Settings') . ' - ' . Yii::t('AdminModule.information', 'Web Application and Cron uses the same PHP version');
if ($cronPhpVersion == phpversion()) {
$checks[] = [
'title' => $title,
'state' => 'OK',
];
} else {
$checks[] = [
'title' => $title,
'state' => 'WARNING',
'hint' => Yii::t('AdminModule.information', 'Web Application PHP version: `{webPhpVersion}`, Cron PHP Version: `{cronPhpVersion}`', ['webPhpVersion' => phpversion(), 'cronPhpVersion' => $cronPhpVersion]),
];
}
}
if ($cronPhpUser = ArrayHelper::getValue($cronPhpInfo, 'user')) {
$title = Yii::t('AdminModule.information', 'Settings') . ' - ' . Yii::t('AdminModule.information', 'Web Application and Cron uses the same user');
if ($cronPhpUser == get_current_user()) {
$checks[] = [
'title' => $title,
'state' => 'OK',
];
} else {
$checks[] = [
'title' => $title,
'state' => 'WARNING',
'hint' => Yii::t('AdminModule.information', 'Web Application user: `{webUser}`, Cron user: `{cronUser}`', ['webUser' => get_current_user(), 'cronUser' => $cronPhpUser]),
];
}
}
}
// Check Runtime Directory
$title = Yii::t('AdminModule.information', 'Permissions') . ' - ' . Yii::t('AdminModule.information', 'Runtime');
$path = Yii::getAlias('@runtime');