commit ffdc8fd9f6afa78c45c6ee8c259c2116c56661ce
parent 7f540d7382977ced1c64f4df1a72f20283b403be
Author: Jan Dankert <devnull@localhost>
Date: Wed, 12 Dec 2018 22:52:32 +0100
Wenn keine Datenbankverbindung vorhanden ist, eine Exception werfen.
Diffstat:
2 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/modules/cms-core/action/LoginAction.class.php b/modules/cms-core/action/LoginAction.class.php
@@ -78,14 +78,18 @@ class LoginAction extends Action
if ( !isset($conf['database'][$dbid] ))
throw new \LogicException( 'unknown DB-Id: '.$dbid );
-
- $db = db_connection();
- if ( is_object($db) )
- {
- $db->rollback();
- $db->disconnect(); // Bäm. Dies. ist. notwenig. WTF.
- //$db = null;
- //Session::setDatabase( null );
+
+ try{
+
+ $db = db();
+
+ $db->rollback();
+ $db->disconnect(); // Bäm. This seems to be necessary. WTF?
+ //$db = null;
+ //Session::setDatabase( null );
+ }
+ catch( Exception $e) {
+ // happens if we have no db connection.
}
try
diff --git a/modules/cms-core/functions/common.inc.php b/modules/cms-core/functions/common.inc.php
@@ -148,11 +148,12 @@ function not($var) {
* Liefert die Datenbankverbindung fuer die aktuelle Sitzung.
*
* @return \database\Database
+ * @deprecated use db()
*/
function db_connection()
{
- return Session::getDatabase();
+ return db();
}
/**
@@ -163,7 +164,12 @@ function db_connection()
function db()
{
- return Session::getDatabase();
+ $db = Session::getDatabase();
+
+ if ( ! is_object($db))
+ throw new RuntimeException('no database available');
+
+ return $db;
}