From 7ed678b04db6dde338f90fbd00d828acee4c9c99 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 14 Nov 2014 15:48:55 +0100 Subject: [PATCH 1/3] eliminate OC_Template::printErrorPage in database classes, fixes #12182 --- lib/private/db/adapter.php | 3 ++- lib/private/db/adaptersqlite.php | 4 ++-- lib/private/db/statementwrapper.php | 7 +++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/private/db/adapter.php b/lib/private/db/adapter.php index 972008776f..93d69cf418 100644 --- a/lib/private/db/adapter.php +++ b/lib/private/db/adapter.php @@ -43,6 +43,7 @@ class Adapter { * insert the @input values when they do not exist yet * @param string $table name * @param array $input key->value pair, key has to be sanitized properly + * @throws \OC\HintException * @return int count of inserted rows */ public function insertIfNotExist($table, $input) { @@ -71,7 +72,7 @@ class Adapter { $entry .= 'Offending command was: ' . $query.'
'; \OC_Log::write('core', $entry, \OC_Log::FATAL); error_log('DB error: ' . $entry); - \OC_Template::printErrorPage( $entry ); + throw new \OC\HintException($entry); } } } diff --git a/lib/private/db/adaptersqlite.php b/lib/private/db/adaptersqlite.php index 3471fcf404..fa0e7eb623 100644 --- a/lib/private/db/adaptersqlite.php +++ b/lib/private/db/adaptersqlite.php @@ -42,7 +42,7 @@ class AdapterSqlite extends Adapter { $entry .= 'Offending command was: ' . $query . '
'; \OC_Log::write('core', $entry, \OC_Log::FATAL); error_log('DB error: '.$entry); - \OC_Template::printErrorPage( $entry ); + throw new \OC\HintException($entry); } if ($stmt->fetchColumn() === '0') { @@ -61,7 +61,7 @@ class AdapterSqlite extends Adapter { $entry .= 'Offending command was: ' . $query.'
'; \OC_Log::write('core', $entry, \OC_Log::FATAL); error_log('DB error: ' . $entry); - \OC_Template::printErrorPage( $entry ); + throw new \OC\HintException($entry); } return $result; diff --git a/lib/private/db/statementwrapper.php b/lib/private/db/statementwrapper.php index ad63de98e9..8d972411fe 100644 --- a/lib/private/db/statementwrapper.php +++ b/lib/private/db/statementwrapper.php @@ -64,7 +64,7 @@ class OC_DB_StatementWrapper { } else { $result = $this->statement->execute(); } - + if ($result === false) { return false; } @@ -161,11 +161,10 @@ class OC_DB_StatementWrapper { // send http status 503 header('HTTP/1.1 503 Service Temporarily Unavailable'); header('Status: 503 Service Temporarily Unavailable'); - OC_Template::printErrorPage('Failed to connect to database'); - die ($entry); + throw new \OC\HintException($entry); } } - + /** * provide an alias for fetch * From 08205c63f9324d2697e2ac1a2cb322bc96b197e5 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 14 Nov 2014 16:59:54 +0100 Subject: [PATCH 2/3] errors are already logged --- lib/private/db/adapter.php | 1 - lib/private/db/adaptersqlite.php | 2 -- 2 files changed, 3 deletions(-) diff --git a/lib/private/db/adapter.php b/lib/private/db/adapter.php index 93d69cf418..86f867d099 100644 --- a/lib/private/db/adapter.php +++ b/lib/private/db/adapter.php @@ -71,7 +71,6 @@ class Adapter { $entry = 'DB Error: "'.$e->getMessage() . '"
'; $entry .= 'Offending command was: ' . $query.'
'; \OC_Log::write('core', $entry, \OC_Log::FATAL); - error_log('DB error: ' . $entry); throw new \OC\HintException($entry); } } diff --git a/lib/private/db/adaptersqlite.php b/lib/private/db/adaptersqlite.php index fa0e7eb623..39e2491ed0 100644 --- a/lib/private/db/adaptersqlite.php +++ b/lib/private/db/adaptersqlite.php @@ -41,7 +41,6 @@ class AdapterSqlite extends Adapter { $entry = 'DB Error: "'.$e->getMessage() . '"
'; $entry .= 'Offending command was: ' . $query . '
'; \OC_Log::write('core', $entry, \OC_Log::FATAL); - error_log('DB error: '.$entry); throw new \OC\HintException($entry); } @@ -60,7 +59,6 @@ class AdapterSqlite extends Adapter { $entry = 'DB Error: "'.$e->getMessage() . '"
'; $entry .= 'Offending command was: ' . $query.'
'; \OC_Log::write('core', $entry, \OC_Log::FATAL); - error_log('DB error: ' . $entry); throw new \OC\HintException($entry); } From 74ffda8261d4cbe763e9fb610881e36edf5f9b4d Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 14 Nov 2014 17:13:51 +0100 Subject: [PATCH 3/3] do not output DB information, and do not set header --- lib/private/db/adapter.php | 8 +++++++- lib/private/db/adaptersqlite.php | 16 ++++++++++++++-- lib/private/db/statementwrapper.php | 11 +++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/private/db/adapter.php b/lib/private/db/adapter.php index 86f867d099..58b3514b92 100644 --- a/lib/private/db/adapter.php +++ b/lib/private/db/adapter.php @@ -71,7 +71,13 @@ class Adapter { $entry = 'DB Error: "'.$e->getMessage() . '"
'; $entry .= 'Offending command was: ' . $query.'
'; \OC_Log::write('core', $entry, \OC_Log::FATAL); - throw new \OC\HintException($entry); + $l = \OC::$server->getL10N('lib'); + throw new \OC\HintException( + $l->t('Database Error'), + $l->t('Please contact your system administrator.'), + 0, + $e + ); } } } diff --git a/lib/private/db/adaptersqlite.php b/lib/private/db/adaptersqlite.php index 39e2491ed0..c5dfa85aaa 100644 --- a/lib/private/db/adaptersqlite.php +++ b/lib/private/db/adaptersqlite.php @@ -41,7 +41,13 @@ class AdapterSqlite extends Adapter { $entry = 'DB Error: "'.$e->getMessage() . '"
'; $entry .= 'Offending command was: ' . $query . '
'; \OC_Log::write('core', $entry, \OC_Log::FATAL); - throw new \OC\HintException($entry); + $l = \OC::$server->getL10N('lib'); + throw new \OC\HintException( + $l->t('Database Error'), + $l->t('Please contact your system administrator.'), + 0, + $e + ); } if ($stmt->fetchColumn() === '0') { @@ -59,7 +65,13 @@ class AdapterSqlite extends Adapter { $entry = 'DB Error: "'.$e->getMessage() . '"
'; $entry .= 'Offending command was: ' . $query.'
'; \OC_Log::write('core', $entry, \OC_Log::FATAL); - throw new \OC\HintException($entry); + $l = \OC::$server->getL10N('lib'); + throw new \OC\HintException( + $l->t('Database Error'), + $l->t('Please contact your system administrator.'), + 0, + $e + ); } return $result; diff --git a/lib/private/db/statementwrapper.php b/lib/private/db/statementwrapper.php index 8d972411fe..a85c0167e0 100644 --- a/lib/private/db/statementwrapper.php +++ b/lib/private/db/statementwrapper.php @@ -158,10 +158,13 @@ class OC_DB_StatementWrapper { OC_Log::write('core', $entry, OC_Log::FATAL); OC_User::setUserId(null); - // send http status 503 - header('HTTP/1.1 503 Service Temporarily Unavailable'); - header('Status: 503 Service Temporarily Unavailable'); - throw new \OC\HintException($entry); + $l = \OC::$server->getL10N('lib'); + throw new \OC\HintException( + $l->t('Database Error'), + $l->t('Please contact your system administrator.'), + 0, + $e + ); } }