clean up usage of DatabaseSetupException and catch Exceptions in entrypoints
This commit is contained in:
parent
c0bdbd9d81
commit
8dc6bdd96b
6
cron.php
6
cron.php
|
@ -44,6 +44,8 @@ function handleUnexpectedShutdown() {
|
|||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
require_once 'lib/base.php';
|
||||
|
||||
session_write_close();
|
||||
|
@ -116,3 +118,7 @@ if (OC::$CLI) {
|
|||
// done!
|
||||
TemporaryCronClass::$sent = true;
|
||||
exit();
|
||||
|
||||
} catch (Exception $ex) {
|
||||
\OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL);
|
||||
}
|
|
@ -23,6 +23,15 @@
|
|||
|
||||
$RUNTIME_NOAPPS = true; //no apps, yet
|
||||
|
||||
try {
|
||||
|
||||
require_once 'lib/base.php';
|
||||
|
||||
OC::handleRequest();
|
||||
|
||||
} catch (Exception $ex) {
|
||||
//show the user a detailed error page
|
||||
OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
|
||||
\OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
|
||||
OC_Template::printExceptionErrorPage($ex);
|
||||
}
|
|
@ -11,6 +11,7 @@ class OC_Response {
|
|||
const STATUS_NOT_MODIFIED = 304;
|
||||
const STATUS_TEMPORARY_REDIRECT = 307;
|
||||
const STATUS_NOT_FOUND = 404;
|
||||
const STATUS_INTERNAL_SERVER_ERROR = 500;
|
||||
|
||||
/**
|
||||
* @brief Enable response caching by sending correct HTTP headers
|
||||
|
@ -70,6 +71,9 @@ class OC_Response {
|
|||
case self::STATUS_NOT_FOUND;
|
||||
$status = $status . ' Not Found';
|
||||
break;
|
||||
case self::STATUS_INTERNAL_SERVER_ERROR;
|
||||
$status = $status . ' Internal Server Error';
|
||||
break;
|
||||
}
|
||||
header($protocol.' '.$status);
|
||||
}
|
||||
|
|
|
@ -106,12 +106,6 @@ class OC_Setup {
|
|||
'hint' => $e->getHint()
|
||||
);
|
||||
return($error);
|
||||
} catch (Exception $e) {
|
||||
$error[] = array(
|
||||
'error' => $e->getMessage(),
|
||||
'hint' => ''
|
||||
);
|
||||
return($error);
|
||||
}
|
||||
}
|
||||
elseif($dbtype == 'pgsql') {
|
||||
|
@ -127,7 +121,7 @@ class OC_Setup {
|
|||
|
||||
try {
|
||||
self::setupPostgreSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username);
|
||||
} catch (Exception $e) {
|
||||
} catch (DatabaseSetupException $e) {
|
||||
$error[] = array(
|
||||
'error' => $l->t('PostgreSQL username and/or password not valid'),
|
||||
'hint' => $l->t('You need to enter either an existing account or the administrator.')
|
||||
|
@ -150,7 +144,7 @@ class OC_Setup {
|
|||
|
||||
try {
|
||||
self::setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace, $username);
|
||||
} catch (Exception $e) {
|
||||
} catch (DatabaseSetupException $e) {
|
||||
$error[] = array(
|
||||
'error' => $l->t('Oracle connection could not be established'),
|
||||
'hint' => $e->getMessage().' Check environment: ORACLE_HOME='.getenv('ORACLE_HOME')
|
||||
|
@ -177,7 +171,7 @@ class OC_Setup {
|
|||
|
||||
try {
|
||||
self::setupMSSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix);
|
||||
} catch (Exception $e) {
|
||||
} catch (DatabaseSetupException $e) {
|
||||
$error[] = array(
|
||||
'error' => 'MS SQL username and/or password not valid',
|
||||
'hint' => 'You need to enter either an existing account or the administrator.'
|
||||
|
@ -326,7 +320,7 @@ class OC_Setup {
|
|||
$connection_string = "host='$e_host' dbname=postgres user='$e_user' password='$e_password'";
|
||||
$connection = @pg_connect($connection_string);
|
||||
if(!$connection) {
|
||||
throw new Exception($l->t('PostgreSQL username and/or password not valid'));
|
||||
throw new DatabaseSetupException($l->t('PostgreSQL username and/or password not valid'));
|
||||
}
|
||||
$e_user = pg_escape_string($dbuser);
|
||||
//check for roles creation rights in postgresql
|
||||
|
@ -371,7 +365,7 @@ class OC_Setup {
|
|||
$connection_string = "host='$e_host' dbname='$e_dbname' user='$e_user' password='$e_password'";
|
||||
$connection = @pg_connect($connection_string);
|
||||
if(!$connection) {
|
||||
throw new Exception($l->t('PostgreSQL username and/or password not valid'));
|
||||
throw new DatabaseSetupException($l->t('PostgreSQL username and/or password not valid'));
|
||||
}
|
||||
$query = "select count(*) FROM pg_class WHERE relname='{$dbtableprefix}users' limit 1";
|
||||
$result = pg_query($connection, $query);
|
||||
|
@ -461,9 +455,9 @@ class OC_Setup {
|
|||
if(!$connection) {
|
||||
$e = oci_error();
|
||||
if (is_array ($e) && isset ($e['message'])) {
|
||||
throw new Exception($e['message']);
|
||||
throw new DatabaseSetupException($e['message']);
|
||||
}
|
||||
throw new Exception($l->t('Oracle username and/or password not valid'));
|
||||
throw new DatabaseSetupException($l->t('Oracle username and/or password not valid'));
|
||||
}
|
||||
//check for roles creation rights in oracle
|
||||
|
||||
|
@ -530,7 +524,7 @@ class OC_Setup {
|
|||
}
|
||||
$connection = @oci_connect($dbuser, $dbpass, $easy_connect_string);
|
||||
if(!$connection) {
|
||||
throw new Exception($l->t('Oracle username and/or password not valid'));
|
||||
throw new DatabaseSetupException($l->t('Oracle username and/or password not valid'));
|
||||
}
|
||||
$query = "SELECT count(*) FROM user_tables WHERE table_name = :un";
|
||||
$stmt = oci_parse($connection, $query);
|
||||
|
@ -641,7 +635,7 @@ class OC_Setup {
|
|||
} else {
|
||||
$entry = '';
|
||||
}
|
||||
throw new Exception($l->t('MS SQL username and/or password not valid: %s', array($entry)));
|
||||
throw new DatabaseSetupException($l->t('MS SQL username and/or password not valid: %s', array($entry)));
|
||||
}
|
||||
|
||||
OC_Config::setValue('dbuser', $dbuser);
|
||||
|
|
10
public.php
10
public.php
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
$RUNTIME_NOAPPS = true;
|
||||
|
||||
try {
|
||||
|
||||
require_once 'lib/base.php';
|
||||
OC::checkMaintenanceMode();
|
||||
if (!isset($_GET['service'])) {
|
||||
|
@ -19,3 +22,10 @@ OC_Util::checkAppEnabled($app);
|
|||
OC_App::loadApp($app);
|
||||
|
||||
require_once OC_App::getAppPath($app) .'/'. $parts[1];
|
||||
|
||||
} catch (Exception $ex) {
|
||||
//show the user a detailed error page
|
||||
OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
|
||||
\OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
|
||||
OC_Template::printExceptionErrorPage($ex);
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
$RUNTIME_NOAPPS = true;
|
||||
|
||||
try {
|
||||
|
||||
require_once 'lib/base.php';
|
||||
$path_info = OC_Request::getPathInfo();
|
||||
if ($path_info === false || $path_info === '') {
|
||||
|
@ -38,3 +41,9 @@ switch ($app) {
|
|||
}
|
||||
$baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
|
||||
require_once $file;
|
||||
|
||||
} catch (Exception $ex) {
|
||||
OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
|
||||
\OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
|
||||
OC_Template::printExceptionErrorPage($ex);
|
||||
}
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
$RUNTIME_NOAPPS = true; //no apps, yet
|
||||
|
||||
try {
|
||||
|
||||
require_once 'lib/base.php';
|
||||
|
||||
if(OC_Config::getValue('installed')==1) $installed='true'; else $installed='false';
|
||||
|
@ -33,3 +35,8 @@ $values=array(
|
|||
'edition'=>OC_Util::getEditionString());
|
||||
|
||||
echo(json_encode($values));
|
||||
|
||||
} catch (Exception $ex) {
|
||||
OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
|
||||
\OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
|
||||
}
|
Loading…
Reference in New Issue