You are here

public function SqlBase::getDatabase in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate/src/Plugin/migrate/source/SqlBase.php \Drupal\migrate\Plugin\migrate\source\SqlBase::getDatabase()
  2. 10 core/modules/migrate/src/Plugin/migrate/source/SqlBase.php \Drupal\migrate\Plugin\migrate\source\SqlBase::getDatabase()

Gets the database connection object.

Return value

\Drupal\Core\Database\Connection The database connection.

3 calls to SqlBase::getDatabase()
File::query in core/modules/file/src/Plugin/migrate/source/d7/File.php
SqlBase::checkRequirements in core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
Checks if requirements for this plugin are OK.
TestSqlBase::getDatabase in core/modules/migrate/tests/src/Kernel/SqlBaseTest.php
Gets the database without caching it.
2 methods override SqlBase::getDatabase()
TestSqlBase::getDatabase in core/modules/migrate/tests/src/Unit/SqlBaseTest.php
Gets the database connection object.
TestSqlBase::getDatabase in core/modules/migrate/tests/src/Kernel/SqlBaseTest.php
Gets the database without caching it.

File

core/modules/migrate/src/Plugin/migrate/source/SqlBase.php, line 142

Class

SqlBase
Sources whose data may be fetched via a database connection.

Namespace

Drupal\migrate\Plugin\migrate\source

Code

public function getDatabase() {
  if (!isset($this->database)) {

    // Look first for an explicit state key containing the configuration.
    if (isset($this->configuration['database_state_key'])) {
      $this->database = $this
        ->setUpDatabase($this->state
        ->get($this->configuration['database_state_key']));
    }
    elseif (isset($this->configuration['key'])) {
      $this->database = $this
        ->setUpDatabase($this->configuration);
    }
    elseif ($fallback_state_key = $this->state
      ->get('migrate.fallback_state_key')) {
      $this->database = $this
        ->setUpDatabase($this->state
        ->get($fallback_state_key));
    }
    else {
      $this->database = $this
        ->setUpDatabase([]);
    }
  }
  return $this->database;
}