Skip to content

Commit

Permalink
Migrate missing PHP modules check to new API and improve it
Browse files Browse the repository at this point in the history
Test all modules listed as required in our documentation

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Oct 12, 2023
1 parent 1d04ce4 commit f2348f4
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 71 deletions.
1 change: 1 addition & 0 deletions apps/settings/composer/composer/autoload_classmap.php
Expand Up @@ -79,6 +79,7 @@
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => $baseDir . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
'OCA\\Settings\\SetupChecks\\NeedsSystemAddressBookSync' => $baseDir . '/../lib/SetupChecks/NeedsSystemAddressBookSync.php',
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php',
'OCA\\Settings\\SetupChecks\\PhpModules' => $baseDir . '/../lib/SetupChecks/PhpModules.php',
'OCA\\Settings\\SetupChecks\\PhpOutdated' => $baseDir . '/../lib/SetupChecks/PhpOutdated.php',
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => $baseDir . '/../lib/SetupChecks/PhpOutputBuffering.php',
'OCA\\Settings\\SetupChecks\\ReadOnlyConfig' => $baseDir . '/../lib/SetupChecks/ReadOnlyConfig.php',
Expand Down
1 change: 1 addition & 0 deletions apps/settings/composer/composer/autoload_static.php
Expand Up @@ -94,6 +94,7 @@ class ComposerStaticInitSettings
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => __DIR__ . '/..' . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
'OCA\\Settings\\SetupChecks\\NeedsSystemAddressBookSync' => __DIR__ . '/..' . '/../lib/SetupChecks/NeedsSystemAddressBookSync.php',
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php',
'OCA\\Settings\\SetupChecks\\PhpModules' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpModules.php',
'OCA\\Settings\\SetupChecks\\PhpOutdated' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutdated.php',
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutputBuffering.php',
'OCA\\Settings\\SetupChecks\\ReadOnlyConfig' => __DIR__ . '/..' . '/../lib/SetupChecks/ReadOnlyConfig.php',
Expand Down
2 changes: 2 additions & 0 deletions apps/settings/lib/AppInfo/Application.php
Expand Up @@ -53,6 +53,7 @@
use OCA\Settings\SetupChecks\InternetConnectivity;
use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
use OCA\Settings\SetupChecks\PhpDefaultCharset;
use OCA\Settings\SetupChecks\PhpModules;
use OCA\Settings\SetupChecks\PhpOutdated;
use OCA\Settings\SetupChecks\PhpOutputBuffering;
use OCA\Settings\SetupChecks\ReadOnlyConfig;
Expand Down Expand Up @@ -151,6 +152,7 @@ public function register(IRegistrationContext $context): void {
$context->registerSetupCheck(InternetConnectivity::class);
$context->registerSetupCheck(LegacySSEKeyFormat::class);
$context->registerSetupCheck(PhpDefaultCharset::class);
$context->registerSetupCheck(PhpModules::class);
$context->registerSetupCheck(PhpOutdated::class);
$context->registerSetupCheck(PhpOutputBuffering::class);
$context->registerSetupCheck(ReadOnlyConfig::class);
Expand Down
35 changes: 0 additions & 35 deletions apps/settings/lib/Controller/CheckSetupController.php
Expand Up @@ -691,40 +691,6 @@ private function getAppDirsWithDifferentOwnerForAppRoot(int $currentUser, array
return $appDirsWithDifferentOwner;
}

/**
* Checks for potential PHP modules that would improve the instance
*
* @return string[] A list of PHP modules that is recommended
*/
protected function hasRecommendedPHPModules(): array {
$recommendedPHPModules = [];

if (!extension_loaded('intl')) {
$recommendedPHPModules[] = 'intl';
}

if (!extension_loaded('sysvsem')) {
// used to limit the usage of resources by preview generator
$recommendedPHPModules[] = 'sysvsem';
}

if (!extension_loaded('exif')) {
// used to extract metadata from images
// required for correct orientation of preview images
$recommendedPHPModules[] = 'exif';
}

if (!defined('PASSWORD_ARGON2I')) {
// Installing php-sodium on >=php7.4 will provide PASSWORD_ARGON2I
// on previous version argon2 wasn't part of the "standard" extension
// and RedHat disabled it so even installing php-sodium won't provide argon2i
// support in password_hash/password_verify.
$recommendedPHPModules[] = 'sodium';
}

return $recommendedPHPModules;
}

protected function isImagickEnabled(): bool {
if ($this->config->getAppValue('theming', 'enabled', 'no') === 'yes') {
if (!extension_loaded('imagick')) {
Expand Down Expand Up @@ -882,7 +848,6 @@ public function check() {
'isImagickEnabled' => $this->isImagickEnabled(),
'areWebauthnExtensionsEnabled' => $this->areWebauthnExtensionsEnabled(),
'is64bit' => $this->is64bit(),
'recommendedPHPModules' => $this->hasRecommendedPHPModules(),
'pendingBigIntConversionColumns' => $this->hasBigIntConversionPendingColumns(),
'isMysqlUsedWithoutUTF8MB4' => $this->isMysqlUsedWithoutUTF8MB4(),
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => $this->isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(),
Expand Down
95 changes: 95 additions & 0 deletions apps/settings/lib/SetupChecks/PhpModules.php
@@ -0,0 +1,95 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
*
* @author Côme Chilliet <come.chilliet@nextcloud.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\SetupChecks;

use OCP\IL10N;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;

class PhpModules implements ISetupCheck {
protected const REQUIRED_MODULES = [
'ctype',
'curl',
'dom',
'fileinfo',
'gd',
'json',
'mbstring',
'openssl',
'posix',
'session',
'xml',
'xmlreader',
'xmlwriter',
'zip',
'zlib',
];
protected const RECOMMENDED_MODULES = [
'intl',
'sysvsem',
'exif',
'sodium',
'bz2',
];

public function __construct(
private IL10N $l10n,
) {
}

public function getName(): string {
return $this->l10n->t('PHP modules');
}

public function getCategory(): string {
return 'system';
}

public function run(): SetupResult {
$missingRecommendedModules = $this->getMissingModules(self::RECOMMENDED_MODULES);
$missingRequiredModules = $this->getMissingModules(self::REQUIRED_MODULES);
if (!empty($missingRequiredModules)) {
return new SetupResult(SetupResult::ERROR, $this->l10n->t('This instance is missing some required PHP modules. It is required to install them: %s', implode(', ', $missingRequiredModules)));
} elseif (!empty($missingRecommendedModules)) {
return new SetupResult(SetupResult::INFO, $this->l10n->t('This instance is missing some recommended PHP modules. For improved performance and better compatibility it is highly recommended to install them: %s', implode(', ', $missingRecommendedModules)));
} else {
return new SetupResult(SetupResult::SUCCESS);
}
}

/**
* Checks for potential PHP modules that would improve the instance
*
* @param string[] $modules modules to test
* @return string[] A list of PHP modules which are missing
*/
protected function getMissingModules(array $modules): array {
return array_values(array_filter(
$modules,
fn (string $module) => !extension_loaded($module),
));
}
}
Expand Up @@ -537,7 +537,6 @@ public function testCheck() {
'isImagickEnabled' => false,
'areWebauthnExtensionsEnabled' => false,
'is64bit' => false,
'recommendedPHPModules' => [],
'pendingBigIntConversionColumns' => [],
'isMysqlUsedWithoutUTF8MB4' => false,
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => true,
Expand Down
10 changes: 0 additions & 10 deletions core/js/setupchecks.js
Expand Up @@ -383,16 +383,6 @@
type: OC.SetupChecks.MESSAGE_TYPE_INFO
})
}
if (data.recommendedPHPModules.length > 0) {
var listOfRecommendedPHPModules = "";
data.recommendedPHPModules.forEach(function(element){
listOfRecommendedPHPModules += '<li>' + element + '</li>';
});
messages.push({
msg: t('core', 'This instance is missing some recommended PHP modules. For improved performance and better compatibility it is highly recommended to install them.') + '<ul><code>' + listOfRecommendedPHPModules + '</code></ul>',
type: OC.SetupChecks.MESSAGE_TYPE_INFO
})
}
if (!data.isImagickEnabled) {
messages.push({
msg: t(
Expand Down

0 comments on commit f2348f4

Please sign in to comment.