function SqlBase::setUpDatabase
Same name in other branches
- 9 core/modules/migrate/src/Plugin/migrate/source/SqlBase.php \Drupal\migrate\Plugin\migrate\source\SqlBase::setUpDatabase()
- 10 core/modules/migrate/src/Plugin/migrate/source/SqlBase.php \Drupal\migrate\Plugin\migrate\source\SqlBase::setUpDatabase()
- 11.x core/modules/migrate/src/Plugin/migrate/source/SqlBase.php \Drupal\migrate\Plugin\migrate\source\SqlBase::setUpDatabase()
Gets a connection to the referenced database.
This method will add the database connection if necessary.
Parameters
array $database_info: Configuration for the source database connection. The keys are: 'key' - The database connection key. 'target' - The database connection target. 'database' - Database configuration array as accepted by Database::addConnectionInfo.
Return value
\Drupal\Core\Database\Connection The connection to use for this plugin's queries.
Throws
\Drupal\migrate\Exception\RequirementsException Thrown if no source database connection is configured.
1 call to SqlBase::setUpDatabase()
- SqlBase::getDatabase in core/
modules/ migrate/ src/ Plugin/ migrate/ source/ SqlBase.php - Gets the database connection object.
File
-
core/
modules/ migrate/ src/ Plugin/ migrate/ source/ SqlBase.php, line 182
Class
- SqlBase
- Sources whose data may be fetched via a database connection.
Namespace
Drupal\migrate\Plugin\migrate\sourceCode
protected function setUpDatabase(array $database_info) {
if (isset($database_info['key'])) {
$key = $database_info['key'];
}
else {
// If there is no explicit database configuration at all, fall back to a
// connection named 'migrate'.
$key = 'migrate';
}
if (isset($database_info['target'])) {
$target = $database_info['target'];
}
else {
$target = 'default';
}
if (isset($database_info['database'])) {
Database::addConnectionInfo($key, $target, $database_info['database']);
}
try {
$connection = Database::getConnection($target, $key);
} catch (ConnectionNotDefinedException $e) {
// If we fell back to the magic 'migrate' connection and it doesn't exist,
// treat the lack of the connection as a RequirementsException.
if ($key == 'migrate') {
throw new RequirementsException("No database connection configured for source plugin " . $this->pluginId, [], 0, $e);
}
else {
throw $e;
}
}
return $connection;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.