aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2025-12-21 19:26:08 +0100
committerGravatar GitHub <noreply@github.com> 2025-12-21 19:26:08 +0100
commit1a3912f25a27c8d78aacbbee98f6056f4ad47f1a (patch)
tree90fe6bd955535aed22152fc3a41a51a4958f4d4d /lib
parent672411ca7053345634a63dd3eabed75baf93043f (diff)
Improve configuration checks (#8334)
Add a distinction between recommended and required extensions. Add check for recommended php-intl extension as follow-up of https://github.com/FreshRSS/FreshRSS/pull/8329#issuecomment-3677686581 Improve related checks such as ZIP. Reduce duplicated translations and tests.
Diffstat (limited to 'lib')
-rw-r--r--lib/Minz/Configuration.php4
-rw-r--r--lib/Minz/ModelPdo.php5
-rw-r--r--lib/lib_install.php79
3 files changed, 52 insertions, 36 deletions
diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php
index 45988f4a9..bb4a8b09e 100644
--- a/lib/Minz/Configuration.php
+++ b/lib/Minz/Configuration.php
@@ -4,8 +4,8 @@ declare(strict_types=1);
/**
* Manage configuration for the application.
* @property string $base_url
- * @property array{'type':string,'host':string,'user':string,'password':string,'base':string,'prefix':string,
- * 'connection_uri_params':string,'pdo_options':array<int,int|string|bool>} $db
+ * @property array{type:'mysql'|'pgsql'|'sqlite',host:string,user:string,password:string,base:string,prefix:string,
+ * connection_uri_params:string,pdo_options:array<int,int|string|bool>} $db
* @property bool $disable_update
* @property string $environment
* @property array<string,bool> $extensions_enabled
diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php
index cb541a1e4..e481911bc 100644
--- a/lib/Minz/ModelPdo.php
+++ b/lib/Minz/ModelPdo.php
@@ -82,10 +82,7 @@ class Minz_ModelPdo {
$this->pdo->setPrefix($db['prefix'] . $this->current_user . '_');
break;
default:
- throw new Minz_PDOConnectionException(
- 'Invalid database type!',
- $db['user'], Minz_Exception::ERROR
- );
+ throw new Minz_PDOConnectionException('Invalid database type!', is_string($db['user'] ?? null) ? $db['user'] : '', Minz_Exception::ERROR);
}
if (self::$usesSharedPdo) {
self::$sharedPdo = $this->pdo;
diff --git a/lib/lib_install.php b/lib/lib_install.php
index 28827f0d6..c3e323dea 100644
--- a/lib/lib_install.php
+++ b/lib/lib_install.php
@@ -4,14 +4,16 @@ declare(strict_types=1);
FreshRSS_SystemConfiguration::register('default_system', join_path(FRESHRSS_PATH, 'config.default.php'));
FreshRSS_UserConfiguration::register('default_user', join_path(FRESHRSS_PATH, 'config-user.default.php'));
-/** @return array<string,string> */
-function checkRequirements(string $dbType = ''): array {
+/**
+ * @param 'mysql'|'pgsql'|'sqlite'|'' $dbType
+ * @return array<string,'ok'|'ko'|'warn'>
+ */
+function checkRequirements(string $dbType = '', bool $checkPhp = true, bool $checkFiles = true): array {
$php = version_compare(PHP_VERSION, FRESHRSS_MIN_PHP_VERSION) >= 0;
$curl = extension_loaded('curl'); // TODO: We actually require cURL >= 7.52 for CURLPROXY_HTTPS
$pdo_mysql = extension_loaded('pdo_mysql');
$pdo_sqlite = extension_loaded('pdo_sqlite');
$pdo_pgsql = extension_loaded('pdo_pgsql');
- $message = '';
switch ($dbType) {
case 'mysql':
$pdo_sqlite = $pdo_pgsql = true;
@@ -29,47 +31,64 @@ function checkRequirements(string $dbType = ''): array {
$pdo = $pdo_mysql || $pdo_sqlite || $pdo_pgsql;
break;
default:
- $pdo_mysql = $pdo_sqlite = $pdo_pgsql = true;
- $pdo = false;
- $message = 'Invalid database type!';
- break;
+ throw new InvalidArgumentException('Invalid database type!');
}
+ $pdo &= class_exists('PDO');
$pcre = extension_loaded('pcre');
$ctype = extension_loaded('ctype');
$fileinfo = extension_loaded('fileinfo');
$dom = class_exists('DOMDocument');
$xml = function_exists('xml_parser_create');
$json = function_exists('json_encode');
+ $intl = extension_loaded('intl');
$mbstring = extension_loaded('mbstring');
+ $zip = extension_loaded('zip');
$data = is_dir(DATA_PATH) && touch(DATA_PATH . '/index.html'); // is_writable() is not reliable for a folder on NFS
$cache = is_dir(CACHE_PATH) && touch(CACHE_PATH . '/index.html');
$tmp = is_dir(TMP_PATH) && is_writable(TMP_PATH);
$users = is_dir(USERS_PATH) && touch(USERS_PATH . '/index.html');
$favicons = is_dir(DATA_PATH) && touch(DATA_PATH . '/favicons/index.html');
+ $tokens = is_dir(DATA_PATH) && touch(DATA_PATH . '/tokens/index.html');
+
+ $result = [];
+ if ($checkPhp) {
+ $result += [
+ 'php' => $php ? 'ok' : 'ko',
+ 'pdo' => $pdo ? 'ok' : 'ko',
+ 'pdo-sqlite' => $pdo_sqlite ? 'ok' : ($dbType === 'sqlite' ? 'ko' : 'warn'),
+ 'pdo-pgsql' => ($dbType === 'pgsql' && !$pdo_pgsql) ? 'ko' : null,
+ 'pdo-mysql' => ($dbType === 'mysql' && !$pdo_mysql) ? 'ko' : null,
+ 'dom' => $dom ? 'ok' : 'ko',
+ 'xml' => $xml ? 'ok' : 'ko',
+ 'curl' => $curl ? 'ok' : 'ko',
+ 'pcre' => $pcre ? 'ok' : 'ko',
+ 'ctype' => $ctype ? 'ok' : 'ko',
+ 'json' => $json ? 'ok' : 'ko',
+ 'mbstring' => $mbstring ? 'ok' : 'warn',
+ 'intl' => $intl ? 'ok' : 'warn',
+ 'zip' => $zip ? 'ok' : 'warn',
+ 'fileinfo' => $fileinfo ? 'ok' : 'warn',
+ ];
+ }
+
+ if ($checkFiles) {
+ $result += [
+ 'data' => $data ? 'ok' : 'ko',
+ 'cache' => $cache ? 'ok' : 'ko',
+ 'tmp' => $tmp ? 'ok' : 'ko',
+ 'users' => $users ? 'ok' : 'ko',
+ 'favicons' => $favicons ? 'ok' : 'ko',
+ 'tokens' => $tokens ? 'ok' : 'ko',
+ ];
+ }
+
+ if ($checkPhp && $checkFiles) {
+ $result['all'] = $php && $curl && $json && $pdo && $pcre && $ctype && $dom && $xml &&
+ $data && $cache && $tmp && $users && $favicons && $tokens ? 'ok' : 'ko';
+ }
- return [
- 'php' => $php ? 'ok' : 'ko',
- 'curl' => $curl ? 'ok' : 'ko',
- 'pdo-mysql' => $pdo_mysql ? 'ok' : 'ko',
- 'pdo-sqlite' => $pdo_sqlite ? 'ok' : 'ko',
- 'pdo-pgsql' => $pdo_pgsql ? 'ok' : 'ko',
- 'pdo' => $pdo ? 'ok' : 'ko',
- 'pcre' => $pcre ? 'ok' : 'ko',
- 'ctype' => $ctype ? 'ok' : 'ko',
- 'fileinfo' => $fileinfo ? 'ok' : 'ko',
- 'dom' => $dom ? 'ok' : 'ko',
- 'xml' => $xml ? 'ok' : 'ko',
- 'json' => $json ? 'ok' : 'ko',
- 'mbstring' => $mbstring ? 'ok' : 'ko',
- 'data' => $data ? 'ok' : 'ko',
- 'cache' => $cache ? 'ok' : 'ko',
- 'tmp' => $tmp ? 'ok' : 'ko',
- 'users' => $users ? 'ok' : 'ko',
- 'favicons' => $favicons ? 'ok' : 'ko',
- 'message' => $message ?: '',
- 'all' => $php && $curl && $pdo && $pcre && $ctype && $dom && $xml &&
- $data && $cache && $tmp && $users && $favicons && $message == '' ? 'ok' : 'ko',
- ];
+ $result = array_filter($result, static fn($v) => $v !== null);
+ return $result;
}
function generateSalt(): string {