Browse Source

Merge pull request #4092 from owncloud/base-better-errors

Generate better errors in base.php
remotes/origin/stable6
Bart Visscher 13 years ago
parent
commit
639097db59
  1. 29
      lib/base.php
  2. 8
      lib/template.php
  3. 2
      lib/user.php
  4. 2
      lib/util.php

29
lib/base.php

@ -124,10 +124,9 @@ class OC {
OC::$THIRDPARTYWEBROOT = rtrim(dirname(OC::$WEBROOT), '/'); OC::$THIRDPARTYWEBROOT = rtrim(dirname(OC::$WEBROOT), '/');
OC::$THIRDPARTYROOT = rtrim(dirname(OC::$SERVERROOT), '/'); OC::$THIRDPARTYROOT = rtrim(dirname(OC::$SERVERROOT), '/');
} else { } else {
echo('3rdparty directory not found! Please put the ownCloud 3rdparty'
throw new Exception('3rdparty directory not found! Please put the ownCloud 3rdparty'
.' folder in the ownCloud folder or the folder above.' .' folder in the ownCloud folder or the folder above.'
.' You can also configure the location in the config.php file.'); .' You can also configure the location in the config.php file.');
exit;
} }
// search the apps folder // search the apps folder
$config_paths = OC_Config::getValue('apps_paths', array()); $config_paths = OC_Config::getValue('apps_paths', array());
@ -150,9 +149,8 @@ class OC {
} }
if (empty(OC::$APPSROOTS)) { if (empty(OC::$APPSROOTS)) {
echo('apps directory not found! Please put the ownCloud apps folder in the ownCloud folder'
throw new Exception('apps directory not found! Please put the ownCloud apps folder in the ownCloud folder'
.' or the folder above. You can also configure the location in the config.php file.'); .' or the folder above. You can also configure the location in the config.php file.');
exit;
} }
$paths = array(); $paths = array();
foreach (OC::$APPSROOTS as $path) { foreach (OC::$APPSROOTS as $path) {
@ -174,14 +172,11 @@ class OC {
if (file_exists(OC::$SERVERROOT . "/config/config.php") if (file_exists(OC::$SERVERROOT . "/config/config.php")
and !is_writable(OC::$SERVERROOT . "/config/config.php")) { and !is_writable(OC::$SERVERROOT . "/config/config.php")) {
$defaults = new OC_Defaults(); $defaults = new OC_Defaults();
$tmpl = new OC_Template('', 'error', 'guest');
$tmpl->assign('errors', array(1 => array(
'error' => "Can't write into config directory 'config'",
'hint' => 'This can usually be fixed by '
OC_Template::printErrorPage(
"Can't write into config directory 'config'",
'This can usually be fixed by '
.'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html#set-the-directory-permissions" target="_blank">giving the webserver write access to the config directory</a>.' .'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html#set-the-directory-permissions" target="_blank">giving the webserver write access to the config directory</a>.'
)));
$tmpl->printPage();
exit();
);
} }
} }
@ -223,10 +218,7 @@ class OC {
header('Retry-After: 120'); header('Retry-After: 120');
// render error page // render error page
$tmpl = new OC_Template('', 'error', 'guest');
$tmpl->assign('errors', array(1 => array('error' => 'ownCloud is in maintenance mode')));
$tmpl->printPage();
exit();
OC_Template::printErrorPage('ownCloud is in maintenance mode');
} }
} }
@ -305,11 +297,7 @@ class OC {
$error = 'Session could not be initialized. Please contact your '; $error = 'Session could not be initialized. Please contact your ';
$error .= 'system administrator'; $error .= 'system administrator';
$tmpl = new OC_Template('', 'error', 'guest');
$tmpl->assign('errors', array(1 => array('error' => $error)));
$tmpl->printPage();
exit();
OC_Template::printErrorPage($error);
} }
$sessionLifeTime = self::getSessionLifeTime(); $sessionLifeTime = self::getSessionLifeTime();
@ -370,6 +358,7 @@ class OC {
self::$loader->registerPrefix('Symfony\\Component\\Routing', 'symfony/routing'); self::$loader->registerPrefix('Symfony\\Component\\Routing', 'symfony/routing');
self::$loader->registerPrefix('Sabre\\VObject', '3rdparty'); self::$loader->registerPrefix('Sabre\\VObject', '3rdparty');
self::$loader->registerPrefix('Sabre_', '3rdparty'); self::$loader->registerPrefix('Sabre_', '3rdparty');
self::$loader->registerPrefix('Patchwork', '3rdparty');
spl_autoload_register(array(self::$loader, 'load')); spl_autoload_register(array(self::$loader, 'load'));
// set some stuff // set some stuff

8
lib/template.php

@ -163,7 +163,7 @@ class OC_Template{
$this->renderas = $renderas; $this->renderas = $renderas;
$this->application = $app; $this->application = $app;
$this->vars = array(); $this->vars = array();
$this->vars['requesttoken'] = OC_Util::callRegister();
$this->vars['requesttoken'] = OC::$session ? OC_Util::callRegister() : '';
$parts = explode('/', $app); // fix translation when app is something like core/lostpassword $parts = explode('/', $app); // fix translation when app is something like core/lostpassword
$this->l10n = OC_L10N::get($parts[0]); $this->l10n = OC_L10N::get($parts[0]);
@ -225,6 +225,9 @@ class OC_Template{
*/ */
static public function getFormFactorExtension() static public function getFormFactorExtension()
{ {
if (!\OC::$session) {
return '';
}
// if the formfactor is not yet autodetected do the // if the formfactor is not yet autodetected do the
// autodetection now. For possible formfactors check the // autodetection now. For possible formfactors check the
// detectFormfactor documentation // detectFormfactor documentation
@ -529,6 +532,9 @@ class OC_Template{
$error_msg = '['.$exception->getCode().'] '.$error_msg; $error_msg = '['.$exception->getCode().'] '.$error_msg;
} }
$hint = $exception->getTraceAsString(); $hint = $exception->getTraceAsString();
if (!empty($hint)) {
$hint = '<pre>'.$hint.'</pre>';
}
while (method_exists($exception,'previous') && $exception = $exception->previous()) { while (method_exists($exception,'previous') && $exception = $exception->previous()) {
$error_msg .= '<br/>Caused by: '; $error_msg .= '<br/>Caused by: ';
if ($exception->getCode()) { if ($exception->getCode()) {

2
lib/user.php

@ -316,7 +316,7 @@ class OC_User {
* @return string uid or false * @return string uid or false
*/ */
public static function getUser() { public static function getUser() {
$uid = OC::$session->get('user_id');
$uid = OC::$session ? OC::$session->get('user_id') : null;
if (!is_null($uid)) { if (!is_null($uid)) {
return $uid; return $uid;
} else { } else {

2
lib/util.php

@ -1,7 +1,5 @@
<?php <?php
require_once 'Patchwork/PHP/Shim/Normalizer.php';
/** /**
* Class for utility functions * Class for utility functions
* *

Loading…
Cancel
Save