From 4b5d1dea2857fb7e4e23231ed2407e710d454ccb Mon Sep 17 00:00:00 2001 From: Olivier van Helden Date: Sun, 2 Feb 2025 15:17:41 -0400 Subject: [PATCH] make sure robust db is connected after converting robust ini --- classes/class-grid.php | 10 +++++++--- classes/init.php | 6 +++--- install.php | 12 +++++++++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/classes/class-grid.php b/classes/class-grid.php index 27ed0c0..e180afe 100644 --- a/classes/class-grid.php +++ b/classes/class-grid.php @@ -41,6 +41,9 @@ class OpenSim_Grid { $is_local_grid = true; // Default, get login_uri from config, query grid for live grid_info $grid_uri = OpenSim::get_option( 'Hypergrid.HomeURI' ); + if( empty( $grid_uri ) ) { + return false; + } } else { $is_local_grid = false; // External grid lookup, not yet implemented @@ -168,7 +171,6 @@ class OpenSim_Grid { $grid_stats = self::get_grid_stats( $args ); if( ! $grid_stats || OpenSim::is_error( $grid_stats ) ) { - error_log( __METHOD__ . ' grid stats empty or error' ); return false; } @@ -197,6 +199,10 @@ class OpenSim_Grid { public static function get_grid_stats( $args = null ) { $grid_info = self::get_grid_info(); + if( empty( $grid_info ) ) { + return false; + } + $grid_uri = $grid_info['login']; $args = array_merge(array( @@ -212,7 +218,6 @@ class OpenSim_Grid { if ( ! $robust_db || OpenSim::is_error($robust_db) ) { $stats['error'] = _('Database not connected.'); } else { - error_log('querying robust db'); $lastmonth = time() - 30 * 86400; $gridonline = $grid_info['online'] ? _('Yes') : _('No'); @@ -265,7 +270,6 @@ class OpenSim_Grid { // Replace keys with values of self::$labels $labels = self::$labels; $labels = array_intersect_key( self::$labels, $stats ); - error_log( 'labels: ' . print_r( $labels, true ) . ' stats: ' . print_r( $stats, true ) ); $stats = array_combine( $labels, $stats ); } diff --git a/classes/init.php b/classes/init.php index 1d7a7b4..805c188 100644 --- a/classes/init.php +++ b/classes/init.php @@ -52,14 +52,14 @@ class OpenSim { require_once( OSHELPERS_DIR . 'classes/class-exception.php' ); require_once( OSHELPERS_DIR . 'includes/databases.php' ); require_once( OSHELPERS_DIR . 'includes/functions.php' ); - $this->connect_db(); + $this->db_connect(); require_once( OSHELPERS_DIR . 'classes/class-locale.php' ); require_once( OSHELPERS_DIR . 'classes/class-ini.php' ); require_once( OSHELPERS_DIR . 'classes/class-grid.php' ); } - public function connect_db() { + public function db_connect() { $DatabaseService = self::get_option( 'DatabaseService', false ); $connectionstring = self::get_option( 'DatabaseService.ConnectionString', false); @@ -77,7 +77,7 @@ class OpenSim { self::$robust_db = $db; } } else { - error_log('No connection string found'); + return false; } } diff --git a/install.php b/install.php index c2a0192..c41cde2 100644 --- a/install.php +++ b/install.php @@ -236,7 +236,17 @@ class OpenSim_Install extends OpenSim_Page { throw new OpenSim_Error( _('Some required values are missing from the configuration file.') ); } - + // Connect to Robust to check credential and get up-to-date grid info + global $OpenSim; + try { + $OpenSim->db_connect(); + if( ! OpenSim::$robust_db ) { + throw new OpenSim_Error( _('Could not connect to the database.') ); + } + } catch (Throwable $e) { + OpenSim::notify_error( $e ); + return false; + } // OpenSim::notify( _('Configuration file loaded successfully.'), 'success' ); // TODO: copy the temp file to the final location on success. return true;