openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 3b1e8c3c3a28e9db710a47911d3808c4e7186a29
parent 7b3d3121d7e136b33a4da4ead032f746b492626a
Author: Jan Dankert <devnull@localhost>
Date:   Thu,  7 Dec 2017 00:58:20 +0100

Type-Hints ergänzt, damit die IDE besser unterstützen kann. Bei Datenbankproblemen eine RuntimeException werfen. Keine CMS-Exceptions in den Modulen!

Diffstat:
action/LoginAction.class.php | 18+++++++++++++-----
db/DbUpdate.class.php | 16+++++++++++-----
2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/action/LoginAction.class.php b/action/LoginAction.class.php @@ -17,6 +17,7 @@ use cms\model\Model; use database\Database; use DB; use DbUpdate; +use Exception; use Http; use InternalAuth; use Logger; @@ -85,7 +86,7 @@ class LoginAction extends Action Session::setDatabase( $db ); }catch(\Exception $e) { - throw new OpenRatException('ERROR_DATABASE_CONNECTION',$e->getMessage() ); + throw new OpenRatException('DATABASE_ERROR_CONNECTION',$e->getMessage() ); } } @@ -858,10 +859,17 @@ class LoginAction extends Action if ( !is_array($conf['database'][$dbid]) ) $this->addValidationError('dbid'); - - $db = new Database( $conf['database'][$dbid],true ); - $db->id = $dbid; - + + try { + + + $db = new Database($conf['database'][$dbid], true); + $db->id = $dbid; + } + catch( Exception $e) { + throw new OpenRatException('DATABASE_ERROR_CONNECTION',$e->getMessage()); + } + // Datenbank aktualisieren, sofern notwendig. require_once( OR_DBCLASSES_DIR.'DbUpdate.class.'.PHP_EXT ); $updater = new DbUpdate(); diff --git a/db/DbUpdate.class.php b/db/DbUpdate.class.php @@ -1,5 +1,7 @@ <?php +use database\Database; + define('OR_DB_SUPPORTED_VERSION',7); define('OR_DB_STATUS_UPDATE_PROGRESS', 0); @@ -7,7 +9,10 @@ define('OR_DB_STATUS_UPDATE_SUCCESS' , 1); class DbUpdate { - function update( $db ) + /** + * @param Database $db + */ + function update(Database $db ) { $version = $this->getDbVersion($db); @@ -37,8 +42,9 @@ class DbUpdate $updaterClassName = 'DBVersion'.str_pad($installVersion, 6, '0', STR_PAD_LEFT); require(OR_DBCLASSES_DIR.'update/'.$updaterClassName.'.class.php'); - - $updater = new $updaterClassName( $db ); + + /** @var \database\DbVersion $updater */ + $updater = new $updaterClassName( $db ); $updater->update(); @@ -62,7 +68,7 @@ class DbUpdate * * @param DB $db */ - private function afterUpdate( $db ) + private function afterUpdate( Database $db ) { // Benutzer zählen. $sql = $db->sql('SELECT COUNT(*) From {{user}}',$db->id); @@ -79,7 +85,7 @@ class DbUpdate - private function getDbVersion( $db ) + private function getDbVersion( Database $db ) { $sql = $db->sql('SELECT 1 FROM {{version}}',$db->id); $versionTableExists = $sql->testQuery();