Merge pull request #12186 from owncloud/fix-12182

eliminate OC_Template::printErrorPage in database classes, fixes #12182
This commit is contained in:
Morris Jobke 2014-11-15 16:50:15 +01:00
commit b9e86b0951
3 changed files with 31 additions and 13 deletions

View File

@ -43,6 +43,7 @@ class Adapter {
* insert the @input values when they do not exist yet * insert the @input values when they do not exist yet
* @param string $table name * @param string $table name
* @param array $input key->value pair, key has to be sanitized properly * @param array $input key->value pair, key has to be sanitized properly
* @throws \OC\HintException
* @return int count of inserted rows * @return int count of inserted rows
*/ */
public function insertIfNotExist($table, $input) { public function insertIfNotExist($table, $input) {
@ -70,8 +71,13 @@ class Adapter {
$entry = 'DB Error: "'.$e->getMessage() . '"<br />'; $entry = 'DB Error: "'.$e->getMessage() . '"<br />';
$entry .= 'Offending command was: ' . $query.'<br />'; $entry .= 'Offending command was: ' . $query.'<br />';
\OC_Log::write('core', $entry, \OC_Log::FATAL); \OC_Log::write('core', $entry, \OC_Log::FATAL);
error_log('DB error: ' . $entry); $l = \OC::$server->getL10N('lib');
\OC_Template::printErrorPage( $entry ); throw new \OC\HintException(
$l->t('Database Error'),
$l->t('Please contact your system administrator.'),
0,
$e
);
} }
} }
} }

View File

@ -41,8 +41,13 @@ class AdapterSqlite extends Adapter {
$entry = 'DB Error: "'.$e->getMessage() . '"<br />'; $entry = 'DB Error: "'.$e->getMessage() . '"<br />';
$entry .= 'Offending command was: ' . $query . '<br />'; $entry .= 'Offending command was: ' . $query . '<br />';
\OC_Log::write('core', $entry, \OC_Log::FATAL); \OC_Log::write('core', $entry, \OC_Log::FATAL);
error_log('DB error: '.$entry); $l = \OC::$server->getL10N('lib');
\OC_Template::printErrorPage( $entry ); throw new \OC\HintException(
$l->t('Database Error'),
$l->t('Please contact your system administrator.'),
0,
$e
);
} }
if ($stmt->fetchColumn() === '0') { if ($stmt->fetchColumn() === '0') {
@ -60,8 +65,13 @@ class AdapterSqlite extends Adapter {
$entry = 'DB Error: "'.$e->getMessage() . '"<br />'; $entry = 'DB Error: "'.$e->getMessage() . '"<br />';
$entry .= 'Offending command was: ' . $query.'<br />'; $entry .= 'Offending command was: ' . $query.'<br />';
\OC_Log::write('core', $entry, \OC_Log::FATAL); \OC_Log::write('core', $entry, \OC_Log::FATAL);
error_log('DB error: ' . $entry); $l = \OC::$server->getL10N('lib');
\OC_Template::printErrorPage( $entry ); throw new \OC\HintException(
$l->t('Database Error'),
$l->t('Please contact your system administrator.'),
0,
$e
);
} }
return $result; return $result;

View File

@ -158,11 +158,13 @@ class OC_DB_StatementWrapper {
OC_Log::write('core', $entry, OC_Log::FATAL); OC_Log::write('core', $entry, OC_Log::FATAL);
OC_User::setUserId(null); OC_User::setUserId(null);
// send http status 503 $l = \OC::$server->getL10N('lib');
header('HTTP/1.1 503 Service Temporarily Unavailable'); throw new \OC\HintException(
header('Status: 503 Service Temporarily Unavailable'); $l->t('Database Error'),
OC_Template::printErrorPage('Failed to connect to database'); $l->t('Please contact your system administrator.'),
die ($entry); 0,
$e
);
} }
} }