openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

commit 074e840792f3c01c6aa0b278d9b108bd6bbb6f2b
parent 24f171132211fd42bf175f6d82bd046f3d76f70d
Author: Jan Dankert <develop@jandankert.de>
Date:   Mon, 20 May 2019 00:52:45 +0200

Refactoring: DB-Update läuft jetzt im Dispatcher. In die Loginaction gehörte es nicht hinein.

Diffstat:
modules/cms-core/Dispatcher.class.php | 41+++++++++++++++++++++++++++++++++++++++++
modules/cms-core/action/LoginAction.class.php | 42------------------------------------------
2 files changed, 41 insertions(+), 42 deletions(-)

diff --git a/modules/cms-core/Dispatcher.class.php b/modules/cms-core/Dispatcher.class.php @@ -10,6 +10,7 @@ use cms\action\Action; use cms\action\RequestParams; use ConfigurationLoader; use database\Database; +use DbUpdate; use DomainException; use Http; use http\Exception; @@ -383,9 +384,49 @@ class Dispatcher { throw new OpenRatException('DATABASE_ERROR_CONNECTION',$e->getMessage() ); } + + + if ( $this->request->hasRequestVar('dbid') ) + $this->updateDatabase( $dbid ); + } + + + + /** + * Updating the database. + * + * @param $dbid integer + * @throws OpenRatException + */ + private function updateDatabase($dbid) + { + try { + $dbConfig = Conf()->subset('database')->subset($dbid); + + if ( ! $dbConfig->is('check_version',true)) + return; // Check for DB version is disabled. + + $adminDb = new Database( $dbConfig->subset('admin')->getConfig() + $dbConfig->getConfig() ); + $adminDb->id = $dbid; + } catch (\Exception $e) { + + throw new OpenRatException('DATABASE_ERROR_CONNECTION', $e->getMessage()); + } + + $updater = new DbUpdate(); + $updater->update($adminDb); + + // Try to close the PDO connection. PDO doc: + // To close the connection, you need to destroy the object by ensuring that all + // remaining references to it are deleted—you do this by assigning NULL to the variable that holds the object. + // If you don't do this explicitly, PHP will automatically close the connection when your script ends. + $adminDb = null; + unset($adminDb); } + + /** * Eröffnet eine Transaktion. */ diff --git a/modules/cms-core/action/LoginAction.class.php b/modules/cms-core/action/LoginAction.class.php @@ -658,13 +658,6 @@ class LoginAction extends Action { global $conf; - $db = db(); // throws Exception, if database is not available. - { - $dbid = $db->id; - - $this->updateDatabase($dbid); // Updating... - } - Session::setUser(''); // Altes Login entfernen. if ( $conf['login']['nologin'] ) @@ -1454,41 +1447,6 @@ class LoginAction extends Action } } - - - - /** - * Updating the database. - * - * @param $dbid integer - * @throws OpenRatException - */ - private function updateDatabase($dbid) - { - try { - $dbConfig = Conf()->subset('database')->subset($dbid); - - if ( ! $dbConfig->is('check_version',false)) - return; // Check for DB version is disabled. - - $adminDb = new Database( $dbConfig->subset('admin')->getConfig() + $dbConfig->getConfig() ); - $adminDb->id = $dbid; - } catch (Exception $e) { - - throw new OpenRatException('DATABASE_ERROR_CONNECTION', $e->getMessage()); - } - - $updater = new DbUpdate(); - $updater->update($adminDb); - - // Try to close the PDO connection. PDO doc: - // To close the connection, you need to destroy the object by ensuring that all - // remaining references to it are deleted—you do this by assigning NULL to the variable that holds the object. - // If you don't do this explicitly, PHP will automatically close the connection when your script ends. - $adminDb = null; - unset($adminDb); - } - }