Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,22 @@
OC::handleRequest();

} catch(\OC\ServiceUnavailableException $ex) {
\OC::loadDefaultEnabledAppTheme();
\OC::$server->getLogger()->logException($ex, array('app' => 'index'));

//show the user a detailed error page
OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
OC_Template::printExceptionErrorPage($ex);
} catch (\OC\HintException $ex) {
\OC::loadDefaultEnabledAppTheme();
OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
OC_Template::printErrorPage($ex->getMessage(), $ex->getHint());
} catch (\OC\User\LoginException $ex) {
\OC::loadDefaultEnabledAppTheme();
OC_Response::setStatus(OC_Response::STATUS_FORBIDDEN);
OC_Template::printErrorPage($ex->getMessage());
} catch (Exception $ex) {
\OC::loadDefaultEnabledAppTheme();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm you are loading the theme because OC_Template needs it when rendering output to the browser ... how about moving \OC::loadDefaultEnabledAppTheme(); to https://github.com/owncloud/core/blob/master/lib/private/legacy/template.php#L102? Loading will then be triggered by the OC_Template constructor itself.

Or you get the DI sortetd out for templates and inject it ... but that's something for 10.1 not 10.0.3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We got proper loading for normal pages. For error pages we have to parse the info.xml files, and that's something we should not do for all pages. That's why i had to do this hacky way.

The best way imo would be to store the path to the enabled theme in a local config file which can be accessed through a config object. But currently we do not support dynamic writing to config files and the enabled theme is the activated theme app.

Once we cleaned up db/local config we could think about a better solution for this, but the scope is too big for just this right now.

try {
\OC::$server->getLogger()->logException($ex, array('app' => 'index'));

Expand All @@ -76,6 +80,7 @@
echo('</body></html>');
}
} catch (Error $ex) {
\OC::loadDefaultEnabledAppTheme();
\OC::$server->getLogger()->logException($ex, array('app' => 'index'));
OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
OC_Template::printExceptionErrorPage($ex);
Expand Down
24 changes: 17 additions & 7 deletions lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,22 @@ protected static function registerAutoloaderCache() {
}
}

/**
* Enables the defaultEnabled app theme
* __do not__ call this for every request, as this parses all apps info.xml
* files in order to determine which app is a default enabled theme while
* not accessing the database which might not be available.
*/
public static function loadDefaultEnabledAppTheme() {
$defaultEnabledAppTheme = \OC_App::getDefaultEnabledAppTheme();

if ($defaultEnabledAppTheme !== false) {
/** @var \OC\Theme\ThemeService $themeService */
$themeService = \OC::$server->query('ThemeService');
$themeService->setAppTheme($defaultEnabledAppTheme);
}
}

/**
* Handle the request
*/
Expand All @@ -843,13 +859,7 @@ public static function handleRequest() {
\OC::$server->getL10N('lib'), new \OC_Defaults(), \OC::$server->getLogger(),
\OC::$server->getSecureRandom());

$defaultEnabledAppTheme = \OC_App::getDefaultEnabledAppTheme();

if ($defaultEnabledAppTheme !== false) {
/** @var \OC\Theme\ThemeService $themeService */
$themeService = \OC::$server->query('ThemeService');
$themeService->setAppTheme($defaultEnabledAppTheme);
}
self::loadDefaultEnabledAppTheme();

$controller = new OC\Core\Controller\SetupController($setupHelper);
$controller->run($_POST);
Expand Down