Skip to content

Commit 856967a

Browse files
committed
(base) Give a hint in web interface if SimpleXML (php-xml) is missing
Fixes nextcloud#2180 And prevents nextcloud#31473, nextcloud#23970, nextcloud#18610, nextcloud#15708 Avoids a 500 error and also gives a useful error message on the web interface if this module isn't installed, gets overlooked during a PHP upgrade, etc. While we check for it later, it's too late for session. Inspired by nextcloud#17163 Signed-off-by: Josh Richards <[email protected]>
1 parent b288d27 commit 856967a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/base.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,28 @@ public static function init(): void {
698698
$bootstrapCoordinator->runInitialRegistration();
699699

700700
$eventLogger->start('init_session', 'Initialize session');
701+
702+
// Check for PHP SimpleXML extension earlier since we need it before our other checks and want to provide a useful hint for web users
703+
// see https://github.com/nextcloud/server/pull/2619
704+
if (!function_exists('simplexml_load_file')) {
705+
if (!defined('OC_CONSOLE') && !self::$CLI) {
706+
$errors[] = [
707+
// don't translate since languages may not be available yet
708+
'error' => 'The PHP SimpleXML/PHP-XML extension is not installed.',
709+
'hint' => 'Install the extension or make sure it is enabled.'
710+
];
711+
http_response_code(503);
712+
OC_Util::addStyle('guest');
713+
try {
714+
OC_Template::printGuestPage('', 'error', ['errors' => $errors]);
715+
exit;
716+
} catch (\Exception $e) {
717+
// In case any error happens when showing the error page, we simply fall back to posting the text.
718+
// This might be the case when e.g. the data directory is broken and we can not load/write SCSS to/from it.
719+
}
720+
}
721+
}
722+
701723
OC_App::loadApps(['session']);
702724
if (!self::$CLI) {
703725
self::initSession();

0 commit comments

Comments
 (0)