Skip to content

Commit

Permalink
(base) Give a hint in web interface if SimpleXML (php-xml) is missing
Browse files Browse the repository at this point in the history
Fixes #2180
And prevents #31473, #23970, #18610, #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 #17163

Signed-off-by: Josh Richards <josh.t.richards@gmail.com>
  • Loading branch information
joshtrichards committed Jun 16, 2023
1 parent b288d27 commit 856967a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,28 @@ public static function init(): void {
$bootstrapCoordinator->runInitialRegistration();

$eventLogger->start('init_session', 'Initialize session');

// Check for PHP SimpleXML extension earlier since we need it before our other checks and want to provide a useful hint for web users
// see https://github.com/nextcloud/server/pull/2619
if (!function_exists('simplexml_load_file')) {
if (!defined('OC_CONSOLE') && !self::$CLI) {
$errors[] = [
// don't translate since languages may not be available yet
'error' => 'The PHP SimpleXML/PHP-XML extension is not installed.',
'hint' => 'Install the extension or make sure it is enabled.'
];
http_response_code(503);
OC_Util::addStyle('guest');
try {
OC_Template::printGuestPage('', 'error', ['errors' => $errors]);
exit;
} catch (\Exception $e) {
// In case any error happens when showing the error page, we simply fall back to posting the text.
// This might be the case when e.g. the data directory is broken and we can not load/write SCSS to/from it.
}
}
}

OC_App::loadApps(['session']);
if (!self::$CLI) {
self::initSession();
Expand Down

0 comments on commit 856967a

Please sign in to comment.