diff --git a/lib/OC.php b/lib/OC.php index 55db8d93f9d06..21e5dc5f12bfb 100644 --- a/lib/OC.php +++ b/lib/OC.php @@ -215,29 +215,58 @@ public static function checkConfig(): void { // Check if config is writable $configFileWritable = is_writable($configFilePath); + if ($configFileWritable) { + return; + } + $configReadOnly = Server::get(IConfig::class)->getSystemValueBool('config_is_read_only'); - if (!$configFileWritable && !$configReadOnly - || !$configFileWritable && \OCP\Util::needUpgrade()) { - $urlGenerator = Server::get(IURLGenerator::class); - $l = Server::get(\OCP\L10N\IFactory::class)->get('lib'); + $needUpgrade = \OCP\Util::needUpgrade(); - if (self::$CLI) { - echo $l->t('Cannot write into "config" directory!') . "\n"; - echo $l->t('This can usually be fixed by giving the web server write access to the config directory.') . "\n"; - echo "\n"; - echo $l->t('But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.') . "\n"; - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ]) . "\n"; - exit; - } else { - Server::get(ITemplateManager::class)->printErrorPage( - $l->t('Cannot write into "config" directory!'), - $l->t('This can usually be fixed by giving the web server write access to the config directory.') . ' ' - . $l->t('But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.') . ' ' - . $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ]), - 503 - ); + // Admin intentionally froze config.php and no upgrade is pending: nothing to warn about. + if ($configReadOnly && !$needUpgrade) { + return; + } + + $urlGenerator = Server::get(IURLGenerator::class); + $l = Server::get(\OCP\L10N\IFactory::class)->get('lib'); + $docs = $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ]); + + if ($needUpgrade && $configReadOnly) { + // Upgrades require a writable config.php even when config_is_read_only is set + $lines = [ + $l->t('Your Nextcloud instance needs an update, but config.php is configured as read-only via "config_is_read_only".'), + $l->t('Temporarily set "config_is_read_only" to false and make sure the config directory is writable for the web server, run the upgrade, then restore read-only mode.'), + $docs, + ]; + } elseif ($needUpgrade) { + $lines = [ + $l->t('Your Nextcloud instance needs an update, but the config directory is not writable.'), + $l->t('This can usually be fixed by giving the web server write access to the config directory.'), + $docs, + ]; + } else { + $lines = [ + $l->t('This can usually be fixed by giving the web server write access to the config directory.'), + $l->t('But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.'), + $docs, + ]; + } + + $title = $l->t('Cannot write into "config" directory!'); + + if (self::$CLI) { + echo $title . "\n"; + foreach ($lines as $line) { + echo $line . "\n"; } + exit; } + + Server::get(ITemplateManager::class)->printErrorPage( + $title, + implode(' ', $lines), + 503 + ); } public static function checkInstalled(\OC\SystemConfig $systemConfig): void {