/** * Returns list of available databases (with access-check based on username/password) * * @param bool $initialInstallation TRUE if first installation is in progress, FALSE if upgrading or usual access * @return array List of available databases */ protected function getDatabaseList($initialInstallation) { $this->initializeDatabaseConnection(); $databaseArray = $this->databaseConnection->admin_get_dbs(); // Remove mysql organizational tables from database list $reservedDatabaseNames = array('mysql', 'information_schema', 'performance_schema'); $allPossibleDatabases = array_diff($databaseArray, $reservedDatabaseNames); // If we are upgrading we show *all* databases the user has access to if ($initialInstallation === false) { return $allPossibleDatabases; } else { // In first installation we show all databases but disable not empty ones (with tables) $databases = array(); foreach ($allPossibleDatabases as $database) { $this->databaseConnection->setDatabaseName($database); $this->databaseConnection->sql_select_db(); $existingTables = $this->databaseConnection->admin_get_tables(); $databases[] = array('name' => $database, 'tables' => count($existingTables)); } return $databases; } }
/** * Selects the database depending on TYPO3 version. * * @param string $databaseName the name of the database to select * @param DatabaseConnection $database database object to process the change * * @return bool */ protected function selectDatabase($databaseName, DatabaseConnection $database) { $database->setDatabaseName($databaseName); $result = $database->sql_select_db(); return $result; }
/** * @test * @expectedException \RuntimeException * @expectedExceptionMessage TYPO3 Fatal Error: Cannot connect to the current database, "Foo"! * @return void */ public function selectDbReturnsFalse() { $this->subject->setDatabaseName('Foo'); $this->assertFalse($this->subject->sql_select_db()); }